Monnify Android SDK

 

Getting started with the Monnify Android SDK

 

 

 

The Monnify Android SDK allows you to accept payments from customers in your Android application via:

  1. Card Payment

  2. Bank Transfer

  3. USSD Payment

  4. Payment by Phone Number

Steps to Implementation

1. Add the dependency for the Monnify SDK

To your root build.gradle file add:

allprojects { repositories { google() mavenCentral() } }

To your app-level build.gradle file add:

dependencies { // ... implementation "com.monnify.android-sdk:monnify-android-sdk:1.1.7" }

2. Create an instance of the Monnify SDK

KOTLIN

class MainActivity : AppCompatActivity() { // ... var monnify = Monnify.instance override fun onCreate(savedInstanceState: Bundle?) { // ... } }

JAVA

3. Set your merchant API key, contract code and application mode

This is done in the onCreate() method of the Launch Activity. The merchant Api Key and contract code can be gotten from your Monnify account dashbard. The application mode should be either TEST or LIVE. The TEST mode works on a sandbox environment and payment can be simulated here. Remember to switch to ApplicationMode.LIVE when generating APKs for production

KOTLIN

JAVA

4. Set your merchant API key, contract code and application mode

This is done when the customer clicks perhaps on a 'Pay' button. The initializePayment() method requires the activity context, an object of the TransactionDetails class, request code, result key You are allowed to set the request code and request key yourself in order to have more control, and to prevent clashes with other args in the main app.

KOTLIN

JAVA


5. Get the outcome of the payment attempt so that you can update application UI after payment gateway is closed.

This is done in the onActivityResult() method of your activity. Use the request code and data key passed in the initializePayment() method to get data returned by the SDK

KOTLIN

JAVA

TADA!

Possible return types from the SDK and meanings below:

Type

Meaning

Type

Meaning

PENDING

Transaction not paid for.

PAID

The customer paid exact amount

OVERPAID

The customer paid more than the expected amount.

PARTIALLY_PAID

The customer paid less than the expected amount.

FAILED

Transaction completed unsuccessfully. This means no payment came in for Account Transfer method or attempt to charge card failed.

PAYMENT_GATEWAY_ERROR

Payment tried but an error occurred on Monnify gateway


Additional initializePayment parameters

Payment Methods specify transaction-level payment methods. Sub-Accounts are accounts that will receive settlement for the particular transaction being initialized. MetaData is map with single depth for any extra information you want to pass along with the transaction. See a sample below:

Kotlin

JAVA