Android SDK

This library aids in processing payment through the following channels

  • Card
  • Verve Wallet
  • QR Code
  • USSD

Usage

There are three steps you would have to complete to set up the SDK and perform transaction.

  • Install the SDK as a dependency
  • Configure the SDK with Merchant Information
  • Initiate payment with customer details

Installation

To install the project, add the following to your root project's build.gradle


    allprojects {
        repositories {
            google()
            jcenter()
            maven { url "http://dl.bintray.com/techquest/maven-repo" }
        }

        //... other stuff
    }

Then add the following to the your app project's build.gradle


    dependencies {
        def versionName = 'latest-version'
        implementation "com.interswitchng:isw-mobile-payment-sdk:$versionName"
    }

now build the project.

Configuration

You would also need to configure the project with your merchant credentials.

Java


public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // configure sdk
        configureSDK();
    }

    public void configureSDK() {
        // use provided configuration for your merchant account
        String merchantId = "<your merchantId>"; 
        String merchantCode = "<your merchantCode>";
        String merchantKey = "<your merchantKey>";

        // create sdk configuration
        IswSdkConfig config = new IswSdkConfig(merchantId, 
                        merchantKey, merchantCode, "566");

        // uncomment to set environment, default is Environment.TEST
        // config.setEnv(Environment.PRODUCTION);

        // initialize sdk at boot of application
        IswMobileSdk.initialize(this, config);
    }
}

Once the SDK has been initialized, you can then perform transactions.

Performing Transactions

You can perform a transaction, once the SDK is configured, by providing the payment info and a payment callback, like so:

Java

    public class PurchaseActivity extends AppCompatActivity implements IswMobileSdk.IswPaymentCallback  {

        @Override
        protected void onCreate() {
            //.. other stuff
            payButton.setOnclickListener((v) -> {
                initiatePayment();
            });
        }


        @Override
        public void onUserCancel() {
            // called when the user cancels
        }

        @Override
        public void onPaymentCompleted(IswPaymentResult result) {
            // called when the transaction was completed (success/failure)
        }

        private void initiatePayment() {
            // set customer info
            String customerId = "<customer-id>",
                    customerName = "<customer-name>",
                    customerEmail = "<[email protected]>",
                    customerMobile = "<customer-phone>",
                    // generate a unique random
                    // reference for each transaction
                    reference = "<your-unique-ref>";

            // amount in kobo e.g. "N500.00" -> 50000
            long amount = providedAmount; // e.g. 50000

            // create payment info
            IswPaymentInfo iswPaymentInfo = new IswPaymentInfo(customerId,
                    customerName, customerEmail, customerMobile,
                    currencyCode, reference, amount);

            // trigger payment with info and payment-callback
            IswMobileSdk.getInstance().pay(iswPaymentInfo, this);
        }

    }

Handling Result

To handle result all you need to do is handle the result in the callback methods: whenever the user cancels, IswPaymentCallback.onUserCancel is called, and when the transaction is complete, IswPaymentCallback.onPaymentCompleted is called with the result: an instance of IswPaymentResult

HANDLING RESULT
Field Type Meaning
responseCode String txn response code
responseDescription String txn response code description
isSuccessful boolean flag indicates if txn is successful
transactionReference String reference for txn
amount Number txn amount
channel String channel used to make payment: one of CARD, WALLET, QR, USSD

Java


public class PurchaseActivity extends AppCompatActivity implements IswMobileSdk.IswPaymentCallback  {
    // ... other stuff

    @Override
    public void onUserCancel() {
        toast("You cancelled payment, please try again.");
    }
    @Override
    public void onPaymentCompleted(IswPaymentResult result) {
        if (result.isSuccessful)
            toast("your payment was successful, using: " + result.channel.name());
        else toast("unable to complete payment at the moment, try again later");
    }
    private void toast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }
}

And that is it you can start processing payment in your android app.


React Native

This library aids in processing payment through the following channels

  • Card
  • Verve Wallet
  • QR Code
  • USSD

Getting started

There are three steps you would have to complete to set up the SDK and perform transaction - Install the SDK as a dependency - Configure the SDK with Merchant Information - Initiate payment with customer details

Installation

$ npm install react-native-isw-mobile-sdk --save

Mostly automatic installation

$ react-native link react-native-isw-mobile-sdk

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-isw-mobile-sdk and add IswMobileSdk.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libIswMobileSdk.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
    • Add import com.interswitchng.IswMobileSdkPackage; to the imports at the top of the file
    • Add new IswMobileSdkPackage() to the list returned by the getPackages() method
  2. Append the following lines to android/settings.gradle: include ':react-native-isw-mobile-sdk' project(':react-native-isw-mobile-sdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-isw-mobile-sdk/android')
  3. Insert the following lines inside the dependencies block in android/app/build.gradle: compile project(':react-native-isw-mobile-sdk')

Configuration

You would also need to configure the project with your merchant credentials.

JavaScript

import IswMobileSdk, { IswPaymentInfo, Environment, IswSdkConfig } from 'react-native-isw-mobile-sdk';
// get your credentials
const merchantId = "your-merchant-id",
 merchantCode = "your-merchant-code",
 merchantSecret = "your-merchant-seceret",
 currencyCode = "currency-code"; // e.g. 566
