monime-package 1.1.2 → 1.1.4
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 +295 -232
- package/dist/index.d.mts +362 -369
- package/dist/index.d.ts +362 -369
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
# monime-package
|
|
3
3
|
|
|
4
|
-
Official
|
|
4
|
+
Official TypeScript SDK for Monime - a modern, type-safe client library for Sierra Leone's leading payment platform. Provides comprehensive API coverage with predictable response patterns and excellent developer experience.
|
|
5
5
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|

|
|
9
9
|

|
|
10
10
|

|
|
11
|
+

|
|
11
12
|
|
|
12
13
|
Package: `monime-package`
|
|
13
14
|
|
|
@@ -20,6 +21,11 @@ Package: `monime-package`
|
|
|
20
21
|
- **[Environment Variables](#environment-variables)**
|
|
21
22
|
- **[Quick Start](#quick-start)**
|
|
22
23
|
- **[API Reference](#api-reference)**
|
|
24
|
+
- **[Payments](#payments)**
|
|
25
|
+
- **[Webhooks](#webhooks)**
|
|
26
|
+
- **[Receipts](#receipts)**
|
|
27
|
+
- **[USSD OTPs](#ussd-otps)**
|
|
28
|
+
- **[Provider KYC](#provider-kyc)**
|
|
23
29
|
- **[Financial Accounts](#financial-accounts)**
|
|
24
30
|
- **[Internal Transfers](#internal-transfers)**
|
|
25
31
|
- **[Payment Codes](#payment-codes)**
|
|
@@ -45,8 +51,10 @@ Package: `monime-package`
|
|
|
45
51
|
- **Typed** request/response objects for safer integrations
|
|
46
52
|
- **Predictable** return shape: `{ success, data?, error? }`
|
|
47
53
|
- **Client-based** auth: set credentials once per instance
|
|
48
|
-
- **
|
|
54
|
+
- **Zero dependencies** (using native `fetch`) for maximum performance and portability
|
|
49
55
|
- **Full API coverage** for all Monime endpoints
|
|
56
|
+
- **Tree-shaking support** - only bundle what you use
|
|
57
|
+
- **Dual module output** - works with both CommonJS and ES modules
|
|
50
58
|
- **Mobile Money support** (Africell, Orange, etc.)
|
|
51
59
|
- **Bank transfers** and digital wallet integrations
|
|
52
60
|
- **Checkout sessions** for hosted payment pages
|
|
@@ -59,8 +67,15 @@ Package: `monime-package`
|
|
|
59
67
|
npm install monime-package
|
|
60
68
|
# or
|
|
61
69
|
pnpm add monime-package
|
|
70
|
+
# or
|
|
71
|
+
yarn add monime-package
|
|
62
72
|
```
|
|
63
73
|
|
|
74
|
+
**Requirements:**
|
|
75
|
+
- Node.js >= 14
|
|
76
|
+
- TypeScript >= 4.5 (for type safety)
|
|
77
|
+
- Modern bundler that supports ES modules and tree-shaking
|
|
78
|
+
|
|
64
79
|
---
|
|
65
80
|
|
|
66
81
|
## Environment Variables
|
|
@@ -124,14 +139,14 @@ The client exposes namespaced APIs under `client.<module>`. Below is the complet
|
|
|
124
139
|
Manage all incoming payments (payins).
|
|
125
140
|
|
|
126
141
|
```ts
|
|
127
|
-
//
|
|
128
|
-
client.payment.
|
|
142
|
+
// Retrieve payment details
|
|
143
|
+
client.payment.retrieve(paymentId: string): Promise<Result<RetrievePaymentResponse>>
|
|
129
144
|
|
|
130
145
|
// List payments
|
|
131
|
-
client.payment.
|
|
146
|
+
client.payment.list(): Promise<Result<ListPaymentsResponse>>
|
|
132
147
|
|
|
133
|
-
//
|
|
134
|
-
client.payment.
|
|
148
|
+
// Update payment
|
|
149
|
+
client.payment.update(paymentId: string, body: any): Promise<Result<UpdatePaymentResponse>>
|
|
135
150
|
```
|
|
136
151
|
|
|
137
152
|
### Webhooks (New)
|
|
@@ -142,17 +157,17 @@ Manage webhooks for real-time notifications.
|
|
|
142
157
|
// Create webhook
|
|
143
158
|
client.webhook.create(body: CreateWebhookRequest): Promise<Result<CreateWebhookResponse>>
|
|
144
159
|
|
|
145
|
-
//
|
|
146
|
-
client.webhook.
|
|
160
|
+
// Retrieve webhook
|
|
161
|
+
client.webhook.retrieve(webhookId: string): Promise<Result<GetWebhookResponse>>
|
|
147
162
|
|
|
148
163
|
// List webhooks
|
|
149
|
-
client.webhook.
|
|
164
|
+
client.webhook.list(): Promise<Result<ListWebhooksResponse>>
|
|
150
165
|
|
|
151
166
|
// Update webhook
|
|
152
167
|
client.webhook.update(webhookId: string, body: UpdateWebhookRequest): Promise<Result<UpdateWebhookResponse>>
|
|
153
168
|
|
|
154
169
|
// Delete webhook
|
|
155
|
-
client.webhook.delete(webhookId: string): Promise<
|
|
170
|
+
client.webhook.delete(webhookId: string): Promise<Result<void>>
|
|
156
171
|
```
|
|
157
172
|
|
|
158
173
|
### Receipts (New)
|
|
@@ -160,8 +175,8 @@ client.webhook.delete(webhookId: string): Promise<{ success: boolean; error?: Er
|
|
|
160
175
|
Manage payment receipts.
|
|
161
176
|
|
|
162
177
|
```ts
|
|
163
|
-
//
|
|
164
|
-
client.receipt.
|
|
178
|
+
// Retrieve receipt
|
|
179
|
+
client.receipt.retrieve(orderNumber: string): Promise<Result<GetReceiptResponse>>
|
|
165
180
|
|
|
166
181
|
// Redeem receipt
|
|
167
182
|
client.receipt.redeem(orderNumber: string, body: any): Promise<Result<RedeemReceiptResponse>>
|
|
@@ -181,8 +196,8 @@ client.ussdOtp.create(body: CreateUssdOtpRequest): Promise<Result<CreateUssdOtpR
|
|
|
181
196
|
Get provider KYC details.
|
|
182
197
|
|
|
183
198
|
```ts
|
|
184
|
-
//
|
|
185
|
-
client.providerKyc.
|
|
199
|
+
// Retrieve provider KYC
|
|
200
|
+
client.providerKyc.retrieve(providerId: string): Promise<Result<GetProviderKycResponse>>
|
|
186
201
|
```
|
|
187
202
|
|
|
188
203
|
### Financial Accounts
|
|
@@ -191,13 +206,13 @@ Manage digital wallets and financial accounts.
|
|
|
191
206
|
|
|
192
207
|
```ts
|
|
193
208
|
// Create a new financial account
|
|
194
|
-
client.financialAccount.create(name: string): Promise<Result<
|
|
209
|
+
client.financialAccount.create(name: string, currency: "USD" | "SLE"): Promise<Result<CreateFinancialAccountResponse>>
|
|
195
210
|
|
|
196
|
-
//
|
|
197
|
-
client.financialAccount.
|
|
211
|
+
// Retrieve account details by ID
|
|
212
|
+
client.financialAccount.retrieve(financialAccountId: string): Promise<Result<RetrieveFinancialAccountResponse>>
|
|
198
213
|
|
|
199
214
|
// List all financial accounts
|
|
200
|
-
client.financialAccount.
|
|
215
|
+
client.financialAccount.list(): Promise<Result<ListFinancialAccountsResponse>>
|
|
201
216
|
```
|
|
202
217
|
|
|
203
218
|
**Parameters:**
|
|
@@ -207,14 +222,14 @@ client.financialAccount.getAll(): Promise<Result<AllFinancialAccount>>
|
|
|
207
222
|
**Example:**
|
|
208
223
|
```ts
|
|
209
224
|
// Create account
|
|
210
|
-
const account = await client.financialAccount.create("My Wallet");
|
|
225
|
+
const account = await client.financialAccount.create("My Wallet", "SLE");
|
|
211
226
|
if (account.success) {
|
|
212
|
-
console.log("Account ID:", account.data.
|
|
213
|
-
console.log("Balance:", account.data.
|
|
227
|
+
console.log("Account ID:", account.data.id);
|
|
228
|
+
console.log("Balance:", account.data.balance.available.value);
|
|
214
229
|
}
|
|
215
230
|
|
|
216
|
-
//
|
|
217
|
-
const details = await client.financialAccount.
|
|
231
|
+
// Retrieve account details
|
|
232
|
+
const details = await client.financialAccount.retrieve("fa-123456");
|
|
218
233
|
```
|
|
219
234
|
|
|
220
235
|
### Internal Transfers
|
|
@@ -227,16 +242,16 @@ client.internalTransfer.create(
|
|
|
227
242
|
sourceAccount: string,
|
|
228
243
|
destinationAccount: string,
|
|
229
244
|
amount: number,
|
|
230
|
-
): Promise<Result<
|
|
245
|
+
): Promise<Result<CreateInternalTransferResponse>>
|
|
231
246
|
|
|
232
|
-
//
|
|
233
|
-
client.internalTransfer.
|
|
247
|
+
// Retrieve transfer details
|
|
248
|
+
client.internalTransfer.retrieve(internalTransferId: string): Promise<Result<RetrieveInternalTransferResponse>>
|
|
234
249
|
|
|
235
250
|
// List all transfers
|
|
236
|
-
client.internalTransfer.
|
|
251
|
+
client.internalTransfer.list(): Promise<Result<ListInternalTransfersResponse>>
|
|
237
252
|
|
|
238
253
|
// Cancel/delete a transfer
|
|
239
|
-
client.internalTransfer.delete(internalTransferId: string): Promise<
|
|
254
|
+
client.internalTransfer.delete(internalTransferId: string): Promise<Result<void>>
|
|
240
255
|
```
|
|
241
256
|
|
|
242
257
|
**Parameters:**
|
|
@@ -250,8 +265,8 @@ client.internalTransfer.delete(internalTransferId: string): Promise<{ success: b
|
|
|
250
265
|
// Transfer 1000 SLE between accounts
|
|
251
266
|
const transfer = await client.internalTransfer.create("fa-source", "fa-dest", 1000);
|
|
252
267
|
if (transfer.success) {
|
|
253
|
-
console.log("Transfer ID:", transfer.data.
|
|
254
|
-
console.log("Status:", transfer.data.
|
|
268
|
+
console.log("Transfer ID:", transfer.data.id);
|
|
269
|
+
console.log("Status:", transfer.data.status);
|
|
255
270
|
}
|
|
256
271
|
```
|
|
257
272
|
|
|
@@ -264,19 +279,19 @@ Generate USSD payment codes for mobile money transactions.
|
|
|
264
279
|
client.paymentCode.create(
|
|
265
280
|
paymentName: string,
|
|
266
281
|
amount: number,
|
|
267
|
-
|
|
282
|
+
financialAccountId: string,
|
|
268
283
|
username: string,
|
|
269
284
|
phoneNumber: string,
|
|
270
|
-
): Promise<Result<
|
|
285
|
+
): Promise<Result<CreatePaymentCodeResponse>>
|
|
271
286
|
|
|
272
|
-
//
|
|
273
|
-
client.paymentCode.
|
|
287
|
+
// Retrieve payment code details
|
|
288
|
+
client.paymentCode.retrieve(paymentCodeId: string): Promise<Result<RetrievePaymentCodeResponse>>
|
|
274
289
|
|
|
275
290
|
// List all payment codes
|
|
276
|
-
client.paymentCode.
|
|
291
|
+
client.paymentCode.list(): Promise<Result<ListPaymentCodesResponse>>
|
|
277
292
|
|
|
278
293
|
// Delete payment code
|
|
279
|
-
client.paymentCode.delete(paymentCodeId: string): Promise<
|
|
294
|
+
client.paymentCode.delete(paymentCodeId: string): Promise<Result<void>>
|
|
280
295
|
```
|
|
281
296
|
|
|
282
297
|
**Parameters:**
|
|
@@ -299,8 +314,8 @@ const paymentCode = await client.paymentCode.create(
|
|
|
299
314
|
);
|
|
300
315
|
|
|
301
316
|
if (paymentCode.success) {
|
|
302
|
-
console.log("USSD Code:", paymentCode.data.
|
|
303
|
-
console.log("Expires at:", paymentCode.data.
|
|
317
|
+
console.log("USSD Code:", paymentCode.data.ussdCode);
|
|
318
|
+
console.log("Expires at:", paymentCode.data.expireTime);
|
|
304
319
|
}
|
|
305
320
|
```
|
|
306
321
|
|
|
@@ -314,16 +329,16 @@ client.payout.create(
|
|
|
314
329
|
amount: number,
|
|
315
330
|
destination: DestinationOption,
|
|
316
331
|
sourceAccount: string,
|
|
317
|
-
): Promise<Result<
|
|
332
|
+
): Promise<Result<CreatePayoutResponse>>
|
|
318
333
|
|
|
319
334
|
// List all payouts
|
|
320
|
-
client.payout.
|
|
335
|
+
client.payout.list(): Promise<Result<ListPayoutsResponse>>
|
|
321
336
|
|
|
322
|
-
//
|
|
323
|
-
client.payout.
|
|
337
|
+
// Retrieve specific payout
|
|
338
|
+
client.payout.retrieve(payoutId: string): Promise<Result<RetrievePayoutResponse>>
|
|
324
339
|
|
|
325
340
|
// Cancel payout
|
|
326
|
-
client.payout.delete(payoutId: string): Promise<
|
|
341
|
+
client.payout.delete(payoutId: string): Promise<Result<void>>
|
|
327
342
|
```
|
|
328
343
|
|
|
329
344
|
**Destination Types:**
|
|
@@ -362,11 +377,11 @@ const bankPayout = await client.payout.create(
|
|
|
362
377
|
Query transaction history and details.
|
|
363
378
|
|
|
364
379
|
```ts
|
|
365
|
-
//
|
|
366
|
-
client.financialTransaction.
|
|
380
|
+
// Retrieve transaction details
|
|
381
|
+
client.financialTransaction.retrieve(transactionId: string): Promise<Result<RetrieveTransactionResponse>>
|
|
367
382
|
|
|
368
383
|
// List all transactions
|
|
369
|
-
client.financialTransaction.
|
|
384
|
+
client.financialTransaction.list(): Promise<Result<ListTransactionsResponse>>
|
|
370
385
|
```
|
|
371
386
|
|
|
372
387
|
**Parameters:**
|
|
@@ -374,10 +389,10 @@ client.financialTransaction.getAll(): Promise<Result<AllTransaction>>
|
|
|
374
389
|
|
|
375
390
|
**Example:**
|
|
376
391
|
```ts
|
|
377
|
-
//
|
|
378
|
-
const transactions = await client.financialTransaction.
|
|
392
|
+
// List all transactions
|
|
393
|
+
const transactions = await client.financialTransaction.list();
|
|
379
394
|
if (transactions.success) {
|
|
380
|
-
transactions.data.
|
|
395
|
+
transactions.data.forEach(tx => {
|
|
381
396
|
console.log(`${tx.type}: ${tx.amount.value} ${tx.amount.currency}`);
|
|
382
397
|
});
|
|
383
398
|
}
|
|
@@ -395,20 +410,22 @@ client.checkoutSession.create(
|
|
|
395
410
|
quantity: number,
|
|
396
411
|
successUrl: string,
|
|
397
412
|
cancelUrl: string,
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
413
|
+
options?: {
|
|
414
|
+
description?: string,
|
|
415
|
+
financialAccountId?: string,
|
|
416
|
+
primaryColor?: string,
|
|
417
|
+
images?: string[],
|
|
418
|
+
}
|
|
419
|
+
): Promise<Result<CreateCheckoutResponse>>
|
|
403
420
|
|
|
404
421
|
// List all checkout sessions
|
|
405
|
-
client.checkoutSession.
|
|
422
|
+
client.checkoutSession.list(): Promise<Result<ListCheckoutsResponse>>
|
|
406
423
|
|
|
407
|
-
//
|
|
408
|
-
client.checkoutSession.
|
|
424
|
+
// Retrieve specific checkout session
|
|
425
|
+
client.checkoutSession.retrieve(checkoutId: string): Promise<Result<RetrieveCheckoutResponse>>
|
|
409
426
|
|
|
410
427
|
// Delete checkout session
|
|
411
|
-
client.checkoutSession.delete(checkoutId: string): Promise<
|
|
428
|
+
client.checkoutSession.delete(checkoutId: string): Promise<Result<void>>
|
|
412
429
|
```
|
|
413
430
|
|
|
414
431
|
**Parameters:**
|
|
@@ -440,8 +457,8 @@ const checkout = await client.checkoutSession.create(
|
|
|
440
457
|
|
|
441
458
|
if (checkout.success) {
|
|
442
459
|
// Redirect customer to checkout page
|
|
443
|
-
console.log("Checkout URL:", checkout.data.
|
|
444
|
-
console.log("Order Number:", checkout.data.
|
|
460
|
+
console.log("Checkout URL:", checkout.data.redirectUrl);
|
|
461
|
+
console.log("Order Number:", checkout.data.orderNumber);
|
|
445
462
|
}
|
|
446
463
|
```
|
|
447
464
|
|
|
@@ -464,6 +481,36 @@ type ClientOptions = {
|
|
|
464
481
|
|
|
465
482
|
---
|
|
466
483
|
|
|
484
|
+
## Development & Build
|
|
485
|
+
|
|
486
|
+
This package uses modern tooling for development and building:
|
|
487
|
+
|
|
488
|
+
### Build System
|
|
489
|
+
- **tsup** for fast TypeScript compilation with dual CJS/ESM output
|
|
490
|
+
- **Biome** for code formatting and linting
|
|
491
|
+
- **Vitest** for testing framework
|
|
492
|
+
|
|
493
|
+
### Available Scripts
|
|
494
|
+
```bash
|
|
495
|
+
# Build the package
|
|
496
|
+
pnpm build
|
|
497
|
+
|
|
498
|
+
# Run tests
|
|
499
|
+
pnpm test
|
|
500
|
+
|
|
501
|
+
# Format and lint code
|
|
502
|
+
pnpm lint-format
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Project Structure
|
|
506
|
+
The package is organized for maximum simplicity:
|
|
507
|
+
- **`src/resources/`**: All API resource implementations (e.g., `payment.ts`, `payout.ts`)
|
|
508
|
+
- **`src/types/`**: Consolidated TypeScript interface definitions
|
|
509
|
+
- **`src/client.ts`**: The main `MonimeClient` entry point
|
|
510
|
+
- **`src/http.ts`**: Shared native `fetch` logic and telemetry
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
467
514
|
## Complete Examples
|
|
468
515
|
|
|
469
516
|
Here are comprehensive examples showing real-world usage patterns:
|
|
@@ -480,14 +527,14 @@ const client = createClient({
|
|
|
480
527
|
});
|
|
481
528
|
|
|
482
529
|
// Create business account
|
|
483
|
-
const businessAccount = await client.financialAccount.create("E-commerce Store");
|
|
530
|
+
const businessAccount = await client.financialAccount.create("E-commerce Store", "SLE");
|
|
484
531
|
if (!businessAccount.success) {
|
|
485
532
|
throw new Error(`Failed to create account: ${businessAccount.error?.message}`);
|
|
486
533
|
}
|
|
487
534
|
|
|
488
|
-
const accountId = businessAccount.data!.
|
|
535
|
+
const accountId = businessAccount.data!.id;
|
|
489
536
|
console.log(`Created account: ${accountId}`);
|
|
490
|
-
console.log(`Balance: ${businessAccount.data!.
|
|
537
|
+
console.log(`Balance: ${businessAccount.data!.balance.available.value} SLE`);
|
|
491
538
|
|
|
492
539
|
// Create checkout session for customer
|
|
493
540
|
const checkout = await client.checkoutSession.create(
|
|
@@ -496,16 +543,18 @@ const checkout = await client.checkoutSession.create(
|
|
|
496
543
|
1,
|
|
497
544
|
"https://store.com/success",
|
|
498
545
|
"https://store.com/cancel",
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
546
|
+
{
|
|
547
|
+
description: "Professional DSLR Camera with lens kit",
|
|
548
|
+
financialAccountId: accountId,
|
|
549
|
+
primaryColor: "#2563EB", // Brand blue
|
|
550
|
+
images: ["https://store.com/camera.jpg"]
|
|
551
|
+
}
|
|
503
552
|
);
|
|
504
553
|
|
|
505
554
|
if (checkout.success) {
|
|
506
|
-
console.log(`Checkout created: ${checkout.data!.
|
|
507
|
-
console.log(`Payment URL: ${checkout.data!.
|
|
508
|
-
console.log(`Order: ${checkout.data!.
|
|
555
|
+
console.log(`Checkout created: ${checkout.data!.id}`);
|
|
556
|
+
console.log(`Payment URL: ${checkout.data!.redirectUrl}`);
|
|
557
|
+
console.log(`Order: ${checkout.data!.orderNumber}`);
|
|
509
558
|
}
|
|
510
559
|
```
|
|
511
560
|
|
|
@@ -522,19 +571,19 @@ const paymentCode = await client.paymentCode.create(
|
|
|
522
571
|
);
|
|
523
572
|
|
|
524
573
|
if (paymentCode.success) {
|
|
525
|
-
console.log(`USSD Code: ${paymentCode.data!.
|
|
526
|
-
console.log(`Expires: ${paymentCode.data!.
|
|
574
|
+
console.log(`USSD Code: ${paymentCode.data!.ussdCode}`);
|
|
575
|
+
console.log(`Expires: ${paymentCode.data!.expireTime}`);
|
|
527
576
|
|
|
528
577
|
// Send USSD code to customer via SMS/email
|
|
529
|
-
await sendToCustomer(paymentCode.data!.
|
|
578
|
+
await sendToCustomer(paymentCode.data!.ussdCode);
|
|
530
579
|
}
|
|
531
580
|
|
|
532
581
|
// 2. Monitor payment status
|
|
533
582
|
const checkPaymentStatus = async (codeId: string) => {
|
|
534
|
-
const status = await client.paymentCode.
|
|
583
|
+
const status = await client.paymentCode.retrieve(codeId);
|
|
535
584
|
if (status.success) {
|
|
536
|
-
console.log(`Payment Status: ${status.data!.
|
|
537
|
-
return status.data!.
|
|
585
|
+
console.log(`Payment Status: ${status.data!.status}`);
|
|
586
|
+
return status.data!.status === 'completed';
|
|
538
587
|
}
|
|
539
588
|
return false;
|
|
540
589
|
};
|
|
@@ -552,9 +601,9 @@ const paySupplier = async () => {
|
|
|
552
601
|
);
|
|
553
602
|
|
|
554
603
|
if (payout.success) {
|
|
555
|
-
console.log(`Payout ID: ${payout.data!.
|
|
556
|
-
console.log(`Status: ${payout.data!.
|
|
557
|
-
console.log(`Fees: ${payout.data!.
|
|
604
|
+
console.log(`Payout ID: ${payout.data!.id}`);
|
|
605
|
+
console.log(`Status: ${payout.data!.status}`);
|
|
606
|
+
console.log(`Fees: ${payout.data!.fees.map(f => `${f.code}: ${f.amount.value}`)}`);
|
|
558
607
|
}
|
|
559
608
|
};
|
|
560
609
|
```
|
|
@@ -564,14 +613,14 @@ const paySupplier = async () => {
|
|
|
564
613
|
```ts
|
|
565
614
|
// Create multiple accounts for different purposes
|
|
566
615
|
const accounts = await Promise.all([
|
|
567
|
-
client.financialAccount.create("Sales Revenue"),
|
|
568
|
-
client.financialAccount.create("Operating Expenses"),
|
|
569
|
-
client.financialAccount.create("Tax Reserve"),
|
|
616
|
+
client.financialAccount.create("Sales Revenue", "SLE"),
|
|
617
|
+
client.financialAccount.create("Operating Expenses", "SLE"),
|
|
618
|
+
client.financialAccount.create("Tax Reserve", "SLE"),
|
|
570
619
|
]);
|
|
571
620
|
|
|
572
621
|
// Check if all accounts were created successfully
|
|
573
622
|
if (accounts.every(acc => acc.success)) {
|
|
574
|
-
const [salesAccount, expensesAccount, taxAccount] = accounts.map(acc => acc.data!.
|
|
623
|
+
const [salesAccount, expensesAccount, taxAccount] = accounts.map(acc => acc.data!.id);
|
|
575
624
|
|
|
576
625
|
// Distribute revenue: 70% operations, 30% tax reserve
|
|
577
626
|
const revenue = 100000; // 1000.00 SLE
|
|
@@ -584,7 +633,7 @@ if (accounts.every(acc => acc.success)) {
|
|
|
584
633
|
transfers.forEach((transfer, index) => {
|
|
585
634
|
const purpose = index === 0 ? 'operations' : 'tax reserve';
|
|
586
635
|
if (transfer.success) {
|
|
587
|
-
console.log(`${purpose} transfer: ${transfer.data!.
|
|
636
|
+
console.log(`${purpose} transfer: ${transfer.data!.id}`);
|
|
588
637
|
}
|
|
589
638
|
});
|
|
590
639
|
}
|
|
@@ -593,8 +642,8 @@ if (accounts.every(acc => acc.success)) {
|
|
|
593
642
|
### Transaction Monitoring & Reporting
|
|
594
643
|
|
|
595
644
|
```ts
|
|
596
|
-
//
|
|
597
|
-
const transactions = await client.financialTransaction.
|
|
645
|
+
// List all transactions for reporting
|
|
646
|
+
const transactions = await client.financialTransaction.list();
|
|
598
647
|
|
|
599
648
|
if (transactions.success) {
|
|
600
649
|
const txs = transactions.data!.result;
|
|
@@ -615,9 +664,9 @@ if (transactions.success) {
|
|
|
615
664
|
const accountIds = [...new Set(txs.map(tx => tx.financialAccount.id))];
|
|
616
665
|
|
|
617
666
|
for (const accountId of accountIds) {
|
|
618
|
-
const account = await client.financialAccount.
|
|
667
|
+
const account = await client.financialAccount.retrieve(accountId);
|
|
619
668
|
if (account.success) {
|
|
620
|
-
console.log(`Account ${accountId}: ${account.data!.
|
|
669
|
+
console.log(`Account ${accountId}: ${account.data!.balance.available.value} SLE`);
|
|
621
670
|
}
|
|
622
671
|
}
|
|
623
672
|
}
|
|
@@ -660,7 +709,7 @@ const createTransferWithRetry = async (
|
|
|
660
709
|
// Usage
|
|
661
710
|
try {
|
|
662
711
|
const transfer = await createTransferWithRetry("fa-source", "fa-dest", 10000);
|
|
663
|
-
console.log("Transfer successful:", transfer.data!.
|
|
712
|
+
console.log("Transfer successful:", transfer.data!.id);
|
|
664
713
|
} catch (error) {
|
|
665
714
|
console.error("Transfer failed permanently:", error.message);
|
|
666
715
|
}
|
|
@@ -702,8 +751,11 @@ await client.financialAccount.create("name");
|
|
|
702
751
|
## Error Handling
|
|
703
752
|
|
|
704
753
|
- **Standard envelope**: every call returns `{ success, data?, error? }`.
|
|
705
|
-
- **Validation**: inputs are validated (e.g. non-empty IDs, positive amounts) and will short-circuit with `success: false` + `
|
|
706
|
-
- **
|
|
754
|
+
- **Validation**: inputs are validated (e.g. non-empty IDs, positive amounts) and will short-circuit with `success: false` + `MonimeValidationError`.
|
|
755
|
+
- **MonimeError**: remote errors are returned as `MonimeError` objects, which include:
|
|
756
|
+
- `status`: HTTP status code (e.g. 401, 404)
|
|
757
|
+
- `requestId`: The unique request ID from Monime's servers
|
|
758
|
+
- `details`: Rich error details from the API
|
|
707
759
|
|
|
708
760
|
---
|
|
709
761
|
|
|
@@ -734,35 +786,59 @@ import type {
|
|
|
734
786
|
// Core types
|
|
735
787
|
ClientOptions,
|
|
736
788
|
|
|
789
|
+
// Payment types
|
|
790
|
+
RetrievePaymentResponse,
|
|
791
|
+
ListPaymentsResponse,
|
|
792
|
+
UpdatePaymentResponse,
|
|
793
|
+
|
|
794
|
+
// Webhook types
|
|
795
|
+
CreateWebhookRequest,
|
|
796
|
+
CreateWebhookResponse,
|
|
797
|
+
GetWebhookResponse,
|
|
798
|
+
ListWebhooksResponse,
|
|
799
|
+
UpdateWebhookRequest,
|
|
800
|
+
UpdateWebhookResponse,
|
|
801
|
+
|
|
802
|
+
// Receipt types
|
|
803
|
+
GetReceiptResponse,
|
|
804
|
+
RedeemReceiptResponse,
|
|
805
|
+
|
|
806
|
+
// USSD OTP types
|
|
807
|
+
CreateUssdOtpRequest,
|
|
808
|
+
CreateUssdOtpResponse,
|
|
809
|
+
|
|
810
|
+
// Provider KYC types
|
|
811
|
+
GetProviderKycResponse,
|
|
812
|
+
|
|
737
813
|
// Financial Account types
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
814
|
+
CreateFinancialAccountResponse,
|
|
815
|
+
RetrieveFinancialAccountResponse,
|
|
816
|
+
ListFinancialAccountsResponse,
|
|
741
817
|
|
|
742
818
|
// Internal Transfer types
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
819
|
+
CreateInternalTransferResponse,
|
|
820
|
+
RetrieveInternalTransferResponse,
|
|
821
|
+
ListInternalTransfersResponse,
|
|
746
822
|
|
|
747
823
|
// Payment Code types
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
824
|
+
CreatePaymentCodeResponse,
|
|
825
|
+
ListPaymentCodesResponse,
|
|
826
|
+
RetrievePaymentCodeResponse,
|
|
751
827
|
|
|
752
828
|
// Payout types
|
|
753
829
|
DestinationOption,
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
830
|
+
CreatePayoutResponse,
|
|
831
|
+
ListPayoutsResponse,
|
|
832
|
+
RetrievePayoutResponse,
|
|
757
833
|
|
|
758
834
|
// Financial Transaction types
|
|
759
|
-
|
|
760
|
-
|
|
835
|
+
RetrieveTransactionResponse,
|
|
836
|
+
ListTransactionsResponse,
|
|
761
837
|
|
|
762
838
|
// Checkout Session types
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
839
|
+
CreateCheckoutResponse,
|
|
840
|
+
ListCheckoutsResponse,
|
|
841
|
+
RetrieveCheckoutResponse,
|
|
766
842
|
} from "monime-package";
|
|
767
843
|
```
|
|
768
844
|
|
|
@@ -774,7 +850,7 @@ All API responses follow this consistent pattern:
|
|
|
774
850
|
type Result<T> = {
|
|
775
851
|
success: boolean;
|
|
776
852
|
data?: T;
|
|
777
|
-
error?: Error;
|
|
853
|
+
error?: Error | MonimeError;
|
|
778
854
|
};
|
|
779
855
|
```
|
|
780
856
|
|
|
@@ -812,146 +888,130 @@ type DestinationOption =
|
|
|
812
888
|
```ts
|
|
813
889
|
// Account creation/retrieval response
|
|
814
890
|
interface CreateFinancialAccount {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
available: {
|
|
826
|
-
currency: string;
|
|
827
|
-
value: number; // Balance in cents (SLE)
|
|
828
|
-
};
|
|
891
|
+
id: string; // Unique account ID
|
|
892
|
+
uvan: string; // Internal identifier
|
|
893
|
+
name: string; // Account name
|
|
894
|
+
currency: string; // Always "SLE"
|
|
895
|
+
reference: string; // Account reference
|
|
896
|
+
description: string; // Account description
|
|
897
|
+
balance: {
|
|
898
|
+
available: {
|
|
899
|
+
currency: string;
|
|
900
|
+
value: number; // Balance in cents (SLE)
|
|
829
901
|
};
|
|
830
|
-
createTime: string; // ISO timestamp
|
|
831
|
-
updateTime: string; // ISO timestamp
|
|
832
902
|
};
|
|
903
|
+
createTime: string; // ISO timestamp
|
|
904
|
+
updateTime: string; // ISO timestamp
|
|
833
905
|
}
|
|
834
906
|
```
|
|
835
907
|
|
|
836
908
|
#### Internal Transfer Types
|
|
837
909
|
```ts
|
|
838
|
-
interface
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
910
|
+
interface CreateInternalTransferResponse {
|
|
911
|
+
id: string; // Transfer ID
|
|
912
|
+
status: string; // Transfer status
|
|
913
|
+
amount: {
|
|
914
|
+
currency: string;
|
|
915
|
+
value: number; // Amount in cents
|
|
916
|
+
};
|
|
917
|
+
sourceFinancialAccount: { id: string };
|
|
918
|
+
destinationFinancialAccount: { id: string };
|
|
919
|
+
financialTransactionReference: string;
|
|
920
|
+
description: string;
|
|
921
|
+
failureDetail: {
|
|
922
|
+
code: string;
|
|
923
|
+
message: string;
|
|
924
|
+
};
|
|
925
|
+
ownershipGraph: {
|
|
926
|
+
owner: {
|
|
927
|
+
id: string;
|
|
928
|
+
type: string;
|
|
857
929
|
owner: {
|
|
858
930
|
id: string;
|
|
859
931
|
type: string;
|
|
860
|
-
owner: {
|
|
861
|
-
id: string;
|
|
862
|
-
type: string;
|
|
863
|
-
};
|
|
864
932
|
};
|
|
865
933
|
};
|
|
866
|
-
createTime: string;
|
|
867
|
-
updateTime: string;
|
|
868
934
|
};
|
|
935
|
+
createTime: string;
|
|
936
|
+
updateTime: string;
|
|
869
937
|
}
|
|
870
938
|
```
|
|
871
939
|
|
|
872
940
|
#### Payment Code Types
|
|
873
941
|
```ts
|
|
874
|
-
interface
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
942
|
+
interface CreatePaymentCodeResponse {
|
|
943
|
+
id: string;
|
|
944
|
+
mode: string; // "recurrent"
|
|
945
|
+
status: string; // Payment status
|
|
946
|
+
name: string; // Payment name
|
|
947
|
+
amount: {
|
|
948
|
+
currency: string;
|
|
949
|
+
value: number; // Amount in cents
|
|
950
|
+
};
|
|
951
|
+
enable: boolean;
|
|
952
|
+
expireTime: string; // ISO timestamp
|
|
953
|
+
customer: { name: string };
|
|
954
|
+
ussdCode: string; // USSD code for payment
|
|
955
|
+
reference: string;
|
|
956
|
+
authorizedProviders: string[];
|
|
957
|
+
authorizedPhoneNumber: string;
|
|
958
|
+
recurrentPaymentTarget: {
|
|
959
|
+
expectedPaymentCount: number;
|
|
960
|
+
expectedPaymentTotal: {
|
|
883
961
|
currency: string;
|
|
884
|
-
value: number;
|
|
885
|
-
};
|
|
886
|
-
enable: boolean;
|
|
887
|
-
expireTime: string; // ISO timestamp
|
|
888
|
-
customer: { name: string };
|
|
889
|
-
ussdCode: string; // USSD code for payment
|
|
890
|
-
reference: string;
|
|
891
|
-
authorizedProviders: string[];
|
|
892
|
-
authorizedPhoneNumber: string;
|
|
893
|
-
recurrentPaymentTarget: {
|
|
894
|
-
expectedPaymentCount: number;
|
|
895
|
-
expectedPaymentTotal: {
|
|
896
|
-
currency: string;
|
|
897
|
-
value: number;
|
|
898
|
-
};
|
|
962
|
+
value: number;
|
|
899
963
|
};
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
financialTransactionReference: string;
|
|
964
|
+
};
|
|
965
|
+
financialAccountId: string;
|
|
966
|
+
processedPaymentData: {
|
|
967
|
+
amount: { currency: string; value: number };
|
|
968
|
+
orderId: string;
|
|
969
|
+
paymentId: string;
|
|
970
|
+
orderNumber: string;
|
|
971
|
+
channelData: {
|
|
972
|
+
providerId: string;
|
|
973
|
+
accountId: string;
|
|
974
|
+
reference: string;
|
|
912
975
|
};
|
|
913
|
-
|
|
914
|
-
updateTime: string;
|
|
915
|
-
ownershipGraph: OwnershipGraph;
|
|
976
|
+
financialTransactionReference: string;
|
|
916
977
|
};
|
|
978
|
+
createTime: string;
|
|
979
|
+
updateTime: string;
|
|
980
|
+
ownershipGraph: OwnershipGraph;
|
|
917
981
|
}
|
|
918
982
|
```
|
|
919
983
|
|
|
920
984
|
#### Checkout Session Types
|
|
921
985
|
```ts
|
|
922
|
-
interface
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
financialAccountId: string;
|
|
948
|
-
brandingOptions: {
|
|
949
|
-
primaryColor: string;
|
|
950
|
-
};
|
|
951
|
-
expireTime: string;
|
|
952
|
-
createTime: string;
|
|
953
|
-
ownershipGraph: OwnershipGraph;
|
|
986
|
+
interface CreateCheckoutResponse {
|
|
987
|
+
id: string;
|
|
988
|
+
status: string;
|
|
989
|
+
name: string;
|
|
990
|
+
orderNumber: string; // Generated order number
|
|
991
|
+
reference: string;
|
|
992
|
+
description: string;
|
|
993
|
+
redirectUrl: string; // Checkout page URL
|
|
994
|
+
cancelUrl: string;
|
|
995
|
+
successUrl: string;
|
|
996
|
+
lineItems: {
|
|
997
|
+
data: Array<{
|
|
998
|
+
type: string;
|
|
999
|
+
id: string;
|
|
1000
|
+
name: string;
|
|
1001
|
+
price: { currency: string; value: number };
|
|
1002
|
+
quantity: number;
|
|
1003
|
+
reference: string;
|
|
1004
|
+
description: string;
|
|
1005
|
+
images: string[];
|
|
1006
|
+
}>;
|
|
1007
|
+
};
|
|
1008
|
+
financialAccountId: string;
|
|
1009
|
+
brandingOptions: {
|
|
1010
|
+
primaryColor: string;
|
|
954
1011
|
};
|
|
1012
|
+
expireTime: string;
|
|
1013
|
+
createTime: string;
|
|
1014
|
+
ownershipGraph: OwnershipGraph;
|
|
955
1015
|
}
|
|
956
1016
|
```
|
|
957
1017
|
|
|
@@ -986,8 +1046,8 @@ interface Amount {
|
|
|
986
1046
|
|
|
987
1047
|
```ts
|
|
988
1048
|
// Type-safe account creation
|
|
989
|
-
const createAccountTyped = async (name: string): Promise<
|
|
990
|
-
const result = await client.financialAccount.create(name);
|
|
1049
|
+
const createAccountTyped = async (name: string): Promise<CreateFinancialAccountResponse | null> => {
|
|
1050
|
+
const result = await client.financialAccount.create(name, "SLE");
|
|
991
1051
|
return result.success ? result.data! : null;
|
|
992
1052
|
};
|
|
993
1053
|
|
|
@@ -996,7 +1056,7 @@ const createMobileMoneyPayout = async (
|
|
|
996
1056
|
amount: number,
|
|
997
1057
|
phoneNumber: string,
|
|
998
1058
|
sourceAccount: string
|
|
999
|
-
): Promise<
|
|
1059
|
+
): Promise<CreatePayoutResponse | null> => {
|
|
1000
1060
|
const destination: DestinationOption = {
|
|
1001
1061
|
type: "momo",
|
|
1002
1062
|
providerId: "m17",
|
|
@@ -1009,12 +1069,12 @@ const createMobileMoneyPayout = async (
|
|
|
1009
1069
|
|
|
1010
1070
|
// Type-safe transaction processing
|
|
1011
1071
|
const processTransactions = async (): Promise<void> => {
|
|
1012
|
-
const txResult = await client.financialTransaction.
|
|
1072
|
+
const txResult = await client.financialTransaction.list();
|
|
1013
1073
|
|
|
1014
1074
|
if (txResult.success && txResult.data) {
|
|
1015
|
-
const transactions:
|
|
1075
|
+
const transactions: ListTransactionsResponse = txResult.data;
|
|
1016
1076
|
|
|
1017
|
-
transactions.result.forEach((tx:
|
|
1077
|
+
transactions.result.forEach((tx: RetrieveTransactionResponse) => {
|
|
1018
1078
|
console.log(`Transaction ${tx.id}: ${tx.amount.value / 100} ${tx.amount.currency}`);
|
|
1019
1079
|
});
|
|
1020
1080
|
}
|
|
@@ -1031,10 +1091,13 @@ We welcome contributions.
|
|
|
1031
1091
|
### Getting Started
|
|
1032
1092
|
1. **Fork the repository** on GitHub
|
|
1033
1093
|
2. **Clone your fork** locally
|
|
1034
|
-
3. **
|
|
1035
|
-
4. **
|
|
1036
|
-
5. **
|
|
1037
|
-
6. **
|
|
1094
|
+
3. **Install dependencies** with `pnpm install`
|
|
1095
|
+
4. **Create a feature branch** from `main`
|
|
1096
|
+
5. **Make your changes** following our coding conventions
|
|
1097
|
+
6. **Run linting** with `pnpm lint-format`
|
|
1098
|
+
7. **Test your changes** with `pnpm test`
|
|
1099
|
+
8. **Build the package** with `pnpm build`
|
|
1100
|
+
9. **Submit a pull request** with a clear description
|
|
1038
1101
|
|
|
1039
1102
|
For detailed contribution guidelines, see [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
1040
1103
|
|