iOS
Integrate Leatherback's payment gateway into your iOS app.
To run the example project, clone the repo, run
pod installfrom the Example directory, and input your Leatherback public key to test.
Requirements
- Xcode 11.0 or greater
- iOS 10 or greater
Installation
Add the following line to your Podfile:
pod 'LAAS'Then run:
pod installUsage
Step 1: Import the SDK
import LAASStep 2: Configure the Checkout
Create a LeatherBackTransactionParam with your payment details and present the LeatherBackViewController.
Set showPersonalInformation to true to let Leatherback collect the customer's name and email during checkout:
let param = LeatherBackTransactionParam(
amount: 1.50,
currencyCode: .GBP,
channels: [.Card, .Account],
showPersonalInformation: true,
reference: "your unique reference number",
key: "your public key",
isProducEnv: false
)
let paymentVC = LeatherBackViewController(delegate: self, param: param)
present(paymentVC, animated: true)Step 3: Handle Transaction Events
Conform your presenting view controller to the LeatherBackDelegate protocol to receive payment results:
class ViewController: UIViewController, LeatherBackDelegate {
func onLeatherBackError(error: LeatherBackErrorResponse) {
// Handle payment error
print("error \(error.localizedDescription)")
}
func onLeatherBackSuccess(response: LeatherBackResponse) {
// Use this reference to verify payment/transaction with Leatherback
print("success \(response.reference)")
}
func onLeatherBackDimissal() {
// Customer closed the payment gateway manually
print("dismissed")
}
}| Delegate Method | When It's Called |
|---|---|
onLeatherBackSuccess(response:) | Transaction completed successfully. Use response.reference to verify the payment. |
onLeatherBackError(error:) | Transaction failed. Inspect error.localizedDescription for details. |
onLeatherBackDimissal() | Customer closed the payment gateway without completing the transaction. |
Configuration Reference
LeatherBackTransactionParam
LeatherBackTransactionParam| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
amount | Double | Yes | — | The amount to charge the customer |
currencyCode | Currency | Yes | — | Currency code (e.g., .NGN, .GBP) |
key | String | Yes | — | Your Leatherback public key |
showPersonalInformation | Bool | Yes | — | true: Leatherback collects customer name and email at checkout. false: you must provide customerName and customerEmail. |
isProducEnv | Bool | Yes | — | true: use your production key. false: use your test key. |
channels | [PaymentChannels] | No | All channels | Payment channels to display. Set to nil to show all available options. |
reference | String | No | nil | Your unique transaction reference. If empty, defaults to nil — the onLeatherBackSuccess delegate will return a generated reference. |
customerEmail | String | No | nil | Customer's email address. Required when showPersonalInformation is false. |
customerName | String | No | nil | Customer's full name. Required when showPersonalInformation is false. |
When
showPersonalInformationis set tofalse, you must provide bothcustomerNameandcustomerEmail. Omitting them will result in an incomplete checkout.
Available Currencies and Channels
| Currency | Constant | Available Channels |
|---|---|---|
| NGN | .NGN | .Card, .Account |
| GBP | .GBP | .Card, .Account |
Show all channels for a currency
Set channels to nil to automatically display all available payment options:
let param = LeatherBackTransactionParam(
amount: 20.00,
currencyCode: .GBP,
channels: nil, // Shows all available channels for GBP
showPersonalInformation: true,
key: "your public key",
isProducEnv: false
)Restrict to specific channels
Pass only the channels you want to offer:
let param = LeatherBackTransactionParam(
amount: 20.00,
currencyCode: .NGN,
channels: [.Card], // Only show card payments
showPersonalInformation: true,
key: "your public key",
isProducEnv: false
)