@vindhq/sloud-payment-sdk 1.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 +398 -0
- package/dist/index.cjs.js +51442 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.esm.js +51440 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +51448 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/react/index.esm.js +51440 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/react/rollup.config.d.ts +8 -0
- package/dist/react/rollup.config.dts.d.ts +3 -0
- package/dist/react/src/components/Button/Button.types.d.ts +6 -0
- package/dist/react/src/components/Button/index.d.ts +3 -0
- package/dist/react/src/components/CopyToClipboardSpan/CopyToClipboard.types.d.ts +4 -0
- package/dist/react/src/components/CopyToClipboardSpan/index.d.ts +3 -0
- package/dist/react/src/components/Input/Input.types.d.ts +17 -0
- package/dist/react/src/components/Input/index.d.ts +3 -0
- package/dist/react/src/components/Skeleton/PaymentOptionSkeletons.d.ts +6 -0
- package/dist/react/src/components/TextArea/TextArea.types.d.ts +19 -0
- package/dist/react/src/components/TextArea/index.d.ts +3 -0
- package/dist/react/src/components/Widget.d.ts +6 -0
- package/dist/react/src/components/modals/AwaitingPaymentModal/AwaitingPaymentModal.d.ts +2 -0
- package/dist/react/src/components/modals/AwaitingPaymentTimeoutModal/AwaitingPaymentTimeoutModal.d.ts +2 -0
- package/dist/react/src/components/modals/Modal.d.ts +10 -0
- package/dist/react/src/components/modals/PaymentDetailsModal/PaymentDetailsModal.d.ts +2 -0
- package/dist/react/src/components/modals/PaymentDetailsModal/hooks/useTimer.d.ts +7 -0
- package/dist/react/src/components/modals/PaymentOptionsModal/PaymentOptionsModal.d.ts +2 -0
- package/dist/react/src/components/modals/PaymentOptionsModal/RadioButton.d.ts +11 -0
- package/dist/react/src/components/modals/PaymentOptionsModal/paymentOptionsMap.d.ts +5 -0
- package/dist/react/src/components/modals/SuccessModal/SuccessModal.d.ts +2 -0
- package/dist/react/src/components/modals/state/actions/data.d.ts +10 -0
- package/dist/react/src/components/modals/state/actions/index.d.ts +5 -0
- package/dist/react/src/components/modals/state/actions/modal.d.ts +5 -0
- package/dist/react/src/components/modals/state/actions/payment.d.ts +7 -0
- package/dist/react/src/components/modals/state/constants/actionTypes.d.ts +24 -0
- package/dist/react/src/components/modals/state/constants/index.d.ts +2 -0
- package/dist/react/src/components/modals/state/constants/initialState.d.ts +36 -0
- package/dist/react/src/components/modals/state/reducers/data.d.ts +2 -0
- package/dist/react/src/components/modals/state/reducers/index.d.ts +2 -0
- package/dist/react/src/components/modals/state/reducers/modal.d.ts +2 -0
- package/dist/react/src/components/modals/state/reducers/payment.d.ts +2 -0
- package/dist/react/src/components/modals/state/types/common.d.ts +12 -0
- package/dist/react/src/components/modals/state/types/data.d.ts +34 -0
- package/dist/react/src/components/modals/state/types/index.d.ts +8 -0
- package/dist/react/src/components/modals/state/types/modal.d.ts +12 -0
- package/dist/react/src/components/modals/state/types/payment.d.ts +14 -0
- package/dist/react/src/components/modals/state/utils/index.d.ts +37 -0
- package/dist/react/src/context/ModalProvider.d.ts +4 -0
- package/dist/react/src/context/PaymentInfoContext.d.ts +26 -0
- package/dist/react/src/context/PaymentWidgetContext.d.ts +13 -0
- package/dist/react/src/context/modal.d.ts +4 -0
- package/dist/react/src/context/types.d.ts +28 -0
- package/dist/react/src/hooks/types.d.ts +34 -0
- package/dist/react/src/hooks/useModalControl.d.ts +27 -0
- package/dist/react/src/hooks/usePaymentAPI.d.ts +10 -0
- package/dist/react/src/hooks/useShortPolling.d.ts +4 -0
- package/dist/react/src/index.d.ts +2 -0
- package/dist/react/src/services/config/endpoints.d.ts +9 -0
- package/dist/react/src/services/config/error.d.ts +5 -0
- package/dist/react/src/services/index.d.ts +27 -0
- package/dist/react/src/services/payments/index.d.ts +4 -0
- package/dist/react/src/services/payments/types.d.ts +68 -0
- package/dist/react/src/services/products/index.d.ts +1 -0
- package/dist/react/src/services/products/types.d.ts +124 -0
- package/dist/react/src/services/store/index.d.ts +2 -0
- package/dist/react/src/services/store/types.d.ts +57 -0
- package/dist/react/src/services/utils/widgetConfig.d.ts +20 -0
- package/dist/react/src/svg_components/ArrowLeftIcon.d.ts +3 -0
- package/dist/react/src/svg_components/BankTransferIcon.d.ts +2 -0
- package/dist/react/src/svg_components/CancelIcon.d.ts +7 -0
- package/dist/react/src/svg_components/CardIcon.d.ts +2 -0
- package/dist/react/src/svg_components/CloseIcon.d.ts +3 -0
- package/dist/react/src/svg_components/CopyIcon.d.ts +2 -0
- package/dist/react/src/svg_components/EyeCloseIcon.d.ts +5 -0
- package/dist/react/src/svg_components/EyeOpenIcon.d.ts +5 -0
- package/dist/react/src/svg_components/SloudIcon.d.ts +2 -0
- package/dist/react/src/utils/enums/AxiosErrorCodes.d.ts +7 -0
- package/dist/react/src/utils/enums/AxiosMethods.d.ts +7 -0
- package/dist/react/src/utils/helpers/classNames.d.ts +7 -0
- package/dist/react/src/utils/helpers/formatCurrency.d.ts +10 -0
- package/dist/react/src/utils/helpers/phoneDefaults.d.ts +3 -0
- package/dist/react/src/utils/helpers/validatePhone.d.ts +7 -0
- package/dist/react/src/utils/image_utils/index.d.ts +9 -0
- package/dist/react/src/utils/storage/index.d.ts +9 -0
- package/dist/react/src/widget.d.ts +27 -0
- package/dist/rollup.config.d.ts +8 -0
- package/dist/rollup.config.dts.d.ts +3 -0
- package/dist/src/components/Button/Button.types.d.ts +6 -0
- package/dist/src/components/Button/index.d.ts +3 -0
- package/dist/src/components/CopyToClipboardSpan/CopyToClipboard.types.d.ts +4 -0
- package/dist/src/components/CopyToClipboardSpan/index.d.ts +3 -0
- package/dist/src/components/Input/Input.types.d.ts +17 -0
- package/dist/src/components/Input/index.d.ts +3 -0
- package/dist/src/components/Skeleton/PaymentOptionSkeletons.d.ts +6 -0
- package/dist/src/components/TextArea/TextArea.types.d.ts +19 -0
- package/dist/src/components/TextArea/index.d.ts +3 -0
- package/dist/src/components/Widget.d.ts +6 -0
- package/dist/src/components/modals/AwaitingPaymentModal/AwaitingPaymentModal.d.ts +2 -0
- package/dist/src/components/modals/AwaitingPaymentTimeoutModal/AwaitingPaymentTimeoutModal.d.ts +2 -0
- package/dist/src/components/modals/Modal.d.ts +10 -0
- package/dist/src/components/modals/PaymentDetailsModal/PaymentDetailsModal.d.ts +2 -0
- package/dist/src/components/modals/PaymentDetailsModal/hooks/useTimer.d.ts +7 -0
- package/dist/src/components/modals/PaymentOptionsModal/PaymentOptionsModal.d.ts +2 -0
- package/dist/src/components/modals/PaymentOptionsModal/RadioButton.d.ts +11 -0
- package/dist/src/components/modals/PaymentOptionsModal/paymentOptionsMap.d.ts +5 -0
- package/dist/src/components/modals/SuccessModal/SuccessModal.d.ts +2 -0
- package/dist/src/components/modals/state/actions/data.d.ts +10 -0
- package/dist/src/components/modals/state/actions/index.d.ts +5 -0
- package/dist/src/components/modals/state/actions/modal.d.ts +5 -0
- package/dist/src/components/modals/state/actions/payment.d.ts +7 -0
- package/dist/src/components/modals/state/constants/actionTypes.d.ts +24 -0
- package/dist/src/components/modals/state/constants/index.d.ts +2 -0
- package/dist/src/components/modals/state/constants/initialState.d.ts +36 -0
- package/dist/src/components/modals/state/reducers/data.d.ts +2 -0
- package/dist/src/components/modals/state/reducers/index.d.ts +2 -0
- package/dist/src/components/modals/state/reducers/modal.d.ts +2 -0
- package/dist/src/components/modals/state/reducers/payment.d.ts +2 -0
- package/dist/src/components/modals/state/types/common.d.ts +12 -0
- package/dist/src/components/modals/state/types/data.d.ts +34 -0
- package/dist/src/components/modals/state/types/index.d.ts +8 -0
- package/dist/src/components/modals/state/types/modal.d.ts +12 -0
- package/dist/src/components/modals/state/types/payment.d.ts +14 -0
- package/dist/src/components/modals/state/utils/index.d.ts +37 -0
- package/dist/src/context/ModalProvider.d.ts +4 -0
- package/dist/src/context/PaymentInfoContext.d.ts +26 -0
- package/dist/src/context/PaymentWidgetContext.d.ts +13 -0
- package/dist/src/context/modal.d.ts +4 -0
- package/dist/src/context/types.d.ts +28 -0
- package/dist/src/hooks/types.d.ts +34 -0
- package/dist/src/hooks/useModalControl.d.ts +27 -0
- package/dist/src/hooks/usePaymentAPI.d.ts +10 -0
- package/dist/src/hooks/useShortPolling.d.ts +4 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/services/config/endpoints.d.ts +9 -0
- package/dist/src/services/config/error.d.ts +5 -0
- package/dist/src/services/index.d.ts +27 -0
- package/dist/src/services/payments/index.d.ts +4 -0
- package/dist/src/services/payments/types.d.ts +68 -0
- package/dist/src/services/products/index.d.ts +1 -0
- package/dist/src/services/products/types.d.ts +124 -0
- package/dist/src/services/store/index.d.ts +2 -0
- package/dist/src/services/store/types.d.ts +57 -0
- package/dist/src/services/utils/widgetConfig.d.ts +20 -0
- package/dist/src/svg_components/ArrowLeftIcon.d.ts +3 -0
- package/dist/src/svg_components/BankTransferIcon.d.ts +2 -0
- package/dist/src/svg_components/CancelIcon.d.ts +7 -0
- package/dist/src/svg_components/CardIcon.d.ts +2 -0
- package/dist/src/svg_components/CloseIcon.d.ts +3 -0
- package/dist/src/svg_components/CopyIcon.d.ts +2 -0
- package/dist/src/svg_components/EyeCloseIcon.d.ts +5 -0
- package/dist/src/svg_components/EyeOpenIcon.d.ts +5 -0
- package/dist/src/svg_components/SloudIcon.d.ts +2 -0
- package/dist/src/utils/enums/AxiosErrorCodes.d.ts +7 -0
- package/dist/src/utils/enums/AxiosMethods.d.ts +7 -0
- package/dist/src/utils/helpers/classNames.d.ts +7 -0
- package/dist/src/utils/helpers/formatCurrency.d.ts +10 -0
- package/dist/src/utils/helpers/phoneDefaults.d.ts +3 -0
- package/dist/src/utils/helpers/validatePhone.d.ts +7 -0
- package/dist/src/utils/image_utils/index.d.ts +9 -0
- package/dist/src/utils/storage/index.d.ts +9 -0
- package/dist/src/widget.d.ts +27 -0
- package/package.json +87 -0
package/README.md
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# Sloud Payment SDK
|
|
2
|
+
|
|
3
|
+
A secure, embeddable payment widget built in React, usable in **any JavaScript application** (React, Angular, Vue, or vanilla JS). Ships with **ESM builds** for easy integration.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Developer-friendly**: authored in React for easy maintenance and composability.
|
|
10
|
+
- **Framework-agnostic**: works with React (peer dependency required).
|
|
11
|
+
- **ESM build format** for modern npm/React apps.
|
|
12
|
+
- **Bundled CSS** via PostCSS.
|
|
13
|
+
- **Asset support** (SVG icons) included in the build.
|
|
14
|
+
- **Built-in validation** using Formik and Yup.
|
|
15
|
+
- **Toast notifications** via react-hot-toast.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Using npm
|
|
23
|
+
npm install sloud-payment-sdk
|
|
24
|
+
|
|
25
|
+
# Using yarn
|
|
26
|
+
yarn add sloud-payment-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Note:** This widget has peer dependencies on React 19.1.1+. Make sure you have React and ReactDOM installed:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install react react-dom
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
The payment widget supports three payment types: **external**, **storefront**, and **sloudfront**. Each type has its own set of required fields.
|
|
40
|
+
|
|
41
|
+
### External Payment (Simple Payments)
|
|
42
|
+
|
|
43
|
+
For straightforward payments with customer details:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import PaymentWidget from "sloud-payment-sdk";
|
|
47
|
+
|
|
48
|
+
const widget = new PaymentWidget({
|
|
49
|
+
type: "external",
|
|
50
|
+
public_key: "your-public-api-key",
|
|
51
|
+
amount: 10000, // Amount in smallest currency unit (e.g., kobo for NGN)
|
|
52
|
+
customer: {
|
|
53
|
+
first_name: "John",
|
|
54
|
+
last_name: "Doe",
|
|
55
|
+
phone_number: "+2348012345678",
|
|
56
|
+
email: "john.doe@example.com",
|
|
57
|
+
},
|
|
58
|
+
isLocalEnv: false, // Optional: set to true for local development
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
widget.showPopup();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Storefront Payment (E-commerce Orders)
|
|
65
|
+
|
|
66
|
+
For e-commerce orders with products and delivery:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import PaymentWidget from "sloud-payment-sdk";
|
|
70
|
+
|
|
71
|
+
const widget = new PaymentWidget({
|
|
72
|
+
type: "storefront",
|
|
73
|
+
public_key: "your-public-api-key",
|
|
74
|
+
slug: "my-store",
|
|
75
|
+
amount: 5000, // Additional amount (e.g., shipping fees)
|
|
76
|
+
discount: 1000, // Optional discount
|
|
77
|
+
channel: "delivery", // "pickup" or "delivery"
|
|
78
|
+
customer: {
|
|
79
|
+
first_name: "Jane",
|
|
80
|
+
last_name: "Smith",
|
|
81
|
+
phone_number: "+2348098765432",
|
|
82
|
+
email: "jane.smith@example.com",
|
|
83
|
+
},
|
|
84
|
+
delivery_details: {
|
|
85
|
+
street: "123 Main Street",
|
|
86
|
+
city: "Lagos",
|
|
87
|
+
state: "Lagos",
|
|
88
|
+
country: "Nigeria",
|
|
89
|
+
note: "Please call on arrival", // Optional
|
|
90
|
+
},
|
|
91
|
+
products: [
|
|
92
|
+
{
|
|
93
|
+
product_id: "prod_123",
|
|
94
|
+
quantity: 2,
|
|
95
|
+
variation: ["Large", "Blue"], // Optional
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
product_id: "prod_456",
|
|
99
|
+
quantity: 1,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Payment method will be selected by the user in the widget UI
|
|
105
|
+
|
|
106
|
+
widget.showPopup();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Sloudfront Payment (Manual Orders)
|
|
110
|
+
|
|
111
|
+
For manual orders with existing transaction/customer/business IDs:
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import PaymentWidget from "sloud-payment-sdk";
|
|
115
|
+
|
|
116
|
+
const widget = new PaymentWidget({
|
|
117
|
+
type: "sloudfront",
|
|
118
|
+
public_key: "your-public-api-key",
|
|
119
|
+
transaction_id: "txn_abc123",
|
|
120
|
+
customer_id: "cust_xyz789",
|
|
121
|
+
business_id: "biz_def456",
|
|
122
|
+
amount: 5000,
|
|
123
|
+
discount: 500,
|
|
124
|
+
channel: "pickup", // "pickup" or "delivery"
|
|
125
|
+
customer: {
|
|
126
|
+
first_name: "Alice",
|
|
127
|
+
last_name: "Johnson",
|
|
128
|
+
phone_number: "+2348011223344",
|
|
129
|
+
email: "alice.johnson@example.com",
|
|
130
|
+
},
|
|
131
|
+
delivery_details: {
|
|
132
|
+
street: "456 Oak Avenue",
|
|
133
|
+
city: "Abuja",
|
|
134
|
+
state: "FCT",
|
|
135
|
+
country: "Nigeria",
|
|
136
|
+
},
|
|
137
|
+
products: [
|
|
138
|
+
{
|
|
139
|
+
product_id: "prod_789",
|
|
140
|
+
quantity: 1,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Payment method will be selected by the user in the widget UI
|
|
146
|
+
|
|
147
|
+
widget.showPopup();
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## API
|
|
153
|
+
|
|
154
|
+
### `new PaymentWidget(options: PaymentWidgetOptions)`
|
|
155
|
+
|
|
156
|
+
Creates a new payment widget instance.
|
|
157
|
+
|
|
158
|
+
#### Common Options (All Payment Types)
|
|
159
|
+
|
|
160
|
+
| Parameter | Type | Required | Description |
|
|
161
|
+
| --------------- | --------- | -------- | -------------------------------------------------- |
|
|
162
|
+
| `type` | `PaymentType` | Yes | Payment type: `"external"`, `"storefront"`, or `"sloudfront"` |
|
|
163
|
+
| `public_key` | `string` | Yes | Your public API key for secure payments |
|
|
164
|
+
| `isLocalEnv` | `boolean` | No | Set to `true` for local development environment |
|
|
165
|
+
|
|
166
|
+
#### External Payment Options
|
|
167
|
+
|
|
168
|
+
| Parameter | Type | Required | Description |
|
|
169
|
+
| ---------- | --------- | -------- | ------------------------------------------ |
|
|
170
|
+
| `amount` | `number` | Yes | Payment amount in smallest currency unit |
|
|
171
|
+
| `customer` | `Customer` | Yes | Customer information object |
|
|
172
|
+
|
|
173
|
+
#### Storefront Payment Options
|
|
174
|
+
|
|
175
|
+
| Parameter | Type | Required | Description |
|
|
176
|
+
| -------------------- | ------------------ | -------- | ------------------------------------------ |
|
|
177
|
+
| `slug` | `string` | Yes | Store identifier |
|
|
178
|
+
| `amount` | `number` | Yes | Additional amount (e.g., shipping fees) |
|
|
179
|
+
| `discount` | `number` | No | Discount amount |
|
|
180
|
+
| `channel` | `ChannelType` | Yes | Delivery channel: `"pickup"` or `"delivery"` |
|
|
181
|
+
| `customer` | `Customer` | Yes | Customer information object |
|
|
182
|
+
| `delivery_details` | `DeliveryDetails` | Yes | Delivery address and notes |
|
|
183
|
+
| `products` | `Product[]` | Yes | Array of products in the order |
|
|
184
|
+
|
|
185
|
+
**Note:** Payment method is selected by the user within the widget UI based on available payment options.
|
|
186
|
+
|
|
187
|
+
#### Sloudfront Payment Options
|
|
188
|
+
|
|
189
|
+
| Parameter | Type | Required | Description |
|
|
190
|
+
| -------------------- | ------------------ | -------- | ------------------------------------------ |
|
|
191
|
+
| `transaction_id` | `string` | Yes | Existing transaction ID |
|
|
192
|
+
| `customer_id` | `string` | Yes | Existing customer ID |
|
|
193
|
+
| `business_id` | `string` | Yes | Existing business ID |
|
|
194
|
+
| `amount` | `number` | Yes | Additional amount |
|
|
195
|
+
| `discount` | `number` | No | Discount amount |
|
|
196
|
+
| `channel` | `ChannelType` | Yes | Delivery channel: `"pickup"` or `"delivery"` |
|
|
197
|
+
| `customer` | `Customer` | Yes | Customer information object |
|
|
198
|
+
| `delivery_details` | `DeliveryDetails` | Yes | Delivery address and notes |
|
|
199
|
+
| `products` | `Product[]` | Yes | Array of products in the order |
|
|
200
|
+
|
|
201
|
+
**Note:** Payment method is selected by the user within the widget UI based on available payment options.
|
|
202
|
+
|
|
203
|
+
#### Type Definitions
|
|
204
|
+
|
|
205
|
+
**Customer**
|
|
206
|
+
```ts
|
|
207
|
+
interface Customer {
|
|
208
|
+
first_name: string;
|
|
209
|
+
last_name: string;
|
|
210
|
+
phone_number: string;
|
|
211
|
+
email: string;
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**DeliveryDetails**
|
|
216
|
+
```ts
|
|
217
|
+
interface DeliveryDetails {
|
|
218
|
+
street: string;
|
|
219
|
+
city: string;
|
|
220
|
+
state: string;
|
|
221
|
+
country: string;
|
|
222
|
+
note?: string;
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**Product**
|
|
227
|
+
```ts
|
|
228
|
+
interface Product {
|
|
229
|
+
product_id: string;
|
|
230
|
+
quantity: number;
|
|
231
|
+
variation?: string[];
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**PaymentType**
|
|
236
|
+
```ts
|
|
237
|
+
type PaymentType = "external" | "storefront" | "sloudfront";
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**ChannelType**
|
|
241
|
+
```ts
|
|
242
|
+
type ChannelType = "pickup" | "delivery";
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Methods
|
|
246
|
+
|
|
247
|
+
##### `showPopup()`
|
|
248
|
+
|
|
249
|
+
Displays the payment widget popup modal.
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
widget.showPopup();
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
##### `hidePopup()`
|
|
256
|
+
|
|
257
|
+
Hides and unmounts the payment widget popup.
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
widget.hidePopup();
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Validation and Error Handling
|
|
266
|
+
|
|
267
|
+
The SDK includes built-in validation for all payment types:
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import {
|
|
271
|
+
PaymentWidget,
|
|
272
|
+
validatePaymentWidgetOptions,
|
|
273
|
+
PaymentWidgetValidationError,
|
|
274
|
+
} from "sloud-payment-sdk";
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
const options = {
|
|
278
|
+
type: "external",
|
|
279
|
+
public_key: "pk_test_123",
|
|
280
|
+
amount: 10000,
|
|
281
|
+
customer: {
|
|
282
|
+
first_name: "John",
|
|
283
|
+
last_name: "Doe",
|
|
284
|
+
phone_number: "+2348012345678",
|
|
285
|
+
email: "invalid-email", // Invalid email format
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// Validate before creating widget
|
|
290
|
+
validatePaymentWidgetOptions(options);
|
|
291
|
+
|
|
292
|
+
const widget = new PaymentWidget(options);
|
|
293
|
+
widget.showPopup();
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (error instanceof PaymentWidgetValidationError) {
|
|
296
|
+
console.error("Validation error:", error.message);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Advanced Usage
|
|
302
|
+
|
|
303
|
+
### Extensible Payload Builders
|
|
304
|
+
|
|
305
|
+
The SDK uses a builder pattern for payment payloads and can be extended with custom payment types:
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
import {
|
|
309
|
+
buildPaymentInstrumentPayload,
|
|
310
|
+
registerPayloadBuilder,
|
|
311
|
+
getRegisteredPaymentTypes,
|
|
312
|
+
} from "sloud-payment-sdk";
|
|
313
|
+
|
|
314
|
+
// Get all registered payment types
|
|
315
|
+
const types = getRegisteredPaymentTypes();
|
|
316
|
+
console.log(types); // ["external", "storefront", "sloudfront"]
|
|
317
|
+
|
|
318
|
+
// Build payload from options
|
|
319
|
+
const payload = buildPaymentInstrumentPayload({
|
|
320
|
+
type: "external",
|
|
321
|
+
// ... other options
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### TypeScript Support
|
|
326
|
+
|
|
327
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
import type {
|
|
331
|
+
PaymentWidgetOptions,
|
|
332
|
+
ExternalPaymentWidgetOptions,
|
|
333
|
+
StorefrontPaymentWidgetOptions,
|
|
334
|
+
SloudfrontPaymentWidgetOptions,
|
|
335
|
+
PaymentType,
|
|
336
|
+
ChannelType,
|
|
337
|
+
Customer,
|
|
338
|
+
DeliveryDetails,
|
|
339
|
+
Product,
|
|
340
|
+
} from "sloud-payment-sdk";
|
|
341
|
+
|
|
342
|
+
// TypeScript will enforce correct fields based on payment type
|
|
343
|
+
const options: StorefrontPaymentWidgetOptions = {
|
|
344
|
+
type: "storefront",
|
|
345
|
+
public_key: "pk_test_123",
|
|
346
|
+
slug: "my-store",
|
|
347
|
+
// ... TypeScript ensures all required fields are present
|
|
348
|
+
};
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Development
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
# Install dependencies
|
|
355
|
+
yarn install
|
|
356
|
+
|
|
357
|
+
# Run dev server with live reload
|
|
358
|
+
yarn dev
|
|
359
|
+
|
|
360
|
+
# Build production bundles
|
|
361
|
+
yarn build
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
- Development server serves `dist` and `public` folders at `http://localhost:8080`.
|
|
365
|
+
- Includes live reload for fast iteration.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## Folder Structure
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
Payment-Widget/
|
|
373
|
+
├─ src/
|
|
374
|
+
│ ├─ index.ts # Entry point
|
|
375
|
+
│ ├─ widget.ts # Widget class
|
|
376
|
+
│ ├─ components/ # React components
|
|
377
|
+
│ └─ styles/ # SCSS/CSS files
|
|
378
|
+
├─ dist/ # Bundled output (ESM, CJS, UMD)
|
|
379
|
+
├─ public/ # Dev server HTML
|
|
380
|
+
├─ rollup.config.ts # Rollup configuration
|
|
381
|
+
└─ package.json
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## Build Details
|
|
387
|
+
|
|
388
|
+
- **ESM/CJS** → externalizes React for React apps.
|
|
389
|
+
- **PostCSS** → injects and minifies CSS.
|
|
390
|
+
- **Assets** → SVG/PNG handled automatically.
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## License
|
|
395
|
+
|
|
396
|
+
Specify your license here (e.g., MIT).
|
|
397
|
+
|
|
398
|
+
---
|