@vindhq/sloud-payment-sdk 1.0.2 → 1.0.3
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 +30 -182
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +24 -54203
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sloud Payment SDK
|
|
2
2
|
|
|
3
|
-
A secure, embeddable payment widget built in React
|
|
3
|
+
A secure, embeddable payment widget for straightforward customer payments, built in React and usable in **any JavaScript application** (React, Angular, Vue, or vanilla JS). Ships with **ESM, CJS, and UMD builds** for easy integration in any environment.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -72,16 +72,12 @@ For direct browser usage without a bundler, use the UMD build which includes Rea
|
|
|
72
72
|
|
|
73
73
|
## Usage
|
|
74
74
|
|
|
75
|
-
The payment widget
|
|
75
|
+
The payment widget is designed for straightforward payments with customer details.
|
|
76
76
|
|
|
77
77
|
> **Note**: When using the UMD build in the browser (via script tag), access the widget via `PaymentWidget.default`. For npm/ES module imports, use the standard `import PaymentWidget from "sloud-payment-sdk"`.
|
|
78
78
|
|
|
79
|
-
### External Payment (Simple Payments)
|
|
80
|
-
|
|
81
|
-
For straightforward payments with customer details:
|
|
82
|
-
|
|
83
79
|
```tsx
|
|
84
|
-
import PaymentWidget from "sloud-payment-sdk";
|
|
80
|
+
import PaymentWidget from "@vindhq/sloud-payment-sdk";
|
|
85
81
|
|
|
86
82
|
const widget = new PaymentWidget({
|
|
87
83
|
type: "external",
|
|
@@ -99,91 +95,6 @@ const widget = new PaymentWidget({
|
|
|
99
95
|
widget.showPopup();
|
|
100
96
|
```
|
|
101
97
|
|
|
102
|
-
### Storefront Payment (E-commerce Orders)
|
|
103
|
-
|
|
104
|
-
For e-commerce orders with products and delivery:
|
|
105
|
-
|
|
106
|
-
```tsx
|
|
107
|
-
import PaymentWidget from "sloud-payment-sdk";
|
|
108
|
-
|
|
109
|
-
const widget = new PaymentWidget({
|
|
110
|
-
type: "storefront",
|
|
111
|
-
public_key: "your-public-api-key",
|
|
112
|
-
slug: "my-store",
|
|
113
|
-
amount: 5000, // Additional amount (e.g., shipping fees)
|
|
114
|
-
discount: 1000, // Optional discount
|
|
115
|
-
channel: "delivery", // "pickup" or "delivery"
|
|
116
|
-
customer: {
|
|
117
|
-
first_name: "Jane",
|
|
118
|
-
last_name: "Smith",
|
|
119
|
-
phone_number: "+2348098765432",
|
|
120
|
-
email: "jane.smith@example.com",
|
|
121
|
-
},
|
|
122
|
-
delivery_details: {
|
|
123
|
-
street: "123 Main Street",
|
|
124
|
-
city: "Lagos",
|
|
125
|
-
state: "Lagos",
|
|
126
|
-
country: "Nigeria",
|
|
127
|
-
note: "Please call on arrival", // Optional
|
|
128
|
-
},
|
|
129
|
-
products: [
|
|
130
|
-
{
|
|
131
|
-
product_id: "prod_123",
|
|
132
|
-
quantity: 2,
|
|
133
|
-
variation: ["Large", "Blue"], // Optional
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
product_id: "prod_456",
|
|
137
|
-
quantity: 1,
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Payment method will be selected by the user in the widget UI
|
|
143
|
-
|
|
144
|
-
widget.showPopup();
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### Sloudfront Payment (Manual Orders)
|
|
148
|
-
|
|
149
|
-
For manual orders with existing transaction/customer/business IDs:
|
|
150
|
-
|
|
151
|
-
```tsx
|
|
152
|
-
import PaymentWidget from "sloud-payment-sdk";
|
|
153
|
-
|
|
154
|
-
const widget = new PaymentWidget({
|
|
155
|
-
type: "sloudfront",
|
|
156
|
-
public_key: "your-public-api-key",
|
|
157
|
-
transaction_id: "txn_abc123",
|
|
158
|
-
customer_id: "cust_xyz789",
|
|
159
|
-
business_id: "biz_def456",
|
|
160
|
-
amount: 5000,
|
|
161
|
-
discount: 500,
|
|
162
|
-
channel: "pickup", // "pickup" or "delivery"
|
|
163
|
-
customer: {
|
|
164
|
-
first_name: "Alice",
|
|
165
|
-
last_name: "Johnson",
|
|
166
|
-
phone_number: "+2348011223344",
|
|
167
|
-
email: "alice.johnson@example.com",
|
|
168
|
-
},
|
|
169
|
-
delivery_details: {
|
|
170
|
-
street: "456 Oak Avenue",
|
|
171
|
-
city: "Abuja",
|
|
172
|
-
state: "FCT",
|
|
173
|
-
country: "Nigeria",
|
|
174
|
-
},
|
|
175
|
-
products: [
|
|
176
|
-
{
|
|
177
|
-
product_id: "prod_789",
|
|
178
|
-
quantity: 1,
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Payment method will be selected by the user in the widget UI
|
|
184
|
-
|
|
185
|
-
widget.showPopup();
|
|
186
|
-
```
|
|
187
98
|
|
|
188
99
|
---
|
|
189
100
|
|
|
@@ -193,50 +104,17 @@ widget.showPopup();
|
|
|
193
104
|
|
|
194
105
|
Creates a new payment widget instance.
|
|
195
106
|
|
|
196
|
-
####
|
|
107
|
+
#### Payment Widget Options
|
|
197
108
|
|
|
198
109
|
| Parameter | Type | Required | Description |
|
|
199
110
|
| --------------- | --------- | -------- | -------------------------------------------------- |
|
|
200
|
-
| `type` | `
|
|
111
|
+
| `type` | `"external"` | Yes | Payment type (must be `"external"`) |
|
|
201
112
|
| `public_key` | `string` | Yes | Your public API key for secure payments |
|
|
202
|
-
| `isLocalEnv` | `boolean` | No | Set to `true` for local development environment |
|
|
203
|
-
|
|
204
|
-
#### External Payment Options
|
|
205
|
-
|
|
206
|
-
| Parameter | Type | Required | Description |
|
|
207
|
-
| ---------- | --------- | -------- | ------------------------------------------ |
|
|
208
113
|
| `amount` | `number` | Yes | Payment amount in smallest currency unit |
|
|
209
114
|
| `customer` | `Customer` | Yes | Customer information object |
|
|
115
|
+
| `isLocalEnv` | `boolean` | No | Set to `true` for local development environment |
|
|
210
116
|
|
|
211
|
-
#### Storefront Payment Options
|
|
212
|
-
|
|
213
|
-
| Parameter | Type | Required | Description |
|
|
214
|
-
| -------------------- | ------------------ | -------- | ------------------------------------------ |
|
|
215
|
-
| `slug` | `string` | Yes | Store identifier |
|
|
216
|
-
| `amount` | `number` | Yes | Additional amount (e.g., shipping fees) |
|
|
217
|
-
| `discount` | `number` | No | Discount amount |
|
|
218
|
-
| `channel` | `ChannelType` | Yes | Delivery channel: `"pickup"` or `"delivery"` |
|
|
219
|
-
| `customer` | `Customer` | Yes | Customer information object |
|
|
220
|
-
| `delivery_details` | `DeliveryDetails` | Yes | Delivery address and notes |
|
|
221
|
-
| `products` | `Product[]` | Yes | Array of products in the order |
|
|
222
|
-
|
|
223
|
-
**Note:** Payment method is selected by the user within the widget UI based on available payment options.
|
|
224
|
-
|
|
225
|
-
#### Sloudfront Payment Options
|
|
226
117
|
|
|
227
|
-
| Parameter | Type | Required | Description |
|
|
228
|
-
| -------------------- | ------------------ | -------- | ------------------------------------------ |
|
|
229
|
-
| `transaction_id` | `string` | Yes | Existing transaction ID |
|
|
230
|
-
| `customer_id` | `string` | Yes | Existing customer ID |
|
|
231
|
-
| `business_id` | `string` | Yes | Existing business ID |
|
|
232
|
-
| `amount` | `number` | Yes | Additional amount |
|
|
233
|
-
| `discount` | `number` | No | Discount amount |
|
|
234
|
-
| `channel` | `ChannelType` | Yes | Delivery channel: `"pickup"` or `"delivery"` |
|
|
235
|
-
| `customer` | `Customer` | Yes | Customer information object |
|
|
236
|
-
| `delivery_details` | `DeliveryDetails` | Yes | Delivery address and notes |
|
|
237
|
-
| `products` | `Product[]` | Yes | Array of products in the order |
|
|
238
|
-
|
|
239
|
-
**Note:** Payment method is selected by the user within the widget UI based on available payment options.
|
|
240
118
|
|
|
241
119
|
#### Type Definitions
|
|
242
120
|
|
|
@@ -250,35 +128,6 @@ interface Customer {
|
|
|
250
128
|
}
|
|
251
129
|
```
|
|
252
130
|
|
|
253
|
-
**DeliveryDetails**
|
|
254
|
-
```ts
|
|
255
|
-
interface DeliveryDetails {
|
|
256
|
-
street: string;
|
|
257
|
-
city: string;
|
|
258
|
-
state: string;
|
|
259
|
-
country: string;
|
|
260
|
-
note?: string;
|
|
261
|
-
}
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
**Product**
|
|
265
|
-
```ts
|
|
266
|
-
interface Product {
|
|
267
|
-
product_id: string;
|
|
268
|
-
quantity: number;
|
|
269
|
-
variation?: string[];
|
|
270
|
-
}
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
**PaymentType**
|
|
274
|
-
```ts
|
|
275
|
-
type PaymentType = "external" | "storefront" | "sloudfront";
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
**ChannelType**
|
|
279
|
-
```ts
|
|
280
|
-
type ChannelType = "pickup" | "delivery";
|
|
281
|
-
```
|
|
282
131
|
|
|
283
132
|
#### Methods
|
|
284
133
|
|
|
@@ -302,14 +151,14 @@ widget.hidePopup();
|
|
|
302
151
|
|
|
303
152
|
## Validation and Error Handling
|
|
304
153
|
|
|
305
|
-
The SDK includes built-in validation
|
|
154
|
+
The SDK includes built-in validation:
|
|
306
155
|
|
|
307
156
|
```ts
|
|
308
157
|
import {
|
|
309
158
|
PaymentWidget,
|
|
310
159
|
validatePaymentWidgetOptions,
|
|
311
160
|
PaymentWidgetValidationError,
|
|
312
|
-
} from "sloud-payment-sdk";
|
|
161
|
+
} from "@vindhq/sloud-payment-sdk";
|
|
313
162
|
|
|
314
163
|
try {
|
|
315
164
|
const options = {
|
|
@@ -338,25 +187,26 @@ try {
|
|
|
338
187
|
|
|
339
188
|
## Advanced Usage
|
|
340
189
|
|
|
341
|
-
###
|
|
190
|
+
### Payload Builders
|
|
342
191
|
|
|
343
|
-
The SDK uses a builder pattern for payment payloads
|
|
192
|
+
The SDK uses a builder pattern for payment payloads:
|
|
344
193
|
|
|
345
194
|
```ts
|
|
346
195
|
import {
|
|
347
196
|
buildPaymentInstrumentPayload,
|
|
348
|
-
|
|
349
|
-
getRegisteredPaymentTypes,
|
|
350
|
-
} from "sloud-payment-sdk";
|
|
351
|
-
|
|
352
|
-
// Get all registered payment types
|
|
353
|
-
const types = getRegisteredPaymentTypes();
|
|
354
|
-
console.log(types); // ["external", "storefront", "sloudfront"]
|
|
197
|
+
} from "@vindhq/sloud-payment-sdk";
|
|
355
198
|
|
|
356
199
|
// Build payload from options
|
|
357
200
|
const payload = buildPaymentInstrumentPayload({
|
|
358
201
|
type: "external",
|
|
359
|
-
|
|
202
|
+
public_key: "pk_test_123",
|
|
203
|
+
amount: 10000,
|
|
204
|
+
customer: {
|
|
205
|
+
first_name: "John",
|
|
206
|
+
last_name: "Doe",
|
|
207
|
+
phone_number: "+2348012345678",
|
|
208
|
+
email: "john.doe@example.com",
|
|
209
|
+
},
|
|
360
210
|
});
|
|
361
211
|
```
|
|
362
212
|
|
|
@@ -367,22 +217,20 @@ The SDK is written in TypeScript and provides full type definitions:
|
|
|
367
217
|
```ts
|
|
368
218
|
import type {
|
|
369
219
|
PaymentWidgetOptions,
|
|
370
|
-
ExternalPaymentWidgetOptions,
|
|
371
|
-
StorefrontPaymentWidgetOptions,
|
|
372
|
-
SloudfrontPaymentWidgetOptions,
|
|
373
|
-
PaymentType,
|
|
374
|
-
ChannelType,
|
|
375
220
|
Customer,
|
|
376
|
-
|
|
377
|
-
Product,
|
|
378
|
-
} from "sloud-payment-sdk";
|
|
221
|
+
} from "@vindhq/sloud-payment-sdk";
|
|
379
222
|
|
|
380
|
-
// TypeScript will enforce correct fields
|
|
381
|
-
const options:
|
|
382
|
-
type: "
|
|
223
|
+
// TypeScript will enforce correct fields
|
|
224
|
+
const options: PaymentWidgetOptions = {
|
|
225
|
+
type: "external",
|
|
383
226
|
public_key: "pk_test_123",
|
|
384
|
-
|
|
385
|
-
|
|
227
|
+
amount: 10000,
|
|
228
|
+
customer: {
|
|
229
|
+
first_name: "John",
|
|
230
|
+
last_name: "Doe",
|
|
231
|
+
phone_number: "+2348012345678",
|
|
232
|
+
email: "john.doe@example.com",
|
|
233
|
+
},
|
|
386
234
|
};
|
|
387
235
|
```
|
|
388
236
|
|