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/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
export const handleNombaApiCall = async (
|
|
4
|
+
url: string,
|
|
5
|
+
method: string,
|
|
6
|
+
body?: {} | null,
|
|
7
|
+
customHeaders?: { [key: string]: string },
|
|
8
|
+
environment?: string
|
|
9
|
+
) => {
|
|
10
|
+
const baseUrl =
|
|
11
|
+
environment === 'sandbox'
|
|
12
|
+
? 'https://sandbox.nomba.com/v1'
|
|
13
|
+
: 'https://api.nomba.com/v1';
|
|
14
|
+
|
|
15
|
+
const options = {
|
|
16
|
+
method: method,
|
|
17
|
+
headers: {
|
|
18
|
+
'content-type': 'application/json',
|
|
19
|
+
...customHeaders,
|
|
20
|
+
},
|
|
21
|
+
data: body && body,
|
|
22
|
+
url: `${baseUrl}${url}`,
|
|
23
|
+
};
|
|
24
|
+
const response = await axios(options);
|
|
25
|
+
return response;
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
export const handleVendorApiCall = async (
|
|
4
|
+
url: string,
|
|
5
|
+
method: string,
|
|
6
|
+
body?: {} | null,
|
|
7
|
+
customHeaders?: { [key: string]: string },
|
|
8
|
+
environment?: string
|
|
9
|
+
) => {
|
|
10
|
+
const baseUrl =
|
|
11
|
+
environment === 'sandbox'
|
|
12
|
+
? 'https://sandbox.nomba.com/v1'
|
|
13
|
+
: 'https://api.nomba.com/v1';
|
|
14
|
+
|
|
15
|
+
const options = {
|
|
16
|
+
method: method,
|
|
17
|
+
headers: {
|
|
18
|
+
'content-type': 'application/json',
|
|
19
|
+
...customHeaders,
|
|
20
|
+
},
|
|
21
|
+
data: body && body,
|
|
22
|
+
url: `${baseUrl}${url}`,
|
|
23
|
+
};
|
|
24
|
+
const response = await axios(options);
|
|
25
|
+
return response;
|
|
26
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
interface CardCheckoutPayload {
|
|
4
4
|
orderReference: string;
|
|
@@ -9,7 +9,7 @@ interface CardCheckoutPayload {
|
|
|
9
9
|
|
|
10
10
|
export const useCardCheckout = async (payload: CardCheckoutPayload) => {
|
|
11
11
|
try {
|
|
12
|
-
const response = await
|
|
12
|
+
const response = await handleVendorApiCall(
|
|
13
13
|
"/checkout/checkout-card-detail",
|
|
14
14
|
"POST",
|
|
15
15
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
interface OtpRequest {
|
|
4
4
|
otp: string;
|
|
@@ -9,7 +9,7 @@ interface OtpRequest {
|
|
|
9
9
|
|
|
10
10
|
export const useCardCheckoutOtp = async (payload: OtpRequest) => {
|
|
11
11
|
try {
|
|
12
|
-
const response = await
|
|
12
|
+
const response = await handleVendorApiCall(
|
|
13
13
|
"/checkout/checkout-card-otp",
|
|
14
14
|
"POST",
|
|
15
15
|
payload
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
export const useFetchUssdBanks = async () => {
|
|
4
4
|
try {
|
|
5
|
-
const response = await
|
|
5
|
+
const response = await handleVendorApiCall(`/checkout/ussd/banks`, "GET");
|
|
6
6
|
return response.data;
|
|
7
7
|
} catch (error: any) {
|
|
8
8
|
return error;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
export const useGenerateQrCode = async (orderReference: string) => {
|
|
4
4
|
try {
|
|
5
|
-
const response = await
|
|
5
|
+
const response = await handleVendorApiCall(
|
|
6
6
|
`/checkout/qr/${orderReference}`,
|
|
7
7
|
"GET"
|
|
8
8
|
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { handleNombaApiCall } from './handleNombaApiCall';
|
|
2
|
+
|
|
3
|
+
interface GenerateTokenPayload {
|
|
4
|
+
clientId: string;
|
|
5
|
+
clientSecret: string;
|
|
6
|
+
accountId: string;
|
|
7
|
+
environment?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useGenerateToken = async (payload: GenerateTokenPayload) => {
|
|
11
|
+
try {
|
|
12
|
+
const response = await handleNombaApiCall(
|
|
13
|
+
'/auth/token/issue',
|
|
14
|
+
'POST',
|
|
15
|
+
{
|
|
16
|
+
grant_type: 'client_credentials',
|
|
17
|
+
client_id: payload.clientId,
|
|
18
|
+
client_secret: payload.clientSecret,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accountId: payload.accountId,
|
|
22
|
+
},
|
|
23
|
+
payload.environment
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return response;
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
return error;
|
|
29
|
+
}
|
|
30
|
+
};
|
package/src/apis/useGetOrder.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
export const useGetOrder = async (orderReference: string) => {
|
|
4
4
|
try {
|
|
5
|
-
const response = await
|
|
5
|
+
const response = await handleVendorApiCall(
|
|
6
6
|
`/checkout/order/${orderReference}`,
|
|
7
7
|
"GET"
|
|
8
8
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
interface UssdCodeRequest {
|
|
4
4
|
ussdBankId: string;
|
|
@@ -16,7 +16,7 @@ export const useGetUssdCode = async (payload: {
|
|
|
16
16
|
orderId: string;
|
|
17
17
|
}) => {
|
|
18
18
|
try {
|
|
19
|
-
const response = await
|
|
19
|
+
const response = await handleVendorApiCall(
|
|
20
20
|
`/checkout/ussd/code`,
|
|
21
21
|
"POST",
|
|
22
22
|
payload
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import eventBus from '../eventBus';
|
|
2
|
+
import { handleNombaApiCall } from './handleNombaApiCall';
|
|
3
|
+
|
|
4
|
+
interface CheckoutPayload {
|
|
5
|
+
order: {
|
|
6
|
+
orderReference: string;
|
|
7
|
+
customerId: string;
|
|
8
|
+
callbackUrl: string;
|
|
9
|
+
customerEmail: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
currency: string;
|
|
12
|
+
accountId: string;
|
|
13
|
+
splitRequest?: {
|
|
14
|
+
splitType: string;
|
|
15
|
+
splitList: [
|
|
16
|
+
{
|
|
17
|
+
accountId: string;
|
|
18
|
+
value: number;
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
tokenizeCard: boolean;
|
|
24
|
+
clientId: string;
|
|
25
|
+
accountId: string;
|
|
26
|
+
environment?: string;
|
|
27
|
+
onCreateOrder: (orderReference: string) => void;
|
|
28
|
+
onFailure: (e: any) => void;
|
|
29
|
+
onClose: () => {};
|
|
30
|
+
onPaymentSuccess: (order: any) => {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const useNombaCheckout = async (payload: CheckoutPayload) => {
|
|
34
|
+
try {
|
|
35
|
+
const response = await handleNombaApiCall(
|
|
36
|
+
'/checkout/order',
|
|
37
|
+
'POST',
|
|
38
|
+
{
|
|
39
|
+
order: {
|
|
40
|
+
...payload.order,
|
|
41
|
+
accountId: payload.accountId,
|
|
42
|
+
},
|
|
43
|
+
tokenizeCard: payload.tokenizeCard,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
accountId: payload.accountId,
|
|
47
|
+
public_key: payload.clientId,
|
|
48
|
+
'X-Nomba-Integration': 'react-sdk',
|
|
49
|
+
},
|
|
50
|
+
payload.environment
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
eventBus.emit('openModal', {
|
|
54
|
+
orderId: response?.data?.data?.orderReference,
|
|
55
|
+
onClose: payload.onClose,
|
|
56
|
+
onPaymentSuccess: payload.onPaymentSuccess,
|
|
57
|
+
environment: payload.environment,
|
|
58
|
+
});
|
|
59
|
+
return payload.onCreateOrder(response.data);
|
|
60
|
+
} catch (error: any) {
|
|
61
|
+
payload.onFailure?.(error);
|
|
62
|
+
return error;
|
|
63
|
+
}
|
|
64
|
+
};
|
package/src/apis/useResendOtp.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
export const useResendOtp = async (orderReference: string) => {
|
|
4
4
|
try {
|
|
5
|
-
const response = await
|
|
5
|
+
const response = await handleVendorApiCall("/checkout/resend-otp", "POST", {
|
|
6
6
|
orderReference,
|
|
7
7
|
});
|
|
8
8
|
return response.data;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleVendorApiCall } from "./handleVendorApiCall";
|
|
2
2
|
|
|
3
3
|
export const useVerifyOrderStatus = async (orderReference: string) => {
|
|
4
4
|
try {
|
|
5
|
-
const response = await
|
|
5
|
+
const response = await handleVendorApiCall(
|
|
6
6
|
"/checkout/confirm-transaction-receipt",
|
|
7
7
|
"POST",
|
|
8
8
|
{ orderReference }
|
package/src/assets/CloseIcon.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
export const CloseIcon = () => (
|
|
4
4
|
<svg
|
|
5
|
-
width=
|
|
6
|
-
height=
|
|
7
|
-
viewBox=
|
|
8
|
-
fill=
|
|
9
|
-
xmlns=
|
|
5
|
+
width='32'
|
|
6
|
+
height='32'
|
|
7
|
+
viewBox='0 0 32 32'
|
|
8
|
+
fill='none'
|
|
9
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
10
10
|
>
|
|
11
|
-
<rect width=
|
|
11
|
+
<rect width='32' height='32' rx='16' fill='#F2F2F2' fillOpacity='0.64' />
|
|
12
12
|
<path
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
d=
|
|
16
|
-
fill=
|
|
13
|
+
fillRule='evenodd'
|
|
14
|
+
clipRule='evenodd'
|
|
15
|
+
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'
|
|
16
|
+
fill='#0D0D0D'
|
|
17
17
|
/>
|
|
18
18
|
</svg>
|
|
19
19
|
);
|
|
@@ -1,39 +1,86 @@
|
|
|
1
|
-
import React, { Component } from
|
|
2
|
-
import
|
|
3
|
-
import Loader from
|
|
4
|
-
import { CloseIcon } from
|
|
5
|
-
|
|
6
|
-
interface NombaCheckoutModalProps {
|
|
7
|
-
orderId: string;
|
|
8
|
-
onClose: () => void;
|
|
9
|
-
}
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import '../styles.css';
|
|
3
|
+
import Loader from '../assets/Loader';
|
|
4
|
+
import { CloseIcon } from '../assets/CloseIcon';
|
|
5
|
+
import eventBus from '../eventBus';
|
|
10
6
|
|
|
11
7
|
interface NombaCheckoutModalState {
|
|
8
|
+
orderId: string;
|
|
12
9
|
isLoading: boolean;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
onPaymentSuccess: (e: any) => void;
|
|
13
|
+
environment: string;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
class NombaCheckoutModal extends Component<
|
|
16
|
-
|
|
17
|
-
NombaCheckoutModalState
|
|
18
|
-
> {
|
|
19
|
-
constructor(props: NombaCheckoutModalProps) {
|
|
16
|
+
class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
|
|
17
|
+
constructor(props: {}) {
|
|
20
18
|
super(props);
|
|
21
19
|
this.state = {
|
|
20
|
+
orderId: '',
|
|
22
21
|
isLoading: true,
|
|
22
|
+
isOpen: false,
|
|
23
|
+
onClose: () => {},
|
|
24
|
+
onPaymentSuccess: () => {},
|
|
25
|
+
environment: 'live',
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
|
|
29
|
+
handleOpen = (orderId: string) => {
|
|
30
|
+
this.setState({ isOpen: true, orderId });
|
|
31
|
+
};
|
|
32
|
+
|
|
26
33
|
handleClose = () => {
|
|
27
|
-
this.
|
|
34
|
+
this.state.onClose?.();
|
|
35
|
+
this.setState({ isOpen: false });
|
|
28
36
|
};
|
|
29
37
|
|
|
30
38
|
handleIframeLoad = () => {
|
|
31
39
|
this.setState({ isLoading: false });
|
|
32
40
|
};
|
|
33
41
|
|
|
42
|
+
handleMessage = (event: MessageEvent) => {
|
|
43
|
+
if (event.data?.type === 'onSuccess') {
|
|
44
|
+
this.state?.onPaymentSuccess(event.data?.orderDetails);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
componentDidMount() {
|
|
49
|
+
window.addEventListener('message', this.handleMessage);
|
|
50
|
+
|
|
51
|
+
eventBus.on(
|
|
52
|
+
'openModal',
|
|
53
|
+
({
|
|
54
|
+
orderId,
|
|
55
|
+
onClose,
|
|
56
|
+
environment,
|
|
57
|
+
onPaymentSuccess,
|
|
58
|
+
}: NombaCheckoutModalState) => {
|
|
59
|
+
this.setState({
|
|
60
|
+
isOpen: true,
|
|
61
|
+
orderId,
|
|
62
|
+
onClose,
|
|
63
|
+
environment,
|
|
64
|
+
onPaymentSuccess,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
eventBus.on('closeModal', () => {
|
|
70
|
+
this.setState({ isOpen: false });
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
componentWillUnmount() {
|
|
75
|
+
window.removeEventListener('message', this.handleMessage);
|
|
76
|
+
eventBus.off('openModal', this.handleOpen);
|
|
77
|
+
eventBus.off('closeModal', this.handleClose);
|
|
78
|
+
}
|
|
79
|
+
|
|
34
80
|
render() {
|
|
35
|
-
const { orderId } = this.
|
|
36
|
-
|
|
81
|
+
const { isLoading, isOpen, orderId } = this.state;
|
|
82
|
+
|
|
83
|
+
if (!isOpen) return null;
|
|
37
84
|
|
|
38
85
|
return (
|
|
39
86
|
<div style={modalStyles.overlay} onClick={this.handleClose}>
|
|
@@ -41,23 +88,23 @@ class NombaCheckoutModal extends Component<
|
|
|
41
88
|
<div style={modalStyles.content}>
|
|
42
89
|
{isLoading && (
|
|
43
90
|
<div style={modalStyles.loader}>
|
|
44
|
-
<div className=
|
|
91
|
+
<div className='spinner'></div>
|
|
45
92
|
<Loader />
|
|
46
93
|
</div>
|
|
47
94
|
)}
|
|
48
|
-
|
|
49
95
|
<button style={modalStyles.closeButton} onClick={this.handleClose}>
|
|
50
96
|
<CloseIcon />
|
|
51
97
|
</button>
|
|
52
98
|
|
|
53
99
|
<iframe
|
|
54
|
-
src={`https://checkout.nomba.com
|
|
55
|
-
allow=
|
|
56
|
-
width=
|
|
57
|
-
height=
|
|
100
|
+
src={`https://checkout.nomba.com/${this.state.environment === 'sandbox' ? 'sandbox' : 'pay'}/${orderId}`}
|
|
101
|
+
allow='clipboard-write clipboard-read'
|
|
102
|
+
width='100%'
|
|
103
|
+
height='80vh'
|
|
58
104
|
style={modalStyles.iframe}
|
|
59
|
-
title=
|
|
105
|
+
title='Nomba checkout'
|
|
60
106
|
onLoad={this.handleIframeLoad}
|
|
107
|
+
id='checkout-sdk-iframe'
|
|
61
108
|
/>
|
|
62
109
|
</div>
|
|
63
110
|
</div>
|
|
@@ -68,64 +115,64 @@ class NombaCheckoutModal extends Component<
|
|
|
68
115
|
|
|
69
116
|
const modalStyles: { [key: string]: React.CSSProperties } = {
|
|
70
117
|
overlay: {
|
|
71
|
-
position:
|
|
118
|
+
position: 'fixed',
|
|
72
119
|
top: 0,
|
|
73
120
|
left: 0,
|
|
74
121
|
right: 0,
|
|
75
122
|
bottom: 0,
|
|
76
|
-
backgroundColor:
|
|
77
|
-
display:
|
|
78
|
-
justifyContent:
|
|
79
|
-
alignItems:
|
|
123
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
124
|
+
display: 'flex',
|
|
125
|
+
justifyContent: 'center',
|
|
126
|
+
alignItems: 'center',
|
|
80
127
|
zIndex: 9999,
|
|
81
128
|
},
|
|
82
129
|
modal: {
|
|
83
|
-
backgroundColor:
|
|
84
|
-
width:
|
|
85
|
-
maxWidth:
|
|
86
|
-
borderRadius:
|
|
87
|
-
boxShadow:
|
|
88
|
-
position:
|
|
89
|
-
height:
|
|
90
|
-
maxHeight:
|
|
130
|
+
backgroundColor: 'white',
|
|
131
|
+
width: '100%',
|
|
132
|
+
maxWidth: '60vw',
|
|
133
|
+
borderRadius: '8px',
|
|
134
|
+
boxShadow: '0 4px 8px rgba(0, 0, 0, 0.1)',
|
|
135
|
+
position: 'relative',
|
|
136
|
+
height: '600px',
|
|
137
|
+
maxHeight: '95vh',
|
|
91
138
|
},
|
|
92
139
|
header: {
|
|
93
|
-
position:
|
|
94
|
-
display:
|
|
95
|
-
justifyContent:
|
|
96
|
-
alignItems:
|
|
140
|
+
position: 'relative',
|
|
141
|
+
display: 'flex',
|
|
142
|
+
justifyContent: 'space-between',
|
|
143
|
+
alignItems: 'center',
|
|
97
144
|
},
|
|
98
145
|
closeButton: {
|
|
99
|
-
position:
|
|
100
|
-
top:
|
|
101
|
-
right:
|
|
102
|
-
border:
|
|
103
|
-
background:
|
|
146
|
+
position: 'absolute',
|
|
147
|
+
top: '16px',
|
|
148
|
+
right: '16px',
|
|
149
|
+
border: 'none',
|
|
150
|
+
background: 'transparent',
|
|
104
151
|
},
|
|
105
152
|
content: {
|
|
106
|
-
position:
|
|
153
|
+
position: 'relative',
|
|
107
154
|
},
|
|
108
155
|
iframe: {
|
|
109
|
-
border:
|
|
110
|
-
borderRadius:
|
|
111
|
-
width:
|
|
112
|
-
maxHeight:
|
|
113
|
-
height:
|
|
114
|
-
display:
|
|
156
|
+
border: 'none',
|
|
157
|
+
borderRadius: '8px',
|
|
158
|
+
width: '100%',
|
|
159
|
+
maxHeight: '95vh',
|
|
160
|
+
height: '600px',
|
|
161
|
+
display: 'block',
|
|
115
162
|
},
|
|
116
163
|
loader: {
|
|
117
|
-
position:
|
|
164
|
+
position: 'absolute',
|
|
118
165
|
top: 0,
|
|
119
166
|
left: 0,
|
|
120
|
-
width:
|
|
121
|
-
height:
|
|
122
|
-
backgroundColor:
|
|
123
|
-
display:
|
|
124
|
-
flexDirection:
|
|
125
|
-
alignItems:
|
|
126
|
-
justifyContent:
|
|
127
|
-
fontSize:
|
|
128
|
-
fontWeight:
|
|
167
|
+
width: '100%',
|
|
168
|
+
height: '100%',
|
|
169
|
+
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
|
170
|
+
display: 'flex',
|
|
171
|
+
flexDirection: 'column',
|
|
172
|
+
alignItems: 'center',
|
|
173
|
+
justifyContent: 'center',
|
|
174
|
+
fontSize: '18px',
|
|
175
|
+
fontWeight: 'bold',
|
|
129
176
|
},
|
|
130
177
|
};
|
|
131
178
|
|
package/src/eventBus.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class EventBus {
|
|
2
|
+
private events: { [key: string]: Array<(data: any) => void> } = {};
|
|
3
|
+
|
|
4
|
+
on(event: string, listener: (data: any) => void): void {
|
|
5
|
+
if (!this.events[event]) {
|
|
6
|
+
this.events[event] = [];
|
|
7
|
+
}
|
|
8
|
+
this.events[event].push(listener);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
emit(event: string, data: any): void {
|
|
12
|
+
if (this.events[event]) {
|
|
13
|
+
this.events[event].forEach(listener => listener(data));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
off(event: string, listener: (data: any) => void): void {
|
|
18
|
+
if (this.events[event]) {
|
|
19
|
+
this.events[event] = this.events[event].filter(l => l !== listener);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const eventBus = new EventBus();
|
|
25
|
+
export default eventBus;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom/client";
|
|
3
|
+
import { NombaCheckoutModal } from "../components/NombaCheckoutModal";
|
|
4
|
+
|
|
5
|
+
let root: ReactDOM.Root | null = null;
|
|
6
|
+
|
|
7
|
+
export const InitializeNombaCheckout = () => {
|
|
8
|
+
const modalDivId = "nomba-checkout-modal";
|
|
9
|
+
|
|
10
|
+
let modalContainer = document.getElementById(modalDivId);
|
|
11
|
+
if (!modalContainer) {
|
|
12
|
+
modalContainer = document.createElement("div");
|
|
13
|
+
modalContainer.id = modalDivId;
|
|
14
|
+
document.body.appendChild(modalContainer);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!root) {
|
|
18
|
+
root = ReactDOM.createRoot(modalContainer);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
root!.render(
|
|
22
|
+
<div>
|
|
23
|
+
<NombaCheckoutModal />
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
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
12
|
|
|
13
13
|
export {
|
|
14
|
-
NombaCheckoutButton,
|
|
15
|
-
NombaCheckoutModal,
|
|
16
14
|
useGetOrder,
|
|
17
15
|
useCardCheckout,
|
|
18
16
|
useCardCheckoutOtp,
|
|
@@ -21,4 +19,7 @@ export {
|
|
|
21
19
|
useVerifyOrderStatus,
|
|
22
20
|
useFetchUssdBanks,
|
|
23
21
|
useGetUssdCode,
|
|
22
|
+
useGenerateToken,
|
|
23
|
+
useNombaCheckout,
|
|
24
|
+
InitializeNombaCheckout,
|
|
24
25
|
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React, { Component } from "react";
|
|
2
|
-
interface NombaCheckoutButtonProps {
|
|
3
|
-
orderId: string;
|
|
4
|
-
buttonText?: string;
|
|
5
|
-
buttonStyle?: React.CSSProperties;
|
|
6
|
-
children?: React.ReactNode;
|
|
7
|
-
onClose: () => void;
|
|
8
|
-
}
|
|
9
|
-
interface NombaCheckoutButtonState {
|
|
10
|
-
showModal: boolean;
|
|
11
|
-
}
|
|
12
|
-
declare class NombaCheckoutButton extends Component<NombaCheckoutButtonProps, NombaCheckoutButtonState> {
|
|
13
|
-
constructor(props: NombaCheckoutButtonProps);
|
|
14
|
-
handleClose: () => void;
|
|
15
|
-
render(): React.JSX.Element;
|
|
16
|
-
}
|
|
17
|
-
export { NombaCheckoutButton };
|