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.
Files changed (36) hide show
  1. package/README.md +99 -19
  2. package/dist/apis/handleNombaApiCall.d.ts +3 -0
  3. package/dist/apis/handleVendorApiCall.d.ts +3 -0
  4. package/dist/apis/useGenerateToken.d.ts +8 -0
  5. package/dist/apis/useNombaCheckout.d.ts +30 -0
  6. package/dist/assets/CloseIcon.d.ts +1 -1
  7. package/dist/components/NombaCheckoutModal.d.ts +14 -9
  8. package/dist/eventBus.d.ts +8 -0
  9. package/dist/helpers/InitializeNombaCheckout.d.ts +1 -0
  10. package/dist/index.d.ts +12 -11
  11. package/dist/index.esm.js +273 -151
  12. package/dist/index.esm.js.map +1 -1
  13. package/dist/index.js +275 -152
  14. package/dist/index.js.map +1 -1
  15. package/package.json +1 -1
  16. package/src/apis/handleNombaApiCall.ts +26 -0
  17. package/src/apis/handleVendorApiCall.ts +26 -0
  18. package/src/apis/useCardCheckout.ts +2 -2
  19. package/src/apis/useCardCheckoutOtp.ts +2 -2
  20. package/src/apis/useFetchUssdBanks.ts +2 -2
  21. package/src/apis/useGenerateQrCode.ts +2 -2
  22. package/src/apis/useGenerateToken.ts +30 -0
  23. package/src/apis/useGetOrder.ts +2 -2
  24. package/src/apis/useGetUssdCode.ts +2 -2
  25. package/src/apis/useNombaCheckout.ts +64 -0
  26. package/src/apis/useResendOtp.ts +2 -2
  27. package/src/apis/useVerifyOrderStatus.ts +2 -2
  28. package/src/assets/CloseIcon.tsx +11 -11
  29. package/src/components/NombaCheckoutModal.tsx +110 -63
  30. package/src/eventBus.ts +25 -0
  31. package/src/helpers/InitializeNombaCheckout.tsx +26 -0
  32. package/src/index.tsx +14 -13
  33. package/dist/apis/handleApiCall.d.ts +0 -3
  34. package/dist/components/NombaCheckoutButton.d.ts +0 -17
  35. package/src/apis/handleApiCall.ts +0 -20
  36. 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 `react-nomba-checkout-sdk` is a lightweight JavaScript library designed to simplify payment processing and checkout experiences in your react web applications.
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
- ## πŸš€ Getting Started
5
+ > Built with ❀️ by **Israel Itua**
6
6
 
7
- To install the SDK, use npm or yarn:
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
- ## Usage
19
+ ---
15
20
 
16
- Here’s how to integrate the SDK into your project:
21
+ ## ⚑ Quick Start
17
22
 
18
- ```
23
+ Here’s how to integrate the SDK into your React project:
19
24
 
20
- ## πŸ“– Usage
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
- ```bash
23
- import { NombaCheckoutButton } from "react-nomba-checkout-sdk";
24
-
25
- const CheckoutPage = ({orderId}) => {
26
- return (
27
- <div>
28
- <NombaCheckoutButton orderId={orderId} onClose = {onClose}/>
29
- </div>
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
- export default CheckoutPage;
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,3 @@
1
+ export declare const handleNombaApiCall: (url: string, method: string, body?: {} | null, customHeaders?: {
2
+ [key: string]: string;
3
+ }, environment?: string) => Promise<import("axios").AxiosResponse<any, any>>;
@@ -0,0 +1,3 @@
1
+ export declare const handleVendorApiCall: (url: string, method: string, body?: {} | null, customHeaders?: {
2
+ [key: string]: string;
3
+ }, environment?: string) => Promise<import("axios").AxiosResponse<any, any>>;
@@ -0,0 +1,8 @@
1
+ interface GenerateTokenPayload {
2
+ clientId: string;
3
+ clientSecret: string;
4
+ accountId: string;
5
+ environment?: string;
6
+ }
7
+ export declare const useGenerateToken: (payload: GenerateTokenPayload) => Promise<any>;
8
+ export {};
@@ -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 "react";
1
+ import React from 'react';
2
2
  export declare const CloseIcon: () => React.JSX.Element;
@@ -1,16 +1,21 @@
1
- import React, { Component } from "react";
2
- import "../styles.css";
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<NombaCheckoutModalProps, NombaCheckoutModalState> {
11
- constructor(props: NombaCheckoutModalProps);
11
+ declare class NombaCheckoutModal extends Component<{}, NombaCheckoutModalState> {
12
+ constructor(props: {});
13
+ handleOpen: (orderId: string) => void;
12
14
  handleClose: () => void;
13
15
  handleIframeLoad: () => void;
14
- render(): React.JSX.Element;
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 { NombaCheckoutButton } from "./components/NombaCheckoutButton";
2
- import { NombaCheckoutModal } from "./components/NombaCheckoutModal";
3
- import { useGetOrder } from "./apis/useGetOrder";
4
- import { useCardCheckout } from "./apis/useCardCheckout";
5
- import { useCardCheckoutOtp } from "./apis/useCardCheckoutOtp";
6
- import { useGenerateQrCode } from "./apis/useGenerateQrCode";
7
- import { useVerifyOrderStatus } from "./apis/useVerifyOrderStatus";
8
- import { useResendOtp } from "./apis/useResendOtp";
9
- import { useFetchUssdBanks } from "./apis/useFetchUssdBanks";
10
- import { useGetUssdCode } from "./apis/useGetUssdCode";
11
- export { NombaCheckoutButton, NombaCheckoutModal, useGetOrder, useCardCheckout, useCardCheckoutOtp, useResendOtp, useGenerateQrCode, useVerifyOrderStatus, useFetchUssdBanks, useGetUssdCode, };
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, };