Android SDK

This guide helps developers create next-generation mobile experiences.

Android SDK overview

Accept payments through Network International in your Android app using the SDK’s prebuilt checkout flow and APIs.

Download the SDK and sample app from Android Payment SDK on GitHub.


Requirements

Supported Android version

Use a device or emulator that meets these requirements:

Development environment

Prepare your development environment:

  • Use Kotlin v1.3 or later with coroutine support, or a compatible Java-based Android project.
  • Install Android Studio as your integrated development environment (IDE).

The SDK uses Kotlin coroutines for background and input/output operations to avoid conflicts with third-party dependencies.


Language and currency support

The SDK supports these languages and currencies:

  • Languages: English and Arabic
  • Currencies: AED (United Arab Emirates dirham) by default. Refer to the payment gateway for other supported currencies.

Get started

Use the Furniture Store sample app to explore the SDK, or import the SDK modules into your project.

Included modules

app module

  • Contains the sample merchant app

  • Depends on:

    • payment-sdk
    • payment-sdk-core
    • Android libraries: RxJava, Retrofit, OkHttp and Glide

payment-sdk module

  • Implements the Pay Page for card-based payments
  • Collects card details, handles 3-D Secure (3DS) when required, and submits requests to the payment gateway
  • Returns the result (success/failure) through an Intent bundle

payment-sdk-core module

  • Provides shared interfaces and classes used by other SDK modules
Android SDK app modules and their dependencies

Android SDK app modules

Download the SDK and sample app

Clone the SDK and sample project from GitHub:

git clone https://github.com/network-international/payment-sdk-android.git

Alternatively, download the ZIP if you prefer not to use Git.

After downloading:

  1. Open the project in Android Studio.
  2. Allow Gradle to sync and download dependencies.
  3. Run the Furniture Store sample app on your emulator or physical device.

Run the app on Android 4.4 (API level 19) or later.

Run the sample app and merchant server

Use the sample app and Sample Merchant Server to test the SDK locally.

The sample merchant server is available in PHP and JavaScript (Node.js) versions.

Step 1: Import the sample merchant app

Import the project:

  1. Open Android Studio.

    Android Studio welcome screen with the option to open an existing project

    Open a project in Android Studio

  2. Select Open an existing project from the welcome screen.

  3. Browse to the folder where you cloned the SDK (payment-sdk-android).

  4. Select the root directory.

  5. Select Open.

  6. Allow Gradle to sync and download any missing dependencies.

  7. Run the app in an emulator or on a physical device after the project loads.


Step 2: Run the sample merchant server

The included Node.js sample merchant server simulates a backend environment. It communicates with the payment gateway and serves mock payment data.

Prerequisites

Install Node.js before configuring the server.


Configuration

Configure the sample server:

  1. Install the dotenv package:
    npm install dotenv
  2. Open the app.js file.
  3. Add the following line to the file:
    require('dotenv').config();
  4. Create a .env file with the following settings:
    API_KEY=YOUR_API_KEY
    IDENTITY_API_URL=YOUR_IDENTITY_API_URL
    GATEWAY_API_URL=YOUR_GATEWAY_API_URL
    PORT=3000
    REALM=YOUR_REALM
  5. Replace the placeholders using the values provided in the N-Genius Online portal.

Replace the placeholders as follows:

  • YOUR_API_KEY: Your API key.
  • YOUR_IDENTITY_API_URL: Your full identity API URL, including https://.
  • YOUR_GATEWAY_API_URL: Your full payment gateway API URL, including https://.
  • YOUR_REALM: Your realm.

Use the documented sandbox URLs for testing. Read Create an order for credential and endpoint guidance.


Start the server

Open a terminal in the project directory and run:

node app.js

Open the local server’s health URL in your browser:

http://localhost:3000/health

The browser displays the sample server’s working status when the server is running. If the server does not load, check the terminal logs for errors.

Health page showing that the local sample server is running

Sample server working status


Step 3: Connect the app to the server

Configure the sample app’s server address:

  1. Open the app module’s build.gradle file.
  2. Set BASE_URL using buildConfigField to the merchant server address.

Use the following configuration for the local server in an Android emulator:

      debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", "\"http://10.0.2.2:3000/\""
        }

        release {
            minifyEnabled true
            shrinkResources true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", "\"http://10.0.2.2:3000/\""
        }

For physical devices, connect the device and your development machine to the same Wi-Fi network.


Step 4: Run the sample app

Select Run in Android Studio to launch the app.

The sample app opens with an option to make a payment.

Demo Store home screen with items and a payment option

