Skip to content
Last updated

iF returns iOS 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 IOS 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 iOS 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 (Swift Package Manager)

In Xcode, navigate to FileSwift PackagesAdd Package Dependency and enter the repository URL:

Repository
https://gitlab.com/runif/ifreturns-mobile-sdk

In Version, select Up to Next Major and take the default option. Then choose iFreturnsMobileSDK in the Package Product column. Once the SDK has been added, import the library in your code:

import IfreturnsMobileSDK

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

swift
let returnView = IfreturnsView(eventListener: self)
view.addSubview(returnView)

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

swift
returnView.initialize(publicToken: String, orderData: OrderData)

Result

If it is successful, ifreturnsInitialized() will be called in the listener you supplied. If it is not successful ifreturnsFailed() 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

swift
returnView.load(flowType: String, sandbox: Boolean)

Result

If it is successful, ifreturnsLoaded() will be called in your listener. If anything goes wrong, ifreturnsFailed() 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.

ifreturnsItemsSelected

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

swift
func ifreturnsItemsSelected (returnView: IfreturnsView, returnItems: [ReturnItem]) {
}

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.

swift
func ifreturnsFailed(returnView: IfreturnsView, error: IfreturnsError) {
   // handle error
}