Skip to content

Integration Instructions

The ItavioSdk requires a minimum Android API level 16. To integrate ItavioSdk into your Android application:

Step 1 - Adding Dependencies

Using Android Studio

Up-to-date Android Studio is recommended and Gradle support is required*.

(1) Add the ItavioPlugin.aar file to your project's libs folder

(2) In your project's build.gradle file add the libs folder to the available repositories

repositories {
    flatDir {
        dirs 'libs'
    }
}

(3) In your project's build.gradle file add these 2 lines to dependencies

dependencies {
    compile 'com.loopj.android:android-async-http:1.4.8'
    compile(name:'ItavioPlugin', ext:'aar')
}

Step 2 - Configure AndroidManifest.xml

(1) If you are not already extending the Application class, you should do so.

<Application android:name=".MyApplication" ...>
  ...
</Application>

(2) Add the following activity within the <Application>...</Application> tags:

<activity android:name="com.itavio.android.plugin.ui.Ui" />

Step 3 - Initialize Itavio

(1) Import this package into your MyApplication class.

import com.itavio.android.plugin.controller.ItavioSdk;

(2) In your MyApplication class call ItavioSdk.initialize(CONTEXT, SECRET_KEY_ID, SECRET_KEY); with the application's context, as well as the Itavio provided secret key id and secret key in the onCreate method.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // Initialize the ItavioSdk
        ItavioSdk.initialize(this, SECRET_KEY_ID, SECRET_KEY);
    }
}

Step 4 - Using Itavio

Be sure that the ItavioSdk has been initialized before calling any of these methods.

Imports

(1) Import these packages into the classes that will be making calls to the ItavioSdk:

import com.itavio.android.plugin.Tuple;
import com.itavio.android.plugin.controller.ItavioSdk;
import com.itavio.android.plugin.controller.SdkResponseHandler;
import com.itavio.android.plugin.model.*;

Performing a purchase

(1) To begin a purchase confirm with Itavio that a purchase should proceed

ItavioSdk.startDebit(Double.valueOf(txtPurchaseAmount.getText().toString()), "USD", new SdkResponseHandler<Tuple<Boolean, TxnStatus>>() {
    @Override
    public void onSuccess(Tuple<Boolean, TxnStatus> obj) {
        if (obj.getLeft()) {
            // Purchase has start
            // Call the store's purchase method

        }
        else
        {
            // Purchase failed
        }
    }

    @Override
    public void onError(Object obj, Throwable e) {
        // An error has occurred
    }
});

(2) Once the purchase has completed from the store inform Itavio that the purchase has been completed

ItavioSdk.completeDebit(new SdkResponseHandler<Tuple<Boolean, TxnStatus>>() {
    @Override
    public void onSuccess(Tuple<Boolean, TxnStatus> obj) {
        // The purchase has been processed
    }

    @Override
    public void onError(Object obj, Throwable e) {
        // An error has occurred
    }
});

(3) If the purchase was cancelled use the ItavioSdk.cancelDebit method instead of ItavioSdk.completeDebit method.

Check for the Parent Itavio App

(1) To determine whether or not the parent app is installed on a users device use

if (!ItavioSdk.checkForParent()) {
    // Itavio parent app is not installed
}

(2) Optionally, to present the user with a dialog to get the Itavio Parent App if it isn't installed use

if(!ItavioSdk.checkForParent(true)) {
  // Itavio parent app is not installed
}

Check the user's remaining balance

(1) To get the user's remaining balance use

ItavioSdk.getBalance(new SdkResponseHandler<Tuple<Double, String>>() {
    @Override
    public void onSuccess(Tuple<Double, String> obj) {
        // obj.getLeft() is a Double that represents the remaining balance.
    }

    @Override
    public void onError(Object obj, Throwable e) {
        // An error has occurred
    }
});

Retrieve the details of the user's limit

(1) To get the user's remaining balance, limit cap, and reset date use

if (ItavioSdk.isEnabled()) {
    ItavioSdk.getLimitDetails(new SdkResponseHandler<Tuple4<Double, Double, Date, String>>() {
        @Override
        public void onSuccess(Tuple4<Double, Double, Date, String> obj) {
            // obj.get_1() is the balance of the limit as a double
            // obj.get_2() is the limit cap as a double
            // obj.get_3() is the date and time the limit renews
            // obj.get_4() is the String currency code of the limit cap and balance
        }

        @Override
        public void onError(Object obj, Throwable e) {
            // An error has occurred
        }
    });
}

Proguard

If you encounter issues with proguard, add the following to your proguard.cfg file:

-keep public class com.itavio.** { *; }

Best Practices - Android

Initializing

It is best to initialize Itavio as early as possible, in the onCreate of the application is recommended.

Checking for the Parent App

Check for the parent app and if necessary present the user with the option to get the parent app every time the IAP storefront is opened. In the case that the user has removed the Parent App, they will be presented with the option to disassociate the plugin from their account.

Showing the Get App Dialog

If the user does not have the Parent App, the Get App Dialog should be shown every time the user accesses the IAP storefront until the user completes a transaction.

Testing Tips

Features to test + Detecting/linking with the Parent App + Retrieving the user's balance + Performing a purchase

Comments