NAV
Java

Android SDK overview

The Worldcoo Android SDK allows to this Operating System developers to interact with the Worldcoo Donation API in a native way through a series of public methods and, also, to inject the Worldcoo Widget in an easier way than developing a custom integration.

1 - Installation

Follow these steps to include the Worldcoo SDK inside your app:

2 - Authentication

<?xml version="1.0" encoding="utf-8"?><manifest 
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ateknea.widget.android.integrationtest">



    <application 
        android:allowBackup="true" 
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">



        <meta-data android:name="com.worldcoo.sdk.api_key" android:value="@string/worldcoo_api_id"/><meta-data android:name="com.worldcoo.sdk.widget_id" android:value="@string/worldcoo_widget_id"/>


        <activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" />


                <categories android:name="android.intent.categories.LAUNCHER" /></intent-filter></activity>
    </application>


</manifest>

In order to have access to the Worldcoo’s API and the widget generator a pair of keys are provided to the integrators. Those keys should be added by the developer into app’s code in a proper way to initialize the SDK successfully (keys API_KEY and WIDGET_ID needs to be declared without any modifications).

Since resources are declared using XML files, some values need to be declared using ASCII (‘-’ character should be &#8211)

Keys will be read from the AndroidManifest.xml as metadata and could be declared apart into string.xml file to hide values.

If everything has been declared in a proper way, the SDK method init(..) will load the keys automatically.

3 - Initialization

Initialization example

Worldcoo sdk = Worldcoo.getInstance()
sdk.init(context, productionMode)

These are the common public methods, both for API integration and Widget injection

3.1 - public static getInstance()

Return the instance of the SDK.

return

3.2 - init(Context appContext, boolean productionMode)

Initializes the SDK

params

return

3.3 - setProductionMode(boolean productionMode)

Sets mode of Donor API REST usage

params

3.4 - isProductionMode()

Returns Donor API mode

return

4 - API integration

API integration example

// SDK initialization
Worldcoo sdk = Worldcoo.getInstance()
sdk.init(context, productionMode)

// Donor API Client
// Being call from a context (fragmento or activity) that implements NativeListener interface
sdk.getAPIClient().getAvailableNGOs(context,listener)

// This will be received from callback: 
onAvailableNGOs(List<NGO>)

// If there are errors
onError(ErrorBody, request)

// Same way to proceed with all Donor API methods

These are the public methods provided by the SDK to interact with the Worldcoo Donation API:

4.1 - getAPIClient(Context context, DonorListener listener)

Returns a client to easily interact with the Donor web API

params

return

4.2 - getAvailableNGOs(int offset, int limit)

Response example

[
    {
        "id": "8720fdd5-1b10-a4c8-a614",
        "name": "NGO Name Example 1",
        "url": "http://www.examplengo1.com",
        "description": "This is an example of NGO description."
        "logos": {
            "S": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/logo.1479742005411.S.jpg",
            "M": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/logo.1479742005411.M.jpg",
            "L": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/logo.1479742005411.L.jpg"
        },
        "media": {},
    },
    {
        "id": "6582d7k1-7d61-99dc-b213",
        "name": "NGO Name Example 2",
        "url": "http://www.examplengo2.com",
        "description": "This is an example of NGO description."
        "logos": {
            "S": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/logo.1479742005411.S.jpg",
            "M": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/logo.1479742005411.M.jpg",
            "L": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/logo.1479742005411.L.jpg"
        },
        "media": {},
    },
    ...
]

Gets available NGOs

params

availableNGOs(ArrayList ngos)

onError(ErrorBody error, RequestType type)

4.3 - getAvailableCampaigns(String ngo_id, int offset, int limit)

Response example

[
    {
        "id": "a9fb530d-6270-0cc7-e8a8",
        "alias": "Demo campaign",
        "ngo_id": "2454de2c-cb31-44e5-83bd",
        "status": "active",
        "location": {
            "country": "ESP",
            "name": "Barcelona"
        },
        "categories": ["water_and_energy", "hunger_and_food_security"],
        "currency": "EUR",
        "collection_objective": {
            "total": 500,
            "distribution": {
                "materials": 100,
                "team": 100,
                "transport": 50,
                "others": 200,
                "providers": 50
            }
        },
        "beneficiaries": {
            "direct": 400,
            "indirect": 1000
        },
        "starting_date": 1464277166,
        "ending_date": null,
        "media": {
            "eaba63b5-d7be-4de8-a53e-283c9104a9a6": {
                "S": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.S.jpg",
                "L": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.L.jpg",
                "M": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.M.jpg",
                "XL": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.XL.jpg"
            },
            "89bfea45-5704-4e4b-9aab-b80c3ac1fa9c": {
                "S": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.S.jpg",
                "L": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.L.jpg",
                "M": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.M.jpg",
                "XL": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.XL.jpg"
            }
        },
        "counters": {
            "donors": 467,
            "donated": 5035
        },
        "texts": {
            "name": "NGO Campaign 1",
            "name_short": "Cmpgn 1",
            "resume": "This is an example of campaign description.",
            "resume_short": "CampaignDescription",
            "activities": "",
            "objectives": "",
            "benefits": "",
            "call_to_action": "",
            "worldcoo_url": ""
        }
    },
    ...
]

Gets available campaign from an NGO.

params

availableCampaigns(ArrayList campaigns)

onError(ErrorBody error, RequestType type)

4.4 - getCampaignDetails(String: ngo_id, String: campaign_id)

Response example

{
    "id": "a9fb530d-6270-0cc7-e8a8",
    "alias": "Demo campaign",
    "ngo_id": "2454de2c-cb31-44e5-83bd",
    "status": "active",
    "location": {
        "country": "ESP",
        "name": "Barcelona"
    },
    "categories": ["water_and_energy", "hunger_and_food_security"],
    "currency": "EUR",
    "collection_objective": {
        "total": 500,
        "distribution": {
            "materials": 100,
            "team": 100,
            "transport": 50,
            "others": 200,
            "providers": 50
        }
    },
    "beneficiaries": {
        "direct": 400,
        "indirect": 1000
    },
    "starting_date": 1464277166,
    "ending_date": null,
    "media": {
        "eaba63b5-d7be-4de8-a53e-283c9104a9a6": {
            "S": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.S.jpg",
            "L": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.L.jpg",
            "M": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.M.jpg",
            "XL": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.XL.jpg"
        },
        "89bfea45-5704-4e4b-9aab-b80c3ac1fa9c": {
            "S": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.S.jpg",
            "L": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.L.jpg",
            "M": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.M.jpg",
            "XL": "https://cdn.worldcoo.com/ngos/ee80cf92-d49b-4b7c-9949-9946750ec451/campaigns/f6425839-1e6f-4dd2-8d4d-593d61f5437f/media/eaba63b5-d7be-4de8-a53e-283c9104a9a6.1479739685956.XL.jpg"
        }
    },
    "counters": {
        "donors": 467,
        "donated": 5035
    },
    "texts": {
        "name": "NGO Campaign 1",
        "name_short": "Cmpgn 1",
        "resume": "This is an example of campaign description.",
        "resume_short": "CampaignDescription",
        "activities": "",
        "objectives": "",
        "benefits": "",
        "call_to_action": "",
        "worldcoo_url": ""
    }
}

Gets campaign details

params

campaignDetail(Campaign: campaign)

onError(ErrorBody error, RequestType type)

4.5 - addDonation(Donation donation)

Response example

{
    "id": "17a10455-120d-e767-0206",
    "amount": 5,
    "currency": "EUR",
    "order_code": "9638467",
    "campaign_counters": {
        "total_donated": 60,
        "target": 50000
    }
}

Adds a donation

params

onDonationAdded(DonationResponse donation)

onError(ErrorBody error, RequestType type)

4.6 - cancelDonation(String donationId)

Response example

{
    "id": "17a10455-120d-e767-0206",
    "amount": 5,
    "currency": "EUR",
    "order_code": "9638467",
    "campaign_counters": {
        "total_donated": 60,
        "target": 50000
    }
}

Cancels a donation

params

onDonationCancelled(DonationResponse response)

onError(ErrorBody error, RequestType type)

5 - Widget injection

Widget Workflow example

// Construct and create the widget object
Worldcoo sdk = Worldcoo.getInstance()
sdk.init(context, productionMode)
sdk.getWidgetInjector(Webview, Widget)

// In your "cart" view you can inject the first step widget to let the user decide if he wants to donate
sdk.initialStep()

// The user continues the checkout process
...
// The user pays and the checkout process arrives to the "thanks" step

// In your "thanks" view you can inject the confirmation step widget.
sdk.confirmation()

// If the user decided to donate, the donation will be sent to Worldcoo system and a thanks message will be shown
// Otherwise, no donation will be sent and nothing will be shown

This is the way you can use the Worldcoo Widget inside your mobile app.

Using the Worldcoo Widget is a two-steps process:

For sure, you’ll need to know what the user choice is, so through the InjectorListener you can listen to the change event while the Initial Widget is shown to act in consequence. For example, you’ll need to add the selected donation amount to the cart total amount or maybe you want set a “withDonation” flag to your order.

5.1 - getInjector(Webview webview, Widget widget)

Returns a widget injector instance

params

return

5.2 - addInjectorListener(InjectorListener listener)

Adds a listener to receive user interaction events from the widget injector

params

Through the InjectorListener you can listen for the following events:

5.2.1 - ready(step: int)

Event data example

{
    step: 1
}

Event triggered when the widget is initialized and the user can interact with it.

event data

5.2.2 - change(widgetId: string, checked: boolean, amount: float, donationId: string)

Event data example

{
    widgetId: "f7629749-89aa-43e3-8b4b-9af3925a63ea",
    checked: true,
    amount: 1,
    donationId: "ee6233f3-1d96-43f7-8fae-0da484c395d0"
}

Event triggered when the user changes the donation amount or the checkbox status.

event data

5.3 - initialStep()

Injects the widget first step on the given webview.

5.4 - confirmation()

Injects the widget second step on the given webview.