Demo Store

Before testing payments, configure the sample app:

  1. Tap the gear icon in the app’s top right corner.

  2. Tap + next to Merchant Attributes.

  3. Enter a key-value pair.

  4. Tap Add.

    Demo app screens for adding merchant attributes

    Merchant attributes

  5. Tap + next to Environments.

  6. Enter a name, API key, outlet reference and realm from the portal.

  7. Tap Add.

    Demo app screens for adding a payment environment

    Add an environment

  8. Tap the back button to return to the home screen.

For credential details, read Create an order.

Step 5: Make a test payment

Use a sandbox test card to test payments:

  1. Select items from the home screen.
  2. Tap Pay.
Demo app home screen with selected items and the Pay button

Select items for payment

Enter the test card number with any name, expiry date and card verification value (CVV) on the payment screen. Tap Make Payment.

Payment screen for a test card number with any name, expiry date and CVV

Enter card details

For transactions requiring a 3DS challenge, enter the one-time passcode (OTP) on the challenge screen. Tap Submit. Frictionless transactions skip this screen.

Android 3DS challenge screen prompting for a one-time passcode

3DS challenge

The app displays a "Payment Success" message when the payment succeeds.

Payment success screen confirming a successful payment

Successful payment


SDK payment flow

When you tap PAY WITH CARD in the sample app, the app requests a payment session from the sample merchant server.

The app then hands control to the Payment SDK, which performs these actions:

  • Displays a secure card entry form
  • Handles 3DS authentication when required
  • Returns a success or failure response to the app

Payment API reference

Configure the Payment SDK to initiate card payments and handle payment gateway results in your Android app.


SDK modules

Import only the SDK components your integration uses.

Required modules

At minimum, import the following Gradle modules:

payment-sdk
payment-sdk-core

Optional: Additional modules

Import additional modules only for payment methods your integration uses. This reduces your Android application package (APK) size and build time.


PaymentClient

The PaymentClient class is your main entry point to initiate and manage payment flows from within your app.

Initialisation

Instantiate PaymentClient using an Activity, not a Context. The SDK returns payment results through onActivityResult().

class PaymentClient(private val context: Activity)
📘

Legacy activity results

Android’s onActivityResult pattern is legacy. For new saved card integrations, use the launcher-based approach.

For usage examples, refer to the Furniture Store sample app.

📘

Deprecated saved card flow

Saved card flows using PaymentClient and onActivityResult are deprecated. Do not use them for new integrations.

Use the launcher-based saved card flow.


Amount representation

The SDK represents amounts using BigDecimal in major currency units.

Each currency has an exponent (the number of decimal places for its minor unit). AED uses an exponent of 2, with 100 fils per dirham:

CurrencyExponentFormatSDK amount exampleEquivalent minor units
AED2major.minorAED 0.00 as 0.000 fils

Card payments

Initiate card payments and handle their results using the SDK.


Payment flow

A card payment follows this sequence:

  1. The merchant app requests a payment session from your merchant server.
  2. The merchant server returns payment session details.
  3. The app calls launchCardPayment() with the required parameters.
  4. The SDK presents a card input form and handles 3DS when required.
  5. The payment gateway processes the payment and returns a result.
  6. The SDK returns the result to the merchant app through onActivityResult().

Launch a card payment

Use the following method to launch a card payment:

📘

Saved card payments

Do not use the deprecated PaymentClient and onActivityResult approach for saved card payments.

Use the launcher-based saved card flow.

paymentClient.launchCardPayment(
    request: CardPaymentRequest,
    requestCode: Int
)

This method launches an activity to collect card details and manage the 3DS flow. When payment completes, the SDK triggers onActivityResult() in your calling activity.


Saved card payments using the launcher

Launch saved card payments with the launcher pattern and receive results through a callback.

1. Initialise the launcher

private val savedCardPaymentLauncher = SavedCardPaymentLauncher(this) {
    viewModel.onPaymentResult(it)
}

2. Trigger a saved card payment

savedCardPaymentLauncher.launch(
    SavedCardPaymentRequest.Builder()
        .payPageUrl(payPageUrl)
        .gatewayAuthorizationUrl(authorizationUrl)
        .build()
)

3. Handle the payment result

fun onPaymentResult(result: PaymentsResult) {
    when (result) {
        PaymentsResult.Success -> saveCardFromOrder(orderReference)
        PaymentsResult.Authorised -> { /* handle authorised state */ }
        PaymentsResult.Cancelled -> { /* handle cancellation */ }
        is PaymentsResult.Failed -> { /* handle failure using result.error */ }
    }
}

Use this launcher-based approach for new saved card integrations. It avoids the deprecated PaymentClient and onActivityResult pattern.


Handle the result

Example of handling the card payment result:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    
    if (requestCode == CARD_PAYMENT_REQUEST_CODE) {
        when (resultCode) {
            Activity.RESULT_OK -> onCardPaymentResponse(
                CardPaymentData.getFromIntent(data!!)
            )
            Activity.RESULT_CANCELED -> onCardPaymentCancelled()
        }
    }
}

If the customer cancels the payment, for example by pressing Back, the SDK returns RESULT_CANCELED.

Result codes

After the SDK returns control, evaluate the outcome using CardPaymentData:

override fun onCardPaymentResponse(data: CardPaymentData) {
    when (data.code) {
      	CardPaymentData.STATUS_PAYMENT_AUTHORIZED,
				CardPaymentData.STATUS_PAYMENT_PURCHASED,
        CardPaymentData.STATUS_PAYMENT_CAPTURED -> {
            view.showOrderSuccessful()
        }
        CardPaymentData.STATUS_PAYMENT_FAILED -> {
            view.showError("Payment failed")
        }
        CardPaymentData.STATUS_GENERIC_ERROR -> {
            view.showError("Generic error (${data.reason})")
        }
        else -> IllegalArgumentException("Unknown payment response (${data.reason})")
    }
}

Result code descriptions

Status codeDescription
STATUS_PAYMENT_CAPTUREDThe payment gateway captured the payment (SALE action).
STATUS_PAYMENT_PURCHASEDThe payment succeeded (PURCHASE action).
STATUS_PAYMENT_AUTHORIZEDThe payment gateway authorised the payment (AUTH action).
STATUS_PAYMENT_FAILEDThe payment failed at the payment gateway.
STATUS_GENERIC_ERRORA client-side error occurred, such as a network issue or unexpected exception.

Read Get a result from an activity in the Android documentation for callback details.

Create a card payment request

Before launching a card payment, create a CardPaymentRequest object using the CardPaymentRequest.Builder class.

The builder requires one parameter:

  • gatewayUrl: The URL your merchant server provides after initiating order creation. Use this URL to build the card payment request.

Currency units for order creation

The SDK uses BigDecimal in major units. During order creation, send the payment gateway an integer representing the amount in the currency’s minor unit.

Convert major units to minor units as follows:

  • AED 1.00 → 100 fils
  • AED 3.99 → 399 fils
  • USD 1.00 → 100 cents

Refer to the PaymentOrderApiInteractor class in the sample merchant app for more information.


Configure project dependencies

Import the SDK modules into your Android Studio project:

  1. Right-click your main app module.
  2. Select New > Import Module....
  3. Select the payment-sdk folder.
  4. Select Open.
  5. Right-click your main app module.
  6. Select Open Module Settings.
  7. Go to Project Structure > Dependencies.
  8. Select +.
  9. Select Module Dependency.
  10. Select all the SDK modules in the list. Hold Shift to select multiple modules.
  11. Select OK.

The payment-sdk module imports its additional dependencies automatically. After adding the modules, your project is ready to use the SDK.


Use executeThreeDS()

📘

Deprecated saved card flow

Saved card flows that use PaymentClient and onActivityResult are deprecated, including flows that combine 3DS handling with legacy activity results.

Do not use these flows for new integrations. Use the launcher-based saved card flow.

Use executeThreeDS() to trigger the EMV 3-D Secure flow for tokenised payments, such as saved cards. This authenticates the cardholder.

paymentClient.executeThreeDS(
    paymentResponse: PaymentResponse,
    requestCode: Int
)

The method accepts these parameters:

  • paymentResponse: A PaymentResponse containing the full JSON response from the N-Genius saved card payment API.
  • requestCode: An Int that distinguishes this callback in onActivityResult().

Optional: Customise SDK colours

Override colour resources in your project’s colors.xml file to match your brand.

Example:

<color name="sdk_primary_color">#FF6200EE</color>
<color name="sdk_secondary_color">#FF03DAC5</color>

Refer to the SDK theming documentation or contact your account team for the full list of customisable keys.

Read the webhooks guide for webhook integration details.

Latest SDK updates

Android SDK v7.0.0 includes these updates:

  • Unified Payment Page support
  • AANI QR code payments
  • Click to Pay enhancements
  • SDK theming and localisation updates
  • Payment user interface updates
  • Testing and environment management enhancements

View Android SDK v7.0.0 release notes

© Network International LLC. All Rights Reserved.