1.0.4 • Published 10 months ago

@adsesugh/monnify-react-native v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Monnify SDK for React Native CLI and Expo

@adsesugh/monnify-react-native is a React Native package that simplifies the integration of the Monnify payment gateway into React Native applications. This package is compatible with both React Native CLI and Expo projects.

Features

  • Easy integration of the Monnify payment gateway.
  • Supports payment in Nigerian Naira (NGN).
  • Handles payment completion and closure callbacks.
  • Compatible with both React Native CLI and Expo.

Installation

For React Native CLI:

  1. Install the package via npm or yarn:

    npm install @adsesugh/monnify-react-native
    # or
    yarn add @adsesugh/monnify-react-native
  2. Install react-native-webview if you haven't already:

     npm install react-native-webview
     # or
     yarn add react-native-webview

For Expo:

  1. Install the package via npm or yarn:

    npx expo install @adsesugh/monnify-react-native
  2. Install react-native-webview using Expo:

    npx expo install react-native-webview

Basic Example

import React, { useState } from 'react';
import { StyleSheet, View, Text, Modal, Pressable } from 'react-native';
import Monnify from '@adsesugh/monnify-react-native'

export default function App() {
  const [modalVisible, setModalVisible] = useState(false);

  const paymentParameters = {
    amount: 5000,
    currency: 'NGN',
    reference: `${new String(new Date().getTime())}`,
    customerFullName: 'John Doe',
    customerEmail: 'admin@gmail.com',
    customerMobileNumber: '08012345689',
    apiKey: 'MK_PROD_P2HCHYTYA4R',
    contractCode: "92822828827",
    paymentDescription: 'Payment for goods',
    mode: 'TEST'
  };

  const onSuccess = (response: any) => {
    console.log('Payment Successful:', response);
    // Handle success scenario
  };
  
  const onError = (response: any) => {
    console.log('Payment Failed:', response);
    // Handle error scenario
  };
  
  const onDismiss = () => {
    setModalVisible(!modalVisible)
  };
 
  return (
        <View style={styles.container}>
            <Monnify
                  paymentParams={paymentParameters}
                  onSuccess={onSuccess}
                  onError={onError}
                  onDismiss={onDismiss}
                  visible={modalVisible}
            />
            <Pressable
                style={[styles.button, styles.buttonOpen]}
                onPress={() => setModalVisible(true)}>
                <Text style={styles.textStyle}>Show Modal</Text>
            </Pressable>
        </View>
  );
}

const styles = StyleSheet.create({
  container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
    },
    button: {
        borderRadius: 20,
        padding: 10,
        elevation: 2,
    },
    buttonOpen: {
        backgroundColor: '#F194FF',
    },
    textStyle: {
        color: 'white',
        fontWeight: 'bold',
        textAlign: 'center',
    },
});

Props

PropTypeRequiredDescription
amountnumberYesThe amount to be paid.
currencystringYesThe currency in which payment will be made (e.g., "NGN").
referencestringYesA unique reference for the payment transaction.
customerFullNamestringYesThe full name of the customer making the payment.
customerEmailstringYesThe email address of the customer making the payment.
apiKeystringYesThe API key provided by Monnify.
contractCodestringYesThe contract code provided by Monnify.
paymentDescriptionstringYesA description of the payment.
metadataRecord<string, any>NoAdditional metadata to be sent with the payment.
incomeSplitConfigArray<Object>NoConfiguration for splitting the payment into sub-accounts.
onSuccess(response: any) => voidNoCallback function that is invoked when the transaction is completed successfully.
onError(data: any) => voidNoCallback function that is invoked when the payment modal is closed without completing the transaction.
onDismiss() => voidNoCallback function that is invoked when the payment modal is closed.
modestringYesThis could be 'TEST' for development and 'LIVE' for production. E.g mode="TEST"

Example with Income Split Configuration

import Monnify from '@adsesugh/monnify-react-native';
import React, { useState } from 'react';
import { StyleSheet, View, Text, Modal, Pressable } from 'react-native';


export default function App() {
 const [modalVisible, setModalVisible] = useState(false);

 const paymentParameters = {
   amount: 5000,
   currency: 'NGN',
   reference: `${new String(new Date().getTime())}`,
   customerFullName: 'John Doe',
   customerEmail: 'admin@gmail.com',
   customerMobileNumber: '08012345678',
   apiKey: 'MK_TEST_P2HGJFA4',
   contractCode: "3520752572",
   paymentDescription: 'Payment for goods',
   mode: 'TEST',
   metadata: {name: "Damilare", age: 45},
   incomeSplitConfig: [
           {
           subAccountCode: "MFY_SUB_342113621921",
           feePercentage: 50,
           splitAmount: 1900,
           feeBearer: true,
           },
           {
           subAccountCode: "MFY_SUB_342113621922",
           feePercentage: 50,
           splitAmount: 2100,
           feeBearer: true,
           },
       ]
   };

 const onSuccess = (response: any) => {
   console.log('Payment Successful:', response);
   // Handle success scenario
 };
 
 const onError = (response: any) => {
   console.log('Payment Failed:', response);
   // Handle error scenario
 };
 
 const onDismiss = () => {
   setModalVisible(!modalVisible)
 };

 return (
       <View style={styles.container}>
           <Monnify
               paymentParams={paymentParameters}
               onSuccess={onSuccess}
               onError={onError}
               onDismiss={onDismiss}
               visible={modelVisible}
           />
           <Pressable
               style={[styles.button, styles.buttonOpen]}
               onPress={() => setModalVisible(true)}>
               <Text style={styles.textStyle}>Pay Now</Text>
           </Pressable>
       </View>
 );
}

const styles = StyleSheet.create({
 container: {
       flex: 1,
       justifyContent: 'center',
       alignItems: 'center',
   },
   button: {
       borderRadius: 20,
       padding: 10,
       elevation: 2,
   },
   buttonOpen: {
       backgroundColor: '#F194FF',
   },
   textStyle: {
       color: 'white',
       fontWeight: 'bold',
       textAlign: 'center',
   },
});
1.0.2

11 months ago

1.0.1

11 months ago

1.0.7-beta

11 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.8-beta

11 months ago

1.0.6-beta

11 months ago

1.0.5-beta

11 months ago

1.0.4-beta

11 months ago

1.0.3-beta

11 months ago

1.0.2-beta

11 months ago

1.0.1-beta

11 months ago

1.0.0-beta

11 months ago