// create configuration for payment
// using the credentials
const config = new IswSdkConfig(
    merchantId, 
    merchantSecret,
    merchantCode,
    currencyCode
)
/**
 *  callback function for initialized sdk
 *  @param isSuccessful boolean flag indicating the result of initializing sdk
 */
const onSdkInitialized = (isSuccessful) => {
    // handle result
}
// initialize the sdk at the start of application
// you can point to a specific environment -> TEST || PRODUCTION
const env = Environment.TEST;
IswMobileSdk.initialize(config, env, onSdkInitialized);

Once the SDK has been initialized, you can then perform transactions.

Performing Transactions

You can perform a transaction, once the SDK is configured, by providing the payment info and payment callbacks, like so:

JavaScript


let triggerPayment = (amount) => {
    // amount expressed in lowest
    // denomination (e.g. kobo): "N500.00" -> 50000
    amount = amount * 100


    const customerId = "<customer-id>",
        customerName = "<customer-name>",
        customerEmail = "<[email protected]>",
        customerMobile = "<customer-phone>",
        // generate a unique random
        // reference for each transaction
        reference = "<your-unique-ref>";;


    // create payment information object
    const paymentInfo = new IswPaymentInfo(
        customerId,
        customerName,
        customerEmail,
        customerMobile,
        reference,
        amount,
    )

    // trigger payment with the payment information
    IswMobileSdk.pay(paymentInfo, userDidComplete, userDidCancel);
}

Handling Result

To handle result all you need to do is process the result in the callback methods: whenever the user cancels, userDidCancel is called, and when the transaction is complete, userDidComplete is called with the result: an object like below is passed to the callback function.

HANDLING RESULT
Field Type Meaning
responseCode String txn response code
responseDescription String txn response code description
isSuccessful boolean flag indicates if txn is successful
transactionReference String reference for txn
amount Number txn amount
channel String channel used to make payment: one of CARD, WALLET, QR, USSD

JavaScript


let userDidComplete = (result) => {
    // process result
}

let userDidCancel = () => {
    // handle cancellation
}

And that is it you can start processing payment in your react-native app.


Flutter SDK

This library aids in processing payment through the following channels

  • Card
  • Verve Wallet
  • QR Code
  • USSD

Getting started

There are three steps you would have to complete to set up the SDK and perform transaction

  • Install the SDK as a dependency
  • Configure the SDK with Merchant Information
  • Initiate payment with customer details

Installation

To install the sdk add the following to your dependencies map in pubspec.yaml

Ruby


dependencies:
  #.... others

  # add the dependency for sdk
  isw_mobile_sdk: '<latest-version>'


Configuration

You would also need to configure the project with your merchant credentials.

Dart

import 'dart:async';
import 'package:isw_mobile_sdk/isw_mobile_sdk.dart';


class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    initSdk();
  }

    // messages to SDK are asynchronous, so we initialize in an async method.
  Future<void> initSdk() async {

    // messages may fail, so we use a try/catch PlatformException.
    try {
        String  merchantId = "your-merchant-id",
        merchantCode = "your-merchant-code",
        merchantSecret = "your-merchant-secret",
        currencyCode = "currency-code"; // e.g  566 for NGN

        var config = new IswSdkConfig (
            merchantId, 
            merchantKey, 
            merchantCode, 
            currencyCode
        );

        // initialize the sdk
        await IswMobileSdk.initialize(config);
        // intialize with environment, default is Environment.TEST
        // IswMobileSdk.initialize(config, Environment.SANDBOX);

    } on PlatformException {}
  }
}

Once the SDK has been initialized, you can then perform transactions.

Performing Transactions

You can perform a transaction, once the SDK is configured, by providing the payment info and payment callbacks, like so:

Dart


  Future<void> pay(int amount) async {

    var customerId = "<customer-id>",
        customerName = "<customer-name>",
        customerEmail = "<[email protected]>",
        customerMobile = "<customer-phone>",
        // generate a unique random
        // reference for each transaction
        reference = "<your-unique-ref>";
    // initialize amount
    // amount expressed in lowest
    // denomination (e.g. kobo): "N500.00" -> 50000
    int amountInKobo = amount * 100
    // create payment info
    var iswPaymentInfo = new IswPaymentInfo(
        customerId, 
        customerName,
        customerEmail, 
        customerMobile, 
        reference, 
        amountInKobo
    );
    // trigger payment
    var result = await IswMobileSdk.pay(iswPaymentInfo);
    // process result
    handleResult(result)
  }

Handling Result

To handle result all you need to do is process the result in the callback methods: whenever the user cancels, the value would be null and hasValue would be false. When the transaction is complete, hasValue would be true and value would have an instance of IswPaymentResult: an object with the below fields.

HANDLING RESULT
Field Type Meaning
responseCode String txn response code
responseDescription String txn response code description
isSuccessful boolean flag indicates if txn is successful
transactionReference String reference for txn
amount Number txn amount
channel String channel used to make payment: one of CARD, WALLET, QR, USSD

Dart


void handleResult(Optional<IswPaymentResult> result) {

    if (result.hasValue) {
        // process result
        showPaymentSuccess(result.value);
    } else { 
        showPaymentError()
    }   
}

And that is it, you can start processing payment in your flutter app.