Skip to content

Repository files navigation

Interswitch Payment Gateway SDK for React Native

Interswitch

The Interswitch Payment Gateway (IPG) SDK for React Native provides a seamless way to integrate secure payment processing into your mobile applications. Built on top of the robust Interswitch Web Checkout, this SDK simplifies the integration process using a high-performance WebView component.

Official Documentation


Features

  • Official Integration: Follows Interswitch Inline Checkout standards.
  • Cross-Platform: Full support for both Expo and React Native CLI.
  • Type Safety: Built with TypeScript for a superior developer experience and fewer runtime errors.
  • Customizable: Control the payment flow with refs, handle custom response data, and style the UI to match your app.

Installation

Install the package via your preferred package manager:

NPM

npm install @interswitchapi/ipg-react-native

Yarn

yarn add @interswitchapi/ipg-react-native

Expo

npx expo install @interswitchapi/ipg-react-native

Important

This package requires react-native-webview as a peer dependency. Ensure it is installed in your project.


Quick Start

The following example demonstrates a basic implementation where the payment modal starts automatically.

importReact,{useState}from'react';import{View,StyleSheet,Text}from'react-native';import{IswPaymentWebView}from'@interswitchapi/ipg-react-native';exportdefaultfunctionApp(){const[txnRef]=useState(`txn_${Date.now()}`);constconfig={merchantCode: 'MX6072',payItemId: '9405967',amount: 100000,// Amount in Kobo (e.g., 1000.00 NGN)mode: 'TEST'asconst,};return(<Viewstyle={styles.container}><Textstyle={styles.title}>Secure Payment</Text><IswPaymentWebViewamount={config.amount}autoStart={true}trnxRef={txnRef}merchantCode={config.merchantCode}payItem={{id: config.payItemId}}mode={config.mode}onCompleted={(response)=>{console.log('Payment Response:',response);}}style={styles.webView}/></View>);}conststyles=StyleSheet.create({container: {flex: 1,paddingTop: 60,paddingHorizontal: 20},title: {fontSize: 22,fontWeight: 'bold',textAlign: 'center',marginBottom: 20,},webView: {flex: 1},});

Advanced Usage

Manual Trigger with Refs

Use the IswWebViewRefMethods to programmatically start() or end() the payment process.

importReact,{useRef}from'react';import{TouchableOpacity,Text}from'react-native';import{IswPaymentWebView,typeIswWebViewRefMethods,}from'@interswitchapi/ipg-react-native';exportdefaultfunctionPaymentScreen(){constpaymentRef=useRef<IswWebViewRefMethods>(null);return(<><TouchableOpacityonPress={()=>paymentRef.current?.start()}><Text>Pay Now</Text></TouchableOpacity><IswPaymentWebViewref={paymentRef}autoStart={false}// ... other propsonCompleted={(res)=>console.log(res)}/></>);}

Handling Custom Response Data

You can pass a generic type to IswPaymentWebView to handle custom data fields returned in the payment callback.

interfaceMyCustomData{orderId: string;userId: string;}// ... inside your component<IswPaymentWebView<MyCustomData>onCompleted={(response)=>{console.log('Order ID:',response.orderId);}}// .../>;

API Reference: Props

PropTypeRequiredDefaultDescription
trnxRefstringYes-Unique transaction reference for the session.
merchantCodestringYes-Your Interswitch Merchant Code.
amountnumber | stringYes-Transaction amount in Kobo (e.g., 100000 = 1000.00).
payItemIswPayItemYes-Object containing id (required) and name (optional).
mode'TEST' | 'LIVE'Yes-Environment for the transaction.
onCompletedFunctionYes-Callback triggered upon completion, cancellation, or error.
currencynumber | stringNo566ISO currency code (Default: 566 for NGN).
customerIswCustomerNo-Optional customer details (id, name, email, phoneNumber).
autoStartbooleanNofalseAutomatically launch the payment modal on mount.
showBackdropbooleanNofalseDisplay a loading backdrop while the gateway initializes.
indicatorColorColorValueNo-Color for the loading activity indicator.
loadingTextstringNo-Custom text displayed during initialization.
styleViewStyleNo-custom styles for the WebView component.
backButtonReactNodeNo-Custom component for the back/close button.
tokeniseCard'true' | 'false'No-Flag to request card tokenization for future use.
splitAccountsSplitAccounts[]No-Array of accounts for settlement splitting.

Contributing

We welcome contributions! Please see the Contributing Guide for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with create-react-native-library

About

Interswitch Payment Gateway SDK for React Native

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages