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
- Add
mavenCentral()to your project-levelbuild.gradle:
allprojects {
repositories {
mavenCentral()
}
}- 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
| Method | Type | Required | Description |
|---|---|---|---|
setAmount() | Double | Yes | The amount to charge the customer |
setApiKey() | String | Yes | Your Leatherback API key |
setIsProdEnv() | Boolean | Yes | Set to true for production, false for testing |
setIsCustomerInformationOptional() | Boolean | Yes | Set to false to require customer name and email |
setCustomerName() | String | Yes | Customer's full name |
setCustomerEmail() | String | Yes | Customer's email address |
setEnvironment() | String | Yes | LeatherBackConstants.Environment.DEV, .STAGING, or .PROD |
setCurrencyCode() | String | Yes | Currency code (e.g., LeatherBackConstants.Currency.NGN) |
setReference() | String | Yes | Your unique transaction reference |
setChannel() | List | Yes | Payment 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:
| Status | Constant | Description |
|---|---|---|
| Success | LeatherBackConstants.LeatherBackTransactionStatus.SUCCESS | Transaction completed successfully |
| Failed | LeatherBackConstants.LeatherBackTransactionStatus.FAILED | Transaction failed |
| Aborted | LeatherBackConstants.LeatherBackTransactionStatus.ABORTED | Customer closed the payment gateway manually |
Available Currencies and Channels
Each currency supports specific payment channels:
| Currency | Constant | Available Channels |
|---|---|---|
| NGN | LeatherBackConstants.Currency.NGN | Card, BANK_TRANSFER |
| GBP | LeatherBackConstants.Currency.GBP | Card, 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()