Trustly Android SDK

Trustly fully supports native Android apps. On this page, you will find instructions on how-to configure Trustly in Android apps.

Trustly Android SDK has been created for Android to simplify the process of implementing the functionality needed when using Trustly within an Android app. It provides a self-contained WebView that enables the Trustly Checkout within your application.

CUSTOM URL SCHEME

To properly integrate Trustly’s SDK, it’s required to use a custom URL scheme for your app. By doing so, Trustly can redirect users back to your app after using external identification apps such as Mobile BankID.

It's a straightforward process; you can follow any Tutorial on Android Custom URL Schemes. The URL scheme can be registered using the following method:

  • Include it in the "URLScheme" attribute when making an API call to Trustly.
Attribute nameDescriptionTypeExample
URLSchemeThe URL scheme used to redirect users back to your appTextyourCustomURLScheme://

Example:

{
    "method": "Deposit",
    "params": {
        "Signature": "f4ThjuMqbsdG6u ... S16VbzD4h==",
        "UUID": "258a2184-2842-b485-25ca-293525152425",
        "Data": { 
            "Username": "merchant_username",
            "Password": "merchant_password",
            "Attributes": {
                "Country": "SE",
                "Locale": "sv_SE",
                "URLScheme":"myapp://"
                ...

Configure Trustly Android SDK:

Authenticate to Github Packages

To authenticate with Github Packages you need to add your GitHub username and a GitHub Access Token to your project level build.gradle file.

Make sure that you your token have both read and write permissions for packages.

🚧

Do not commit these credentials to your repo.

Add library to your dependencies

Go to app -> build.gradle and add the following code to your dependencies:

implementation 'trustly.android.library:trustly-android-library:+'

Create WebView

Go to app -> src -> main-> res -> layout -> activity_main.xml and add the following code:

<WebView
   android:id="@+id/webview"
   android:layout_width="match_parent"
   android:layout_height="match_parent"/>

Modify MainActivity
Import dependencies inside your MainActivity:

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import android.webkit.WebView;
import com.trustlyAndroidLibrary.TrustlyWebView;

Add the following code to your MainActivity:

@Override

protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);


   setContentView(R.layout.activity_main);

   WebView main = findViewById(R.id.webview);


   final TrustlyWebView trustlyView = new TrustlyWebView(this, 
   "< Insert Trustly Url >");

   main.addView(trustlyView);
}

Add permission for Internet

Go to app -> src -> main -> AndroidManifest.xml and add the following code:

<uses-permission android:name="android.permission.INTERNET"/>

Checkout Events

If you want more control of your Checkout flow you can choose to opt-in to receiving and handling Checkout events.

You opt-in by creating an implementation of the TrustlyEventHandler interface.

public interface TrustlyEventHandler {

  void onTrustlyCheckoutSuccess(TrustlySDKEventObject eventObject);

  void onTrustlyCheckoutRedirect(TrustlySDKEventObject eventObject);

  void onTrustlyCheckoutAbort(TrustlySDKEventObject eventObject);

  void onTrustlyCheckoutError(TrustlySDKEventObject eventObject);

}

and passing your implementation to the TrustlyWebView.

TrustlyEventHandler eventHandler = new TrustlyEventHandlerImplementation();
TrustlyWebView trustlyView = new TrustlyWebView(this, trustlyCheckoutUrl, eventHandler);

📘

If you choose to subscribe for TrustlyCheckoutEvents you will need to handle all opening of third party applications yourself!