react-nomba-checkout-sdk 1.0.3 β 2.0.1
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 +57 -27
- package/dist/apis/useNombaCheckout.d.ts +2 -2
- package/dist/assets/CloseIcon.d.ts +1 -1
- package/dist/components/NombaCheckoutModal.d.ts +2 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.esm.js +37 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +37 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/apis/useNombaCheckout.ts +6 -12
- package/src/assets/CloseIcon.tsx +11 -11
- package/src/components/NombaCheckoutModal.tsx +22 -7
- package/src/index.tsx +12 -12
package/README.md
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
```bash
|
|
25
|
+
```jsx
|
|
23
26
|
import { useState } from 'react';
|
|
24
27
|
import {
|
|
25
28
|
useNombaCheckout,
|
|
@@ -27,7 +30,7 @@ import {
|
|
|
27
30
|
} from 'react-nomba-checkout-sdk';
|
|
28
31
|
import './App.css';
|
|
29
32
|
|
|
30
|
-
//
|
|
33
|
+
// Initialize Nomba Checkout on app load
|
|
31
34
|
InitializeNombaCheckout();
|
|
32
35
|
|
|
33
36
|
function App() {
|
|
@@ -37,49 +40,76 @@ function App() {
|
|
|
37
40
|
setIsLoading(true);
|
|
38
41
|
|
|
39
42
|
const res = await useNombaCheckout({
|
|
40
|
-
accountId: '
|
|
41
|
-
clientId: '
|
|
42
|
-
clientSecret: 'clientsecret',
|
|
43
|
+
accountId: 'your-account-id',
|
|
44
|
+
clientId: 'your-client-id',
|
|
43
45
|
order: {
|
|
44
|
-
callbackUrl: '
|
|
45
|
-
customerEmail: '
|
|
46
|
-
amount: '
|
|
46
|
+
callbackUrl: 'sample-url',
|
|
47
|
+
customerEmail: 'sample-email@gmail.com',
|
|
48
|
+
amount: '10.00',
|
|
47
49
|
currency: 'NGN',
|
|
48
50
|
splitRequest: {
|
|
49
51
|
splitType: 'PERCENTAGE',
|
|
50
52
|
splitList: [
|
|
51
53
|
{
|
|
52
|
-
accountId: '
|
|
54
|
+
accountId: 'your-account-id',
|
|
53
55
|
value: '65.45',
|
|
54
56
|
},
|
|
55
57
|
],
|
|
56
58
|
},
|
|
57
59
|
},
|
|
58
60
|
tokenizeCard: 'true',
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
setIsLoading(false);
|
|
61
|
+
onCreateOrder: (orderReference) => {
|
|
62
|
+
console.log('Function called after the order is created');
|
|
62
63
|
console.log({ orderReference });
|
|
64
|
+
setIsLoading(false);
|
|
63
65
|
},
|
|
64
66
|
onFailure: (err) => {
|
|
65
|
-
|
|
66
|
-
setIsLoading(false);
|
|
67
|
+
console.log('Function called if error occurs while creating order.');
|
|
67
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 });
|
|
68
78
|
},
|
|
69
79
|
});
|
|
70
80
|
};
|
|
81
|
+
|
|
71
82
|
return (
|
|
72
83
|
<>
|
|
73
|
-
<h1>
|
|
74
|
-
|
|
84
|
+
<h1>Pay with Nomba</h1>
|
|
75
85
|
<button onClick={handleCheckout}>
|
|
76
|
-
{isLoading ? 'Please wait...' : 'Pay with Nomba
|
|
86
|
+
{isLoading ? 'Please wait...' : 'Pay with Nomba Checkout'}
|
|
77
87
|
</button>
|
|
78
88
|
</>
|
|
79
89
|
);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
export default App;
|
|
93
|
+
```
|
|
83
94
|
|
|
95
|
+
---
|
|
84
96
|
|
|
85
|
-
|
|
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/) β’
|
|
@@ -19,12 +19,12 @@ interface CheckoutPayload {
|
|
|
19
19
|
};
|
|
20
20
|
tokenizeCard: boolean;
|
|
21
21
|
clientId: string;
|
|
22
|
-
clientSecret: string;
|
|
23
22
|
accountId: string;
|
|
24
23
|
environment?: string;
|
|
25
|
-
|
|
24
|
+
onCreateOrder: (orderReference: string) => void;
|
|
26
25
|
onFailure: (e: any) => void;
|
|
27
26
|
onClose: () => {};
|
|
27
|
+
onPaymentSuccess: (order: any) => {};
|
|
28
28
|
}
|
|
29
29
|
export declare const useNombaCheckout: (payload: CheckoutPayload) => Promise<any>;
|
|
30
30
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export declare const CloseIcon: () => React.JSX.Element;
|
|
@@ -5,6 +5,7 @@ interface NombaCheckoutModalState {
|
|
|
5
5
|
isLoading: boolean;
|
|
6
6
|
isOpen: boolean;
|
|
7
7
|
onClose: () => void;
|
|
8
|
+
onPaymentSuccess: (e: any) => void;
|
|
8
9
|
environment: string;
|
|
9
10
|
}
|
|
10
11
|
declare class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
|
|
@@ -12,6 +13,7 @@ declare class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState>
|
|
|
12
13
|
handleOpen: (orderId: string) => void;
|
|
13
14
|
handleClose: () => void;
|
|
14
15
|
handleIframeLoad: () => void;
|
|
16
|
+
handleMessage: (event: MessageEvent) => void;
|
|
15
17
|
componentDidMount(): void;
|
|
16
18
|
componentWillUnmount(): void;
|
|
17
19
|
render(): React.JSX.Element | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useGetOrder } from
|
|
2
|
-
import { useCardCheckout } from
|
|
3
|
-
import { useCardCheckoutOtp } from
|
|
4
|
-
import { useGenerateQrCode } from
|
|
5
|
-
import { useVerifyOrderStatus } from
|
|
6
|
-
import { useResendOtp } from
|
|
7
|
-
import { useFetchUssdBanks } from
|
|
8
|
-
import { useGetUssdCode } from
|
|
9
|
-
import { useGenerateToken } from
|
|
10
|
-
import { useNombaCheckout } from
|
|
11
|
-
import { InitializeNombaCheckout } from
|
|
12
|
-
export { useGetOrder, useCardCheckout, useCardCheckoutOtp, useResendOtp, useGenerateQrCode, useVerifyOrderStatus, useFetchUssdBanks, useGetUssdCode, useGenerateToken, useNombaCheckout, InitializeNombaCheckout };
|
|
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, };
|
package/dist/index.esm.js
CHANGED
|
@@ -4036,40 +4036,34 @@ var EventBus = /** @class */ (function () {
|
|
|
4036
4036
|
var eventBus = new EventBus();
|
|
4037
4037
|
|
|
4038
4038
|
var useNombaCheckout = function (payload) { return __awaiter(undefined, undefined, undefined, function () {
|
|
4039
|
-
var
|
|
4040
|
-
var _a, _b, _c
|
|
4041
|
-
return __generator(this, function (
|
|
4042
|
-
switch (
|
|
4039
|
+
var response, error_1;
|
|
4040
|
+
var _a, _b, _c;
|
|
4041
|
+
return __generator(this, function (_d) {
|
|
4042
|
+
switch (_d.label) {
|
|
4043
4043
|
case 0:
|
|
4044
|
-
|
|
4045
|
-
return [4 /*yield*/, useGenerateToken({
|
|
4046
|
-
clientId: payload.clientId,
|
|
4047
|
-
clientSecret: payload.clientSecret,
|
|
4048
|
-
accountId: payload.accountId,
|
|
4049
|
-
environment: payload.environment,
|
|
4050
|
-
})];
|
|
4051
|
-
case 1:
|
|
4052
|
-
tokenResponse = _f.sent();
|
|
4044
|
+
_d.trys.push([0, 2, , 3]);
|
|
4053
4045
|
return [4 /*yield*/, handleNombaApiCall('/checkout/order', 'POST', {
|
|
4054
4046
|
order: __assign(__assign({}, payload.order), { accountId: payload.accountId }),
|
|
4055
4047
|
tokenizeCard: payload.tokenizeCard,
|
|
4056
4048
|
}, {
|
|
4057
|
-
Authorization: "Bearer ".concat((_b = (_a = tokenResponse === null || tokenResponse === undefined ? undefined : tokenResponse.data) === null || _a === undefined ? undefined : _a.data) === null || _b === undefined ? undefined : _b.access_token),
|
|
4058
4049
|
accountId: payload.accountId,
|
|
4050
|
+
public_key: payload.clientId,
|
|
4051
|
+
'X-Nomba-Integration': 'react-sdk',
|
|
4059
4052
|
}, payload.environment)];
|
|
4060
|
-
case
|
|
4061
|
-
response =
|
|
4053
|
+
case 1:
|
|
4054
|
+
response = _d.sent();
|
|
4062
4055
|
eventBus.emit('openModal', {
|
|
4063
|
-
orderId: (
|
|
4056
|
+
orderId: (_b = (_a = response === null || response === undefined ? undefined : response.data) === null || _a === undefined ? undefined : _a.data) === null || _b === undefined ? undefined : _b.orderReference,
|
|
4064
4057
|
onClose: payload.onClose,
|
|
4058
|
+
onPaymentSuccess: payload.onPaymentSuccess,
|
|
4065
4059
|
environment: payload.environment,
|
|
4066
4060
|
});
|
|
4067
|
-
return [2 /*return*/, response.data];
|
|
4068
|
-
case
|
|
4069
|
-
error_1 =
|
|
4070
|
-
(
|
|
4061
|
+
return [2 /*return*/, payload.onCreateOrder(response.data)];
|
|
4062
|
+
case 2:
|
|
4063
|
+
error_1 = _d.sent();
|
|
4064
|
+
(_c = payload.onFailure) === null || _c === undefined ? undefined : _c.call(payload, error_1);
|
|
4071
4065
|
return [2 /*return*/, error_1];
|
|
4072
|
-
case
|
|
4066
|
+
case 3: return [2 /*return*/];
|
|
4073
4067
|
}
|
|
4074
4068
|
});
|
|
4075
4069
|
}); };
|
|
@@ -4077,9 +4071,9 @@ var useNombaCheckout = function (payload) { return __awaiter(undefined, undefine
|
|
|
4077
4071
|
var Loader = function () { return (React.createElement("svg", { width: "18", height: "21", viewBox: "0 0 18 21", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
4078
4072
|
React.createElement("path", { d: "M10.3203 8.49095L12.002 7.47669L13.6836 6.46243L15.3652 5.44817L17.0468 4.43393V0.545959L15.3652 1.56021L13.6836 2.57447L12.002 3.58872L10.3203 4.60297L8.63871 5.6172V7.56118L6.95709 6.54697L5.27546 5.53271L3.50974 4.51845L1.82811 3.5042L0.146484 2.48994V6.37789L1.82811 7.39215L3.50974 8.40641L5.19136 9.42067L6.87298 10.4349L8.5546 11.4492L6.87298 12.4634L5.19136 13.4777L3.50974 14.4919L1.82811 15.5062L0.146484 16.3514V20.2394L1.82811 19.2251L3.50974 18.2108L5.19136 17.1966L6.87298 16.1824L8.5546 15.1681V13.2241L10.2362 14.2383L11.9179 15.2526L13.5995 16.2669L15.2811 17.2811L16.9628 18.2954V14.4074L15.2811 13.3932L13.5995 12.3789L11.9179 11.3646L10.2362 10.3504L8.5546 9.33613L10.3203 8.49095Z", fill: "#121212" }))); };
|
|
4079
4073
|
|
|
4080
|
-
var CloseIcon = function () { return (React.createElement("svg", { width:
|
|
4081
|
-
React.createElement("rect", { width:
|
|
4082
|
-
React.createElement("path", {
|
|
4074
|
+
var CloseIcon = function () { return (React.createElement("svg", { width: '32', height: '32', viewBox: '0 0 32 32', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
4075
|
+
React.createElement("rect", { width: '32', height: '32', rx: '16', fill: '#F2F2F2', fillOpacity: '0.64' }),
|
|
4076
|
+
React.createElement("path", { fillRule: 'evenodd', clipRule: 'evenodd', d: 'M11.7646 11.7646C11.8948 11.6344 12.1059 11.6344 12.236 11.7646L16.0003 15.5289L19.7646 11.7646C19.8948 11.6344 20.1059 11.6344 20.236 11.7646C20.3662 11.8948 20.3662 12.1059 20.236 12.236L16.4717 16.0003L20.236 19.7646C20.3662 19.8948 20.3662 20.1059 20.236 20.236C20.1059 20.3662 19.8948 20.3662 19.7646 20.236L16.0003 16.4717L12.236 20.236C12.1059 20.3662 11.8948 20.3662 11.7646 20.236C11.6344 20.1059 11.6344 19.8948 11.7646 19.7646L15.5289 16.0003L11.7646 12.236C11.6344 12.1059 11.6344 11.8948 11.7646 11.7646Z', fill: '#0D0D0D' }))); };
|
|
4083
4077
|
|
|
4084
4078
|
var NombaCheckoutModal = /** @class */ (function (_super) {
|
|
4085
4079
|
__extends(NombaCheckoutModal, _super);
|
|
@@ -4096,26 +4090,41 @@ var NombaCheckoutModal = /** @class */ (function (_super) {
|
|
|
4096
4090
|
_this.handleIframeLoad = function () {
|
|
4097
4091
|
_this.setState({ isLoading: false });
|
|
4098
4092
|
};
|
|
4093
|
+
_this.handleMessage = function (event) {
|
|
4094
|
+
var _a, _b, _c;
|
|
4095
|
+
if (((_a = event.data) === null || _a === undefined ? undefined : _a.type) === 'onSuccess') {
|
|
4096
|
+
(_b = _this.state) === null || _b === undefined ? undefined : _b.onPaymentSuccess((_c = event.data) === null || _c === undefined ? undefined : _c.orderDetails);
|
|
4097
|
+
}
|
|
4098
|
+
};
|
|
4099
4099
|
_this.state = {
|
|
4100
4100
|
orderId: '',
|
|
4101
4101
|
isLoading: true,
|
|
4102
4102
|
isOpen: false,
|
|
4103
4103
|
onClose: function () { },
|
|
4104
|
+
onPaymentSuccess: function () { },
|
|
4104
4105
|
environment: 'live',
|
|
4105
4106
|
};
|
|
4106
4107
|
return _this;
|
|
4107
4108
|
}
|
|
4108
4109
|
NombaCheckoutModal.prototype.componentDidMount = function () {
|
|
4109
4110
|
var _this = this;
|
|
4111
|
+
window.addEventListener('message', this.handleMessage);
|
|
4110
4112
|
eventBus.on('openModal', function (_a) {
|
|
4111
|
-
var orderId = _a.orderId, onClose = _a.onClose, environment = _a.environment;
|
|
4112
|
-
_this.setState({
|
|
4113
|
+
var orderId = _a.orderId, onClose = _a.onClose, environment = _a.environment, onPaymentSuccess = _a.onPaymentSuccess;
|
|
4114
|
+
_this.setState({
|
|
4115
|
+
isOpen: true,
|
|
4116
|
+
orderId: orderId,
|
|
4117
|
+
onClose: onClose,
|
|
4118
|
+
environment: environment,
|
|
4119
|
+
onPaymentSuccess: onPaymentSuccess,
|
|
4120
|
+
});
|
|
4113
4121
|
});
|
|
4114
4122
|
eventBus.on('closeModal', function () {
|
|
4115
4123
|
_this.setState({ isOpen: false });
|
|
4116
4124
|
});
|
|
4117
4125
|
};
|
|
4118
4126
|
NombaCheckoutModal.prototype.componentWillUnmount = function () {
|
|
4127
|
+
window.removeEventListener('message', this.handleMessage);
|
|
4119
4128
|
eventBus.off('openModal', this.handleOpen);
|
|
4120
4129
|
eventBus.off('closeModal', this.handleClose);
|
|
4121
4130
|
};
|
|
@@ -4131,7 +4140,7 @@ var NombaCheckoutModal = /** @class */ (function (_super) {
|
|
|
4131
4140
|
React.createElement(Loader, null))),
|
|
4132
4141
|
React.createElement("button", { style: modalStyles.closeButton, onClick: this.handleClose },
|
|
4133
4142
|
React.createElement(CloseIcon, null)),
|
|
4134
|
-
React.createElement("iframe", { src: "https://checkout.nomba.com/".concat(this.state.environment === 'sandbox' ? 'sandbox' : 'pay', "/").concat(orderId), allow: 'clipboard-write clipboard-read', width: '100%', height: '80vh', style: modalStyles.iframe, title: 'Nomba checkout', onLoad: this.handleIframeLoad })))));
|
|
4143
|
+
React.createElement("iframe", { src: "https://checkout.nomba.com/".concat(this.state.environment === 'sandbox' ? 'sandbox' : 'pay', "/").concat(orderId), allow: 'clipboard-write clipboard-read', width: '100%', height: '80vh', style: modalStyles.iframe, title: 'Nomba checkout', onLoad: this.handleIframeLoad, id: 'checkout-sdk-iframe', name: 'react-sdk' })))));
|
|
4135
4144
|
};
|
|
4136
4145
|
return NombaCheckoutModal;
|
|
4137
4146
|
}(Component));
|