0.1.1 • Published 5 years ago

mnfyrnsdk v0.1.1

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

React Native Wrapper for Monnify Mobile SDKs

for Android & iOS

Index

  1. Description
  2. Installation
  3. Usage

1. Description

This module provides a wrapper to add Monnify Payments to your React Native application.

2. Installation

npm i mnfyrnsdk --save

OR

yarn add mnfyrnsdk

Configuration

Manual Config (Android)

  • The following steps are optional, should be taken if you have not run react-native link mnfyrnsdk already.
  • Add the following in your android/settings.gradle file:
include ':mnfyrnsdk'
project(':mnfyrnsdk').projectDir = new File(rootProject.projectDir, '../node_modules/mnfyrnsdk/android')
  • Add the following in your android/app/build.grade file:
defaultConfig {
    ...
    multiDexEnabled true
}

dependencies {
    ...
    implementation 'com.android.support:multidex:1.0.3'
    implementation project(':mnfyrnsdk')
}
  • Add the following in your ...MainApplication.java file:
import com.mnfyrnsdk.rnmonnifymodule.RNMonnifyPackage;

@Override
protected List<ReactPackage> getPackages() {
    @SuppressWarnings("UnnecessaryLocalVariable")
    List<ReactPackage> packages = new PackageList(this).getPackages();
    packages.add(new RNMonnifyPackage());
    return packages;
}

3. Usage

Initialize Library

Somewhere high up in your project and way before calling any other method exposed by this library, your index file or equivalent is a good spot, ensure you initialize the library with your api key, contractCode and applicationMode as follows:

import RNMonnify from 'mnfyrnsdk';

MonnifySdk.init({
  apiKey: 'MK_TEST_VR7J3UAACH',
  contractCode: '4876165459',
  applicationMode: 'TEST'
});

Initialize Payment (iOS & Android)

Using the mnfyrnsdk module, you can start and complete a transaction with the Monnify Android and iOS SDKs. With this option, you pass both your payment properties to the SDK - with this worklow, you initiate and complete a transaction on your mobile app.

RNMonnify.initializePayment(paymentParams);

paymentParams is a Javascript Object representing the parameters of the charge to be initiated and RNMonnify.initializePayment() returns a Javascript Promise like:

import RNMonnify from 'mnfyrnsdk';

chargeCard() {

	RNMonnify.initializePayment({
        amount: 1200.5,
        customerName: 'Tobi Adeyemi',
        customerEmail: 'tobiadeyemi@gmail.com',
        paymentReference: '222',
        paymentDescription: 'Foodies',
        currencyCode: 'NGN',
        incomeSplitConfig: [],
    })
	.then(response => {
	  console.log(response); // card charged successfully, get reference here
	})
	.catch(error => {
	  console.log(error); // error is a javascript Error object
	  console.log(error.message);
	  console.log(error.code);
	})

}

Request Signature

ArgumentTypeDescription
amountfloatthe transaction amount
customerEmailstringemail of the user to be charged
currencyCodestringsets the currency for the transaction e.g. NGN
paymentDescriptionstringdescription of payment
customerNamestringsets the name of customer
paymentReferencestringsets the transaction reference which must be unique per transaction

Response Object

An object of the form is returned from a successful charge

{
    paymentDate: '',
    amountPayable: 1200,
    amountPaid: 0,
    paymentMethod: 'CARD',
    transactionStatus: 'PENDING',
    transactionReference: 'trx_1k2o600w';
}
0.1.1

5 years ago

0.1.0

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago