Android SDK

Installation

Forter3DS SDK supports installation via Maven

Requirements

Minimum version: Android 5.1 (API level 22)

Step 1: Add to Maven

  • If the Gradle version is 7.0 and above:
    Inside your app's settings.gradle, append the following repository, provided below, to your dependencyResolutionManagement block.
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        ...
        maven {
            url "https://mobile-sdks.forter.com/android"
            credentials {
                username "<username-provided-by-forter>"
                password "<password-provided-by-forter>"
            }
        }
    }
}
  • If the Gradle version is earlier than 7.0:
    Inside your app's build.gradle, append the following repository, provided below, to your repositories block.
repositories {
    ...
    maven { url 'https://maven.google.com' }
    maven {
        url "https://mobile-sdks.forter.com/android"
        credentials {
            username "<username-provided-by-forter>"
            password "<password-provided-by-forter>"
        }
    }
}

NOTE: Specify and commit the credentials to your Git. Note that these credentials are not sensitive, but we keep them private to prevent bots and search engines from accessing the repository.

Step 2: Add the Forter3DS SDK dependency

Add the Forter3DS SDK as a dependency to your app's build.gradle file under the dependencies block. Use the dependency provided below.

implementation 'com.forter.mobile:forter3ds-android:1.2.0@aar'

Step 3: Manifest Permissions

Additionally, the Forter3DS SDK requires the common permission: read phone state. This permission is typically required by many applications and components. If you have not already included them in your permissions list, please add them to your manifest file.

<!-- Forter3DS SDK permissions -->
<uses-permission android:name="android.permission.INTERNET" />

Initializing the SDK

The Forter3DS SDK must be initialized from the main Application Context. If your app is not currently using an Application class, please add one and register it in the Manifest.

Application Class

  1. Instantiation - You can obtain an instance of the Forter3DS object by calling Forter3DS.getInstance. This call generates a singleton object for the Forter3DS object.

  2. Initialization - To initialize the Forter3DS SDK, add the code provided (Java / Kotlin) to the onCreate method of your application class.

public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.filters);
     // initialize Forter3DS
     Forter3DS.getInstance().setup(this.applicationContext);
}
override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     setContentView(R.layout.checkout_activity)
     // initialize Forter3DS
     Forter3DS.getInstance().setup(this.applicationContext)
}

Do Challenge if Needed

Using the managedOrderToken that was received from the backend (see Order API, the doChallengeIfNeeded(token:activity:delegate:)should be called. This method will display the challenge if required, otherwise, it will continue with the transaction.

Method

doChallengeIfNeeded(token:activity:delegate:):
Perform a managed order challenge if needed.

Parameters

  • token (String) : The managed order token obtained from the merchant's backend.

  • activity (Activity) : The activity responsible for presenting the challenge UI.

  • delegate (FTR3DSManagedOrderDelegate) : The delegate that will receive the challenge result.

Example

Forter3DS.doChallengeIfNeeded("your_managed_order_token_here", YourPresentingActivity.this, this);
Forter3DS.doChallengeIfNeeded("your_managed_order_token_here", this, this)

Callback

The FTR3DSManagedOrderDelegate protocol provides a structured way to handle the completion of managed order flows. By adopting this protocol, developers can respond to the completion of managed order challenges and handle any potential errors that may arise during the process.

Method

challengeCompleted(error:): This method is called when the managed order flow is completed, either successfully or with an error. It provides developers with information about the status of the managed order challenge.

Parameter

  • error: An optional parameter of type Error that indicates whether an error occurred during the managed order flow. If no error occurred, this parameter will be null.

Example

public class PaymentActivity extends Activity implements FTR3DSManagedOrderDelegate {
    
    public void performManagedOrderFlow() {
        // Initiating the managed order flow
    }
    
    // FTR3DSManagedOrderDelegate method
    public void challengeCompleted(Error error) {
        if (error != null) {
            // Handle error scenario
            System.out.println("Managed order flow completed with error: " + error.getMessage());
        } else {
            // Handle success scenario
        }
    } 
}   
class PaymentActivity : Activity(), FTR3DSManagedOrderDelegate {
    
    fun performManagedOrderFlow() {
        // Initiating the managed order flow
    }
    
    // FTR3DSManagedOrderDelegate method
    override fun challengeCompleted(error: Error?) {
        if (error != null) {
            // Handle error scenario
            println("Managed order flow completed with error: " + error.message)
        } else {
            // Handle success scenario
        }
    }
}