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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-nomba-checkout-sdk",
3
- "version": "1.0.3",
3
+ "version": "2.0.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,5 @@
1
1
  import eventBus from '../eventBus';
2
2
  import { handleNombaApiCall } from './handleNombaApiCall';
3
- import { useGenerateToken } from './useGenerateToken';
4
3
 
5
4
  interface CheckoutPayload {
6
5
  order: {
@@ -23,23 +22,16 @@ interface CheckoutPayload {
23
22
  };
24
23
  tokenizeCard: boolean;
25
24
  clientId: string;
26
- clientSecret: string;
27
25
  accountId: string;
28
26
  environment?: string;
29
- onSuccess: (orderReference: string) => void;
27
+ onCreateOrder: (orderReference: string) => void;
30
28
  onFailure: (e: any) => void;
31
29
  onClose: () => {};
30
+ onPaymentSuccess: (order: any) => {};
32
31
  }
33
32
 
34
33
  export const useNombaCheckout = async (payload: CheckoutPayload) => {
35
34
  try {
36
- const tokenResponse = await useGenerateToken({
37
- clientId: payload.clientId,
38
- clientSecret: payload.clientSecret,
39
- accountId: payload.accountId,
40
- environment: payload.environment,
41
- });
42
-
43
35
  const response = await handleNombaApiCall(
44
36
  '/checkout/order',
45
37
  'POST',
@@ -51,8 +43,9 @@ export const useNombaCheckout = async (payload: CheckoutPayload) => {
51
43
  tokenizeCard: payload.tokenizeCard,
52
44
  },
53
45
  {
54
- Authorization: `Bearer ${tokenResponse?.data?.data?.access_token}`,
55
46
  accountId: payload.accountId,
47
+ public_key: payload.clientId,
48
+ 'X-Nomba-Integration': 'react-sdk',
56
49
  },
57
50
  payload.environment
58
51
  );
@@ -60,9 +53,10 @@ export const useNombaCheckout = async (payload: CheckoutPayload) => {
60
53
  eventBus.emit('openModal', {
61
54
  orderId: response?.data?.data?.orderReference,
62
55
  onClose: payload.onClose,
56
+ onPaymentSuccess: payload.onPaymentSuccess,
63
57
  environment: payload.environment,
64
58
  });
65
- return response.data;
59
+ return payload.onCreateOrder(response.data);
66
60
  } catch (error: any) {
67
61
  payload.onFailure?.(error);
68
62
  return error;
@@ -1,19 +1,19 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
 
3
3
  export const CloseIcon = () => (
4
4
  <svg
5
- width="32"
6
- height="32"
7
- viewBox="0 0 32 32"
8
- fill="none"
9
- xmlns="http://www.w3.org/2000/svg"
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="32" height="32" rx="16" fill="#F2F2F2" fill-opacity="0.64" />
11
+ <rect width='32' height='32' rx='16' fill='#F2F2F2' fillOpacity='0.64' />
12
12
  <path
13
- fill-rule="evenodd"
14
- clip-rule="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"
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
  );
@@ -9,6 +9,7 @@ interface NombaCheckoutModalState {
9
9
  isLoading: boolean;
10
10
  isOpen: boolean;
11
11
  onClose: () => void;
12
+ onPaymentSuccess: (e: any) => void;
12
13
  environment: string;
13
14
  }
14
15
 
@@ -20,6 +21,7 @@ class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
20
21
  isLoading: true,
21
22
  isOpen: false,
22
23
  onClose: () => {},
24
+ onPaymentSuccess: () => {},
23
25
  environment: 'live',
24
26
  };
25
27
  }
@@ -37,19 +39,30 @@ class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
37
39
  this.setState({ isLoading: false });
38
40
  };
39
41
 
42
+ handleMessage = (event: MessageEvent) => {
43
+ if (event.data?.type === 'onSuccess') {
44
+ this.state?.onPaymentSuccess(event.data?.orderDetails);
45
+ }
46
+ };
47
+
40
48
  componentDidMount() {
49
+ window.addEventListener('message', this.handleMessage);
50
+
41
51
  eventBus.on(
42
52
  'openModal',
43
53
  ({
44
54
  orderId,
45
55
  onClose,
46
56
  environment,
47
- }: {
48
- orderId: string;
49
- onClose: () => void;
50
- environment: string;
51
- }) => {
52
- this.setState({ isOpen: true, orderId, onClose, environment });
57
+ onPaymentSuccess,
58
+ }: NombaCheckoutModalState) => {
59
+ this.setState({
60
+ isOpen: true,
61
+ orderId,
62
+ onClose,
63
+ environment,
64
+ onPaymentSuccess,
65
+ });
53
66
  }
54
67
  );
55
68
 
@@ -59,6 +72,7 @@ class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
59
72
  }
60
73
 
61
74
  componentWillUnmount() {
75
+ window.removeEventListener('message', this.handleMessage);
62
76
  eventBus.off('openModal', this.handleOpen);
63
77
  eventBus.off('closeModal', this.handleClose);
64
78
  }
@@ -78,7 +92,6 @@ class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
78
92
  <Loader />
79
93
  </div>
80
94
  )}
81
-
82
95
  <button style={modalStyles.closeButton} onClick={this.handleClose}>
83
96
  <CloseIcon />
84
97
  </button>
@@ -91,6 +104,8 @@ class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
91
104
  style={modalStyles.iframe}
92
105
  title='Nomba checkout'
93
106
  onLoad={this.handleIframeLoad}
107
+ id='checkout-sdk-iframe'
108
+ name='react-sdk'
94
109
  />
95
110
  </div>
96
111
  </div>
package/src/index.tsx CHANGED
@@ -1,14 +1,14 @@
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"
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
14
  useGetOrder,
@@ -21,5 +21,5 @@ export {
21
21
  useGetUssdCode,
22
22
  useGenerateToken,
23
23
  useNombaCheckout,
24
- InitializeNombaCheckout
24
+ InitializeNombaCheckout,
25
25
  };