Skip to content
Last updated

iF returns Android SDK

Overview

iFreturns products are built to run on desktop and mobile browsers. In case our products require to run in an app, they need to run in something called a web view. This is a view that can render web content inside an app, just like a browser tab would.

This guide details how to integrate the iF returns widget into your Android app. The integration consists in adding iF returns widget as a view, and performing a few operations on it. Our goal with this integration is to offer you the same simple development experience as you have on the web.

Set up Android SDK - Client Session

The client session connection model should only be used in flows where the widget is to collect data on the return request, but without storing the final request. In this model , a client session will be generated when the SDK is initialised. This session will be used by the view to retrieve the order data to be displayed to the customer.

Add the SDK

Add the iF returns Mobile SDK repository in the apps build.gradle file.

Repository
repositories {
  maven {
     url 'https://cdn.ifreturns.com/mobile-sdk/'
  }
}

If you are using Java, add compile options for the callbacks to support Java version 1.8 in the apps build.gradle.

android {
   ...
   compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
   }
   ...
}

Add the SDK as a dependency to your app’s build.gradle:

dependencies {
   implementation 'com.ifreturns.mobile:sdk:1.x.x'
}

Create the View

The first step to render the iF returns widget, is to create an instance of the view where it will be loaded, and adding it to your view hierarchy.

Parameters

To create the view the following parameters must be included:

ParameterTypeDescription
IfreturnsEventListenerdelegateListener that receives events during the execution of the return flow.

Sample Code

kotlin
final IfreturnsView ifreturnsView = new IfreturnsView(
   callback
);

The SDK will notify you of events via an event listener that you will need to implement. This parameter is not optional.

Initialize the View

Before content is rendered into returnView, it needs to be configured. You can do this by initializing the view. After the view has been created and added, the initialize() method must be called to configure the library .

Parameters

The initialize() method uses the following parameters:

ParameterTypeDescription
publicTokenstringToken assigned to your merchant code and your domain.
orderDataobjectData of the sales order that contains the products the customer wants to return.

The orderData object has the same format as the Javascript SDK.

Sample Code

kotlin
returnView.initialize(publicToken, orderData)

Result

If it is successful, onIfreturnsInitialized() will be called in the listener you supplied. If it is not successful onIfreturnsFailed() will be called instead.

Display the View

Once the view has been initialized it can be displayed in the app. To display the view you have to call the load() method. Once the view is opened the customer can select the resolution for each returned product.

Parameters

The load() method uses the following parameters:

ParameterTypeDescription
flowTypestringReturn steps that will be supported by the widget. Following values are accepted
  • ITEMS_SELECTION
sandboxbooleanFlag to indicate that the test environment should be used. The default is false.

Sample Code

kotlin
returnView.load(flowType, sandbox)

Result

If it is successful, onIfreturnsLoaded() will be called in your listener. If anything goes wrong, onIfreturnsFailed() will be called.

Handle the view response

When the view is loaded, and the customer has confirmed the list of items he/she wants to return, all the data collected during the executed process flow will be returned via the event listener configured in the view. This data must be used by the merchant in order to finalise the customer's return flow on his website.

onIfreturnsItemsSelected

After the customer has selected all the items to be returned, the onIfreturnsItemsSelected() will be called in your listener. If the customer closes the view before completing the process, the method onIfreturnsDismissed() will be called. If something goes wrong with the process, onIfreturnsFailed() will be called instead.

kotlin
func onIfreturnsItemsSelected (returnView, returnItems) {
}

The returnItem object has the same format as the Javascript SDK.

Handling Errors

This will handle all the errors from the previous implementations. IfreturnsError type will contain the information needed to show to the user and also to handle all the states of the listener.

kotlin
func onIfreturnsFailed(returnView, error) {
   // handle error
}