|
1 | 1 | # react-native-interswitch-pay |
2 | 2 |
|
3 | | -interswtich payment gateway sdk for react native |
| 3 | +<img width="459" alt="Interswitch" src="https://github.com/user-attachments/assets/1450262e-2ae9-4ec3-ac74-31fe50655b49"> |
| 4 | + |
| 5 | +The Interswitch React Native SDK simplifies the integration of the Interswitch Payment Gateway (IPG) into your React Native app using a WebView component. |
| 6 | + |
| 7 | + |
| 8 | +[demo](https://www.loom.com/share/a368f65a0b2641b69e4fce1d74fcbbd8) |
| 9 | + |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- Flexible implementation following the [official documentation](https://docs.interswitchgroup.com/docs/web-checkout). |
| 14 | +- Integrated with the [Interswitch Web Redirect](https://docs.interswitchgroup.com/docs/web-checkout#option-2---web-redirect). |
| 15 | +- Built with TypeScript for type safety and an enhanced developer experience. |
| 16 | +- Supports both Expo and React Native CLI. |
| 17 | + |
4 | 18 |
|
5 | 19 | ## Installation |
6 | 20 |
|
| 21 | +##### Npm |
| 22 | + |
7 | 23 | ```sh |
8 | 24 | npm install react-native-interswitch-pay |
9 | 25 | ``` |
10 | 26 |
|
11 | | -## Usage |
| 27 | +##### Yarn |
| 28 | + |
| 29 | +```sh |
| 30 | +yarn react-native-interswitch-pay |
| 31 | +``` |
| 32 | + |
| 33 | +##### Expo |
| 34 | + |
| 35 | +```sh |
| 36 | +expo install react-native-interswitch-pay |
| 37 | +``` |
| 38 | + |
| 39 | + |
| 40 | +> **_Important_**: This package depends on `react-native-webview` as a peer dependency and requires it for proper functionality. |
12 | 41 |
|
| 42 | +## Quick Examples. |
| 43 | + |
| 44 | + |
| 45 | +#### Auto start Payment |
13 | 46 |
|
14 | 47 | ```js |
15 | | -import { multiply } from 'react-native-interswitch-pay'; |
16 | 48 |
|
17 | | -// ... |
| 49 | +import { View } from 'react-native'; |
| 50 | +import IswPaymentWebView from 'react-native-interswitch-pay'; |
| 51 | + |
| 52 | +export const PaymentScreen = () => { |
| 53 | + |
| 54 | + const handleCallback = () => { |
| 55 | + console.log('Handle callback here') |
| 56 | + }; |
| 57 | + |
| 58 | + return ( |
| 59 | + <View style={styles.container}> |
| 60 | + <IswPaymentWebView |
| 61 | + amount={amount} |
| 62 | + currency={566} |
| 63 | + mode={'TEST'} |
| 64 | + autoStart={true} |
| 65 | + payItem={{id: '9405967'}} |
| 66 | + merchantCode={'MX6072'} |
| 67 | + onCompleted={handleCallback} |
| 68 | + transactionReference={'12344grtr'} |
| 69 | + redirectUrl="https://example.com/payment-response" |
| 70 | + checkoutUrl={'https://newwebpay.qa.interswitchng.com/collections/w/pay'} |
| 71 | + /> |
| 72 | + </View> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +const styles = StyleSheet.create({ |
| 77 | + container: { |
| 78 | + flex: 1, |
| 79 | + backgroundColor: '#fff', |
| 80 | + paddingTop: '10%', |
| 81 | + }, |
| 82 | +}); |
| 83 | + |
18 | 84 |
|
19 | | -const result = multiply(3, 7); |
20 | 85 | ``` |
21 | 86 |
|
| 87 | +#### Use with Ref to trigger using a button |
| 88 | + |
| 89 | +```js |
| 90 | +import * as React from 'react'; |
| 91 | +import { Button, StyleSheet, View } from 'react-native'; |
| 92 | +import IswPaymentWebView from 'react-native-interswitch-pay'; |
| 93 | + |
| 94 | + |
| 95 | +// Note: For typescript support |
| 96 | +type TIswPaymentWebView = React.ComponentRef<typeof IswPaymentWebView>; |
| 97 | + |
| 98 | +export default function App() { |
| 99 | + const IswWebViewRef = React.useRef<TIswPaymentWebView>(null); |
| 100 | + |
| 101 | + return ( |
| 102 | + <View style={styles.container}> |
| 103 | + <IswPaymentWebView |
| 104 | + amount={amount} |
| 105 | + currency={566} |
| 106 | + mode={'TEST'} |
| 107 | + autoStart={false} |
| 108 | + ref={IswWebViewRef} |
| 109 | + payItem={{id: '9405967'}} |
| 110 | + merchantCode={'MX6072'} |
| 111 | + onCompleted={handleCallback} |
| 112 | + transactionReference={'12344grtr'} |
| 113 | + redirectUrl="https://example.com/payment-response" |
| 114 | + checkoutUrl={'https://newwebpay.qa.interswitchng.com/collections/w/pay'} |
| 115 | + /> |
| 116 | + <Button |
| 117 | + onPress={() => { |
| 118 | + IswWebViewRef.current?.start(); |
| 119 | + }} |
| 120 | + title={'Pay Now'} |
| 121 | + /> |
| 122 | + </View> |
| 123 | + ); |
| 124 | +} |
| 125 | + |
| 126 | +const styles = StyleSheet.create({ |
| 127 | + container: { |
| 128 | + flex: 1, |
| 129 | + backgroundColor: '#fff', |
| 130 | + paddingTop: '10%', |
| 131 | + }, |
| 132 | + box: { |
| 133 | + width: 60, |
| 134 | + height: 60, |
| 135 | + marginVertical: 20, |
| 136 | + }, |
| 137 | +}); |
| 138 | +``` |
| 139 | +
|
| 140 | +### Props |
| 141 | +
|
| 142 | +| Props Name | Description | Required | Value | Data type | |
| 143 | +| -------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -------- | --------------------------------------- | -------- | |
| 144 | +| transactionReference | transaction reference. | Yes | | string | |
| 145 | +| merchantCode | ISW merchant code | Yes | | string | |
| 146 | +| amount | Cost of the item you want your customer to pay | Yes | | number | |
| 147 | +| customer | Customer information e.g email, first name, last name | No | | object | |
| 148 | +| payItem | Payment Item e.g id and name | Yes | | object[] | |
| 149 | +| autoStart | To auto initialize transaction | No | false | boolean | |
| 150 | +| indicatorColor | activity indicator color | No | red | string | |
| 151 | +| redirectUrl | Merchant's website redirect url. | Yes | | string | |
| 152 | +| currency | ISO currency code e.g 566 | Yes | e.g 566 | number | |
| 153 | +| mode | Environment e.g LIVE, TEST | Yes | TEST | string | |
| 154 | +| onCompleted | Callback that triggers when webview close or cancels | Yes | | Function | |
| 155 | +| splitAccounts | ISW Split accounts for settlements | No | `SplitAccounts[]` | Array | |
| 156 | +| onWebMessage | Callback to handle web view message event | no | | Function | |
22 | 157 |
|
23 | 158 | ## Contributing |
24 | 159 |
|
|
0 commit comments