Android

The Leatherback Android SDK provides a secure, streamlined way to integrate our payment gateway directly into your mobile application. By utilizing our pre-built checkout UI, you can accept payments via various channels without the overhead of building complex payment interfaces from scratch.

Installation

  1. Add mavenCentral() to your project-level build.gradle:
allprojects {
    repositories {
        mavenCentral()
    }
}
  1. Add the SDK dependency to your module-level build.gradle:
implementation 'co.leatherback:leatherback-checkout-android:1.0.17-alpha02'
📦

Check Maven Central for the latest version of the SDK.

Integration

Step 1: Create an Activity Result Launcher

Register an ActivityResultLauncher to handle the checkout result. The SDK returns a LeatherBackTransactionResponse containing the transaction status.

   private val startActivityResult: ActivityResultLauncher<Intent> = registerForActivityResult(
       ActivityResultContracts.StartActivityForResult()
   ) {
       val data = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
           it.data?.getParcelableExtra(
               LeatherBackConstants.IntentParams.LEATHERBACK_RESULT,
               LeatherBackTransactionResponse::class.java
           )
       } else {
           it.data?.getParcelableExtra(
               LeatherBackConstants.IntentParams.LEATHERBACK_RESULT
           )
       }
       if (it.resultCode == RESULT_OK && data != null) {
           when (data.status) {
               LeatherBackConstants.LeatherBackTransactionStatus.SUCCESS -> {
                   // Payment completed successfully
               }
               LeatherBackConstants.LeatherBackTransactionStatus.FAILED -> {
                   // Payment failed
               }
               LeatherBackConstants.LeatherBackTransactionStatus.ABORTED -> {
                   // Customer closed the payment gateway manually
               }
           }
       }
   }

Step 2: Build the Checkout Configuration

Use the LeatherbackCheckoutParcel.Builder to configure the payment details.

   val leatherbackCheckout = LeatherbackCheckoutParcel
       .Builder()
       .setAmount(20.toDouble())
       .setApiKey("YOUR_API_KEY_GOES_HERE")
       .setIsProdEnv(false)
       .setIsCustomerInformationOptional(false)
       .setCustomerName("John Doe")
       .setCustomerEmail("[email protected]")
       .setEnvironment("YOUR_ENVIRONMENT_GOES_HERE")
       .setCurrencyCode(LeatherBackConstants.Currency.NGN)
       .setReference("YOUR_UNIQUE_REF_GOES_HERE")
       .setChannel(LeatherBackConstants.Payment.Channel.getValue(LeatherBackConstants.Currency.NGN))
       .build()

Builder Parameters

MethodTypeRequiredDescription
setAmount()DoubleYesThe amount to charge the customer
setApiKey()StringYesYour Leatherback API key
setIsProdEnv()BooleanYesSet to true for production, false for testing
setIsCustomerInformationOptional()BooleanYesSet to false to require customer name and email
setCustomerName()StringYesCustomer's full name
setCustomerEmail()StringYesCustomer's email address
setEnvironment()StringYesLeatherBackConstants.Environment.DEV, .STAGING, or .PROD
setCurrencyCode()StringYesCurrency code (e.g., LeatherBackConstants.Currency.NGN)
setReference()StringYesYour unique transaction reference
setChannel()ListYesPayment channels for the selected currency

Step 3: Initialize Payment

Pass the checkout configuration and activity result launcher to CheckoutManager.initialize() to launch the payment flow.

   CheckoutManager.initialize(
       context,
       leatherbackCheckout,
       startActivityResult,
       onInitializeError = {
           // Handle initialization error
       }
   )

Transaction Status Types

The LeatherBackTransactionResponse returns one of the following statuses:

StatusConstantDescription
SuccessLeatherBackConstants.LeatherBackTransactionStatus.SUCCESSTransaction completed successfully
FailedLeatherBackConstants.LeatherBackTransactionStatus.FAILEDTransaction failed
AbortedLeatherBackConstants.LeatherBackTransactionStatus.ABORTEDCustomer closed the payment gateway manually

Available Currencies and Channels

Each currency supports specific payment channels:

CurrencyConstantAvailable Channels
NGNLeatherBackConstants.Currency.NGNCard, BANK_TRANSFER
GBPLeatherBackConstants.Currency.GBPCard, ACCOUNT

Return all channels for a currency

Use LeatherBackConstants.Payment.Channel.getValue() to automatically include all available channels for a given currency:

   val leatherbackCheckout = LeatherbackCheckoutParcel
       .Builder()
       .setChannel(LeatherBackConstants.Payment.Channel.getValue(LeatherBackConstants.Currency.GBP))
       .build()

Restrict to specific channels

To allow only specific channels for a currency, pass them as a list:

   val leatherbackCheckout = LeatherbackCheckoutParcel
       .Builder()
       .setChannel(listOf(LeatherBackConstants.PaymentMethods.BANK_TRANSFER))
       .build()