react-nomba-checkout-sdk 1.0.1 β 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -19
- package/dist/apis/handleNombaApiCall.d.ts +3 -0
- package/dist/apis/handleVendorApiCall.d.ts +3 -0
- package/dist/apis/useGenerateToken.d.ts +8 -0
- package/dist/apis/useNombaCheckout.d.ts +30 -0
- package/dist/assets/CloseIcon.d.ts +1 -1
- package/dist/components/NombaCheckoutModal.d.ts +14 -9
- package/dist/eventBus.d.ts +8 -0
- package/dist/helpers/InitializeNombaCheckout.d.ts +1 -0
- package/dist/index.d.ts +12 -11
- package/dist/index.esm.js +273 -151
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +275 -152
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/apis/handleNombaApiCall.ts +26 -0
- package/src/apis/handleVendorApiCall.ts +26 -0
- package/src/apis/useCardCheckout.ts +2 -2
- package/src/apis/useCardCheckoutOtp.ts +2 -2
- package/src/apis/useFetchUssdBanks.ts +2 -2
- package/src/apis/useGenerateQrCode.ts +2 -2
- package/src/apis/useGenerateToken.ts +30 -0
- package/src/apis/useGetOrder.ts +2 -2
- package/src/apis/useGetUssdCode.ts +2 -2
- package/src/apis/useNombaCheckout.ts +64 -0
- package/src/apis/useResendOtp.ts +2 -2
- package/src/apis/useVerifyOrderStatus.ts +2 -2
- package/src/assets/CloseIcon.tsx +11 -11
- package/src/components/NombaCheckoutModal.tsx +110 -63
- package/src/eventBus.ts +25 -0
- package/src/helpers/InitializeNombaCheckout.tsx +26 -0
- package/src/index.tsx +14 -13
- package/dist/apis/handleApiCall.d.ts +0 -3
- package/dist/components/NombaCheckoutButton.d.ts +0 -17
- package/src/apis/handleApiCall.ts +0 -20
- package/src/components/NombaCheckoutButton.tsx +0 -67
package/README.md
CHANGED
|
@@ -1,35 +1,115 @@
|
|
|
1
|
-
# React Nomba Checkout SDK
|
|
1
|
+
# π React Nomba Checkout SDK
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The **`react-nomba-checkout-sdk`** is a lightweight React SDK designed to simplify payment processing and checkout integration using [Nomba's](https://nomba.com/) secure and reliable infrastructure.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Built with β€οΈ by **Israel Itua**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## π¦ Installation
|
|
10
|
+
|
|
11
|
+
You can install the SDK using npm or yarn:
|
|
8
12
|
|
|
9
13
|
```bash
|
|
10
14
|
npm install react-nomba-checkout-sdk
|
|
11
15
|
# or
|
|
12
16
|
yarn add react-nomba-checkout-sdk
|
|
17
|
+
```
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
---
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
## β‘ Quick Start
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
Hereβs how to integrate the SDK into your React project:
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
```jsx
|
|
26
|
+
import { useState } from 'react';
|
|
27
|
+
import {
|
|
28
|
+
useNombaCheckout,
|
|
29
|
+
InitializeNombaCheckout,
|
|
30
|
+
} from 'react-nomba-checkout-sdk';
|
|
31
|
+
import './App.css';
|
|
21
32
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
}
|
|
33
|
+
// Initialize Nomba Checkout on app load
|
|
34
|
+
InitializeNombaCheckout();
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
38
|
+
|
|
39
|
+
const handleCheckout = async () => {
|
|
40
|
+
setIsLoading(true);
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
const res = await useNombaCheckout({
|
|
43
|
+
accountId: 'your-account-id',
|
|
44
|
+
clientId: 'your-client-id',
|
|
45
|
+
order: {
|
|
46
|
+
callbackUrl: 'sample-url',
|
|
47
|
+
customerEmail: 'sample-email@gmail.com',
|
|
48
|
+
amount: '10.00',
|
|
49
|
+
currency: 'NGN',
|
|
50
|
+
splitRequest: {
|
|
51
|
+
splitType: 'PERCENTAGE',
|
|
52
|
+
splitList: [
|
|
53
|
+
{
|
|
54
|
+
accountId: 'your-account-id',
|
|
55
|
+
value: '65.45',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
tokenizeCard: 'true',
|
|
61
|
+
onCreateOrder: (orderReference) => {
|
|
62
|
+
console.log('Function called after the order is created');
|
|
63
|
+
console.log({ orderReference });
|
|
64
|
+
setIsLoading(false);
|
|
65
|
+
},
|
|
66
|
+
onFailure: (err) => {
|
|
67
|
+
console.log('Function called if error occurs while creating order.');
|
|
68
|
+
console.log(err);
|
|
69
|
+
setIsLoading(false);
|
|
70
|
+
},
|
|
71
|
+
onClose: () => {
|
|
72
|
+
console.log('Function called when modal is closed.');
|
|
73
|
+
setIsLoading(false);
|
|
74
|
+
},
|
|
75
|
+
onPaymentSuccess: (successResponse) => {
|
|
76
|
+
console.log('Function called on payment success.');
|
|
77
|
+
console.log({ successResponse });
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<>
|
|
84
|
+
<h1>Pay with Nomba</h1>
|
|
85
|
+
<button onClick={handleCheckout}>
|
|
86
|
+
{isLoading ? 'Please wait...' : 'Pay with Nomba Checkout'}
|
|
87
|
+
</button>
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
34
91
|
|
|
92
|
+
export default App;
|
|
35
93
|
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## π API Reference
|
|
98
|
+
|
|
99
|
+
### `InitializeNombaCheckout()`
|
|
100
|
+
|
|
101
|
+
Initializes the SDK. Call once when your app loads.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### `useNombaCheckout(options)`
|
|
106
|
+
|
|
107
|
+
Launches the Nomba checkout modal. |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## π€ Author
|
|
112
|
+
|
|
113
|
+
**Israel Itua**
|
|
114
|
+
Frontend Engineer
|
|
115
|
+
[GitHub](https://github.com/the-israelItua/) β’
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface CheckoutPayload {
|
|
2
|
+
order: {
|
|
3
|
+
orderReference: string;
|
|
4
|
+
customerId: string;
|
|
5
|
+
callbackUrl: string;
|
|
6
|
+
customerEmail: string;
|
|
7
|
+
amount: string;
|
|
8
|
+
currency: string;
|
|
9
|
+
accountId: string;
|
|
10
|
+
splitRequest?: {
|
|
11
|
+
splitType: string;
|
|
12
|
+
splitList: [
|
|
13
|
+
{
|
|
14
|
+
accountId: string;
|
|
15
|
+
value: number;
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
tokenizeCard: boolean;
|
|
21
|
+
clientId: string;
|
|
22
|
+
accountId: string;
|
|
23
|
+
environment?: string;
|
|
24
|
+
onCreateOrder: (orderReference: string) => void;
|
|
25
|
+
onFailure: (e: any) => void;
|
|
26
|
+
onClose: () => {};
|
|
27
|
+
onPaymentSuccess: (order: any) => {};
|
|
28
|
+
}
|
|
29
|
+
export declare const useNombaCheckout: (payload: CheckoutPayload) => Promise<any>;
|
|
30
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export declare const CloseIcon: () => React.JSX.Element;
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import React, { Component } from
|
|
2
|
-
import
|
|
3
|
-
interface NombaCheckoutModalProps {
|
|
4
|
-
orderId: string;
|
|
5
|
-
onClose: () => void;
|
|
6
|
-
}
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import '../styles.css';
|
|
7
3
|
interface NombaCheckoutModalState {
|
|
4
|
+
orderId: string;
|
|
8
5
|
isLoading: boolean;
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
onPaymentSuccess: (e: any) => void;
|
|
9
|
+
environment: string;
|
|
9
10
|
}
|
|
10
|
-
declare class NombaCheckoutModal extends Component<
|
|
11
|
-
constructor(props:
|
|
11
|
+
declare class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
|
|
12
|
+
constructor(props: {});
|
|
13
|
+
handleOpen: (orderId: string) => void;
|
|
12
14
|
handleClose: () => void;
|
|
13
15
|
handleIframeLoad: () => void;
|
|
14
|
-
|
|
16
|
+
handleMessage: (event: MessageEvent) => void;
|
|
17
|
+
componentDidMount(): void;
|
|
18
|
+
componentWillUnmount(): void;
|
|
19
|
+
render(): React.JSX.Element | null;
|
|
15
20
|
}
|
|
16
21
|
export { NombaCheckoutModal };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare class EventBus {
|
|
2
|
+
private events;
|
|
3
|
+
on(event: string, listener: (data: any) => void): void;
|
|
4
|
+
emit(event: string, data: any): void;
|
|
5
|
+
off(event: string, listener: (data: any) => void): void;
|
|
6
|
+
}
|
|
7
|
+
declare const eventBus: EventBus;
|
|
8
|
+
export default eventBus;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const InitializeNombaCheckout: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
1
|
+
import { useGetOrder } from './apis/useGetOrder';
|
|
2
|
+
import { useCardCheckout } from './apis/useCardCheckout';
|
|
3
|
+
import { useCardCheckoutOtp } from './apis/useCardCheckoutOtp';
|
|
4
|
+
import { useGenerateQrCode } from './apis/useGenerateQrCode';
|
|
5
|
+
import { useVerifyOrderStatus } from './apis/useVerifyOrderStatus';
|
|
6
|
+
import { useResendOtp } from './apis/useResendOtp';
|
|
7
|
+
import { useFetchUssdBanks } from './apis/useFetchUssdBanks';
|
|
8
|
+
import { useGetUssdCode } from './apis/useGetUssdCode';
|
|
9
|
+
import { useGenerateToken } from './apis/useGenerateToken';
|
|
10
|
+
import { useNombaCheckout } from './apis/useNombaCheckout';
|
|
11
|
+
import { InitializeNombaCheckout } from './helpers/InitializeNombaCheckout';
|
|
12
|
+
export { useGetOrder, useCardCheckout, useCardCheckoutOtp, useResendOtp, useGenerateQrCode, useVerifyOrderStatus, useFetchUssdBanks, useGetUssdCode, useGenerateToken, useNombaCheckout, InitializeNombaCheckout, };
|