@mbanq/core-sdk-js 1.0.0-alpha.5 → 1.0.0-alpha.7
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 +458 -194
- package/dist/chunk-5PEETHWV.mjs +1 -0
- package/dist/chunk-BDI3SHA2.js +1 -0
- package/dist/chunk-I3DNDGQO.mjs +1 -0
- package/dist/chunk-OGW7GTJP.js +1 -0
- package/dist/chunk-RX3BFHHX.mjs +1 -0
- package/dist/chunk-VLCBT53A.js +1 -0
- package/dist/client/index.d.mts +3 -10
- package/dist/client/index.d.ts +3 -10
- package/dist/client/index.js +1 -1
- package/dist/client/index.mjs +1 -1
- package/dist/commands/index.d.mts +66 -4
- package/dist/commands/index.d.ts +66 -4
- package/dist/commands/index.js +1 -1
- package/dist/commands/index.mjs +1 -1
- package/dist/{config.d-NcOIimSJ.d.mts → config.d-CyK6ZM6s.d.mts} +2 -1
- package/dist/{config.d-NcOIimSJ.d.ts → config.d-CyK6ZM6s.d.ts} +2 -1
- package/dist/{index-B5WvpVzR.d.ts → index-5Sj83ZJ4.d.mts} +2 -64
- package/dist/index-CS61O2LI.d.ts +403 -0
- package/dist/index-DGLz0zv-.d.mts +403 -0
- package/dist/{index-CR5y5AHj.d.mts → index-DXK5OdKW.d.ts} +2 -64
- package/dist/index.d.mts +43 -5
- package/dist/index.d.ts +43 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
- package/dist/chunk-4TZWTPAO.mjs +0 -1
- package/dist/chunk-E4GWSVC5.js +0 -1
- package/dist/chunk-XGUW3EAC.js +0 -1
- package/dist/chunk-XOV45AFR.js +0 -1
- package/dist/chunk-YPDJGVWM.mjs +0 -1
- package/dist/chunk-ZC5XVPET.mjs +0 -1
package/README.md
CHANGED
|
@@ -1,47 +1,195 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://avatars.githubusercontent.com/u/26124358?s=200&v=4" alt="Mbanq Logo" width="120"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# Core SDK JS
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
[](https://www.npmjs.com/package/@mbanq/core-sdk-js)
|
|
9
|
+

|
|
10
|
+
|
|
2
11
|
## Table of Contents
|
|
3
12
|
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- #### Custom Update
|
|
24
|
-
- ### Error Handling
|
|
25
|
-
- ### Examples
|
|
13
|
+
- [Introduction](#introduction)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick Start](#quick-start)
|
|
16
|
+
- [Setup](#setup)
|
|
17
|
+
- [Axios Instance Logger](#axios-instance-logger)
|
|
18
|
+
- [Middleware](#middleware)
|
|
19
|
+
- [Logging Middleware](#logging-middleware)
|
|
20
|
+
- [Metrics Middleware](#metrics-middleware)
|
|
21
|
+
- [Custom Middleware](#custom-middleware)
|
|
22
|
+
- [API Reference](#api-reference)
|
|
23
|
+
- [Payment Operations](#payment-operations)
|
|
24
|
+
- [Create Payment](#create-payment)
|
|
25
|
+
- [Get Payment](#get-payment)
|
|
26
|
+
- [Update Payment](#update-payment)
|
|
27
|
+
- [List Payments](#list-payments)
|
|
28
|
+
- [Multi-Tenant Support](#multi-tenant-support)
|
|
29
|
+
- [Type Safety & Validation](#type-safety--validation)
|
|
30
|
+
- [Error Handling](#error-handling)
|
|
31
|
+
- [Examples](#examples)
|
|
26
32
|
|
|
27
33
|
## Introduction
|
|
28
|
-
This library provides a
|
|
34
|
+
This library provides a comprehensive JavaScript SDK for interacting with the Mbanq payment API. It offers type-safe payment operations with built-in validation, multi-tenant support, and a modern fluent API design.
|
|
29
35
|
## Installation
|
|
30
36
|
|
|
31
37
|
```bash
|
|
32
38
|
npm install @mbanq/core-sdk-js
|
|
33
39
|
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { createClient } from '@mbanq/core-sdk-js';
|
|
45
|
+
|
|
46
|
+
// Initialize the client
|
|
47
|
+
const apiClient = createClient({
|
|
48
|
+
secret: 'your-api-secret',
|
|
49
|
+
signee: 'YOUR-SIGNEE',
|
|
50
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
51
|
+
tenantId: 'your-tenant-id'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Create a payment
|
|
55
|
+
const payment = await apiClient.payment.create({
|
|
56
|
+
amount: 1000,
|
|
57
|
+
currency: 'USD',
|
|
58
|
+
paymentRail: 'ACH',
|
|
59
|
+
paymentType: 'CREDIT',
|
|
60
|
+
debtor: {
|
|
61
|
+
name: 'John Sender',
|
|
62
|
+
identifier: '123456789',
|
|
63
|
+
agent: {
|
|
64
|
+
name: 'First Bank',
|
|
65
|
+
identifier: '021000021'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
creditor: {
|
|
69
|
+
name: 'Jane Receiver',
|
|
70
|
+
identifier: '987654321',
|
|
71
|
+
agent: {
|
|
72
|
+
name: 'Second Bank',
|
|
73
|
+
identifier: '121000248'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// List payments with filtering
|
|
79
|
+
const payments = await apiClient.payment.list()
|
|
80
|
+
.where('status').eq('DRAFT')
|
|
81
|
+
.where('paymentRail').eq('ACH')
|
|
82
|
+
.limit(10)
|
|
83
|
+
.execute();
|
|
84
|
+
```
|
|
85
|
+
|
|
34
86
|
## Setup
|
|
35
|
-
|
|
87
|
+
|
|
88
|
+
### Authentication Options
|
|
89
|
+
|
|
90
|
+
The SDK supports multiple authentication methods. Choose the one that fits your integration:
|
|
91
|
+
|
|
92
|
+
#### 1. JWT Token Authentication (Recommended)
|
|
93
|
+
Use your API secret and signee for JWT-based authentication:
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
const client = createClient({
|
|
97
|
+
secret: 'your-jwt-secret',
|
|
98
|
+
signee: 'YOUR-SIGNEE',
|
|
99
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
100
|
+
tenantId: 'your-tenant-id'
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 2. Bearer Token Authentication
|
|
105
|
+
If you already have a valid access token:
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
// With "Bearer " prefix (recommended)
|
|
109
|
+
const client = createClient({
|
|
110
|
+
bearerToken: 'Bearer your-access-token',
|
|
111
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
112
|
+
tenantId: 'your-tenant-id'
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Without "Bearer " prefix (automatically added)
|
|
116
|
+
const client = createClient({
|
|
117
|
+
bearerToken: 'your-access-token', // "Bearer " will be added automatically
|
|
118
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
119
|
+
tenantId: 'your-tenant-id'
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### 3. OAuth Credential Authentication
|
|
124
|
+
For OAuth 2.0 password grant flow:
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
const client = createClient({
|
|
128
|
+
credential: {
|
|
129
|
+
client_id: 'your-client-id',
|
|
130
|
+
client_secret: 'your-client-secret',
|
|
131
|
+
username: 'your-username',
|
|
132
|
+
password: 'your-password',
|
|
133
|
+
grant_type: 'password'
|
|
134
|
+
},
|
|
135
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
136
|
+
tenantId: 'your-tenant-id'
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Authentication Priority
|
|
141
|
+
When multiple authentication methods are provided, the SDK uses them in this order:
|
|
142
|
+
1. **`bearerToken`** - Takes highest priority if provided
|
|
143
|
+
2. **`credential`** - OAuth flow is used if no bearerToken
|
|
144
|
+
3. **`secret` + `signee`** - JWT authentication used as fallback
|
|
145
|
+
|
|
146
|
+
#### Additional Configuration Options
|
|
147
|
+
```javascript
|
|
148
|
+
const client = createClient({
|
|
149
|
+
// Choose one authentication method from above
|
|
150
|
+
secret: 'your-jwt-secret',
|
|
151
|
+
signee: 'YOUR-SIGNEE',
|
|
152
|
+
|
|
153
|
+
// Required configuration
|
|
154
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
155
|
+
tenantId: 'your-tenant-id',
|
|
156
|
+
|
|
157
|
+
// Optional configuration
|
|
158
|
+
traceId: 'custom-trace-id', // Custom request tracing identifier
|
|
159
|
+
axiosConfig: {
|
|
160
|
+
timeout: 30000, // Request timeout in milliseconds (default: 29000)
|
|
161
|
+
keepAlive: true, // HTTP keep-alive for connection reuse
|
|
162
|
+
headers: {
|
|
163
|
+
'Custom-Header': 'custom-value' // Additional HTTP headers
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Security Best Practices
|
|
170
|
+
|
|
171
|
+
#### Credential Management
|
|
172
|
+
- **Never hardcode credentials** in your source code
|
|
173
|
+
- Use environment variables or secure credential management systems
|
|
174
|
+
- Rotate API secrets and tokens regularly
|
|
175
|
+
- Use the minimum required permissions for your integration
|
|
176
|
+
|
|
177
|
+
#### Environment Variables Example
|
|
36
178
|
```javascript
|
|
37
|
-
const
|
|
38
|
-
secret:
|
|
39
|
-
signee:
|
|
40
|
-
baseUrl:
|
|
41
|
-
tenantId:
|
|
179
|
+
const client = createClient({
|
|
180
|
+
secret: process.env.MBANQ_API_SECRET,
|
|
181
|
+
signee: process.env.MBANQ_API_SIGNEE,
|
|
182
|
+
baseUrl: process.env.MBANQ_API_URL,
|
|
183
|
+
tenantId: process.env.MBANQ_TENANT_ID
|
|
42
184
|
});
|
|
43
185
|
```
|
|
44
186
|
|
|
187
|
+
#### Production Considerations
|
|
188
|
+
- Use HTTPS endpoints only (`https://`)
|
|
189
|
+
- Implement proper error handling to avoid credential leakage in logs
|
|
190
|
+
- Configure appropriate request timeouts
|
|
191
|
+
- Use connection pooling for high-volume applications
|
|
192
|
+
|
|
45
193
|
### Axios Instance Logger
|
|
46
194
|
You can also configure an Axios instance logger to set up interceptors or other axios-specific configurations:
|
|
47
195
|
|
|
@@ -192,212 +340,328 @@ const client = createClient({
|
|
|
192
340
|
```
|
|
193
341
|
|
|
194
342
|
## API Reference
|
|
195
|
-
### Transfer Operations
|
|
196
|
-
### `GetTransfers(options)`
|
|
197
343
|
|
|
198
|
-
|
|
199
|
-
#### Parameters:
|
|
344
|
+
### Payment Operations
|
|
200
345
|
|
|
201
|
-
|
|
202
|
-
- `transferStatus` (String, optional): Filter by transfer status
|
|
203
|
-
- `executedAt` (Date): Filter executed transfers from this date
|
|
204
|
-
- `queryLimit` (Date, optional): Number of results per page
|
|
205
|
-
- `paymentType` (String): Filter by paymentType
|
|
206
|
-
- `tenantId` (String, optional): Set tenant ID
|
|
346
|
+
#### Create Payment
|
|
207
347
|
|
|
208
|
-
|
|
348
|
+
Creates a new payment with comprehensive validation.
|
|
209
349
|
|
|
210
|
-
- Promise`<Array>` of transfer objects
|
|
211
|
-
|
|
212
|
-
#### Example:
|
|
213
350
|
```javascript
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
351
|
+
const payment = await apiClient.payment.create({
|
|
352
|
+
// Required fields
|
|
353
|
+
amount: 1000,
|
|
354
|
+
currency: 'USD',
|
|
355
|
+
paymentRail: 'ACH', // ACH, WIRE, SWIFT, INTERNAL, FXPAY, CARD
|
|
356
|
+
paymentType: 'CREDIT', // CREDIT or DEBIT
|
|
357
|
+
|
|
358
|
+
// Originator (sender)
|
|
359
|
+
debtor: {
|
|
360
|
+
name: 'John Sender',
|
|
361
|
+
identifier: '123456789', // Account number
|
|
362
|
+
accountType: 'CHECKING', // Optional: CHECKING or SAVINGS
|
|
363
|
+
agent: {
|
|
364
|
+
name: 'First Bank',
|
|
365
|
+
identifier: '021000021' // Routing code
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
// Recipient (receiver)
|
|
370
|
+
creditor: {
|
|
371
|
+
name: 'Jane Receiver',
|
|
372
|
+
identifier: '987654321',
|
|
373
|
+
accountType: 'SAVINGS',
|
|
374
|
+
address: { // Required for WIRE transfers
|
|
375
|
+
streetAddress: '123 Main St',
|
|
376
|
+
city: 'New York',
|
|
377
|
+
state: 'NY',
|
|
378
|
+
country: 'US',
|
|
379
|
+
postalCode: '10001'
|
|
380
|
+
},
|
|
381
|
+
agent: {
|
|
382
|
+
name: 'Second Bank',
|
|
383
|
+
identifier: '121000248'
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
// Optional fields
|
|
388
|
+
clientId: 'client-123',
|
|
389
|
+
reference: ['Invoice-001', 'Payment-ABC'],
|
|
390
|
+
exchangeRate: 1.25,
|
|
391
|
+
chargeBearer: 'OUR', // For SWIFT: OUR, BEN, SHA
|
|
392
|
+
valueDate: '2025-01-15',
|
|
393
|
+
paymentRailMetaData: {
|
|
394
|
+
priority: 'high',
|
|
395
|
+
category: 'business'
|
|
396
|
+
}
|
|
397
|
+
}).execute();
|
|
222
398
|
```
|
|
223
|
-
### `LogFailTransfer(params)`
|
|
224
399
|
|
|
225
|
-
|
|
226
|
-
#### Parameters:
|
|
227
|
-
- `params (Object)`
|
|
228
|
-
- `payload` (Transfer): The payload of transfer
|
|
229
|
-
- `tanantId` (String): tenant ID
|
|
400
|
+
#### Get Payment
|
|
230
401
|
|
|
231
|
-
|
|
402
|
+
Retrieves a specific payment by ID.
|
|
232
403
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
Marks a transfer as failed.
|
|
238
|
-
#### Parameters:
|
|
239
|
-
|
|
240
|
-
- `options`
|
|
241
|
-
- `externalId`: (String)
|
|
242
|
-
- `paymentType`: (String, optional)
|
|
243
|
-
- `tenantId`: (String, optional)
|
|
244
|
-
|
|
245
|
-
#### Returns:
|
|
246
|
-
|
|
247
|
-
- Promise`<Object>`
|
|
248
|
-
- `id`: (string)
|
|
249
|
-
- `clientId`: (number)
|
|
250
|
-
- `resourceId`: (number)
|
|
251
|
-
- `resourceIdentifier`: (string)
|
|
252
|
-
|
|
253
|
-
### `MarkAsProcessing(options)`
|
|
404
|
+
```javascript
|
|
405
|
+
const payment = await apiClient.payment.get('payment-456').execute();
|
|
406
|
+
```
|
|
254
407
|
|
|
255
|
-
|
|
256
|
-
#### Parameters:
|
|
408
|
+
#### Update Payment
|
|
257
409
|
|
|
258
|
-
|
|
259
|
-
- `externalId`: (string)
|
|
260
|
-
- `fileUrl`: (string)
|
|
261
|
-
- `paymentType`: (string)
|
|
262
|
-
- `traceNumbers`: (Object)
|
|
263
|
-
- `outgoingTransfer`: (string)
|
|
264
|
-
- `tenantId`: (string, optional)
|
|
410
|
+
Updates an existing payment. All fields are optional.
|
|
265
411
|
|
|
266
|
-
|
|
412
|
+
```javascript
|
|
413
|
+
const updatedPayment = await apiClient.payment.update('payment-456', {
|
|
414
|
+
amount: 1500,
|
|
415
|
+
status: 'EXECUTION_SCHEDULED',
|
|
416
|
+
creditor: {
|
|
417
|
+
name: 'Updated Recipient Name'
|
|
418
|
+
},
|
|
419
|
+
errorCode: 'E001',
|
|
420
|
+
errorMessage: 'Insufficient funds',
|
|
421
|
+
exchangeRate: 1.30,
|
|
422
|
+
reference: ['Updated-Reference'],
|
|
423
|
+
paymentRailMetaData: {
|
|
424
|
+
updated: true
|
|
425
|
+
}
|
|
426
|
+
}).execute();
|
|
427
|
+
```
|
|
267
428
|
|
|
268
|
-
|
|
269
|
-
- `id`: (string)
|
|
270
|
-
- `clientId`: (number)
|
|
271
|
-
- `resourceId`: (number)
|
|
272
|
-
- `resourceIdentifier`: (string)
|
|
429
|
+
#### List Payments
|
|
273
430
|
|
|
274
|
-
|
|
431
|
+
Retrieves payments with powerful filtering capabilities.
|
|
275
432
|
|
|
276
|
-
|
|
277
|
-
|
|
433
|
+
```javascript
|
|
434
|
+
// Simple list
|
|
435
|
+
const payments = await apiClient.payment.list().execute();
|
|
436
|
+
|
|
437
|
+
// With filters and pagination
|
|
438
|
+
const payments = await apiClient.payment.list()
|
|
439
|
+
.where('status').eq('DRAFT')
|
|
440
|
+
.where('paymentRail').eq('ACH')
|
|
441
|
+
.where('paymentType').eq('CREDIT')
|
|
442
|
+
.where('originatorName').eq('John Doe')
|
|
443
|
+
.limit(50)
|
|
444
|
+
.offset(0)
|
|
445
|
+
.execute();
|
|
446
|
+
|
|
447
|
+
// Available filter fields
|
|
448
|
+
// originatorName, originatorAccount, originatorBankRoutingCode
|
|
449
|
+
// recipientName, recipientAccount, recipientBankRoutingCode
|
|
450
|
+
// reference, traceNumber, externalId, clientId
|
|
451
|
+
// dateFormat, locale, originatedBy, paymentRail, paymentType
|
|
452
|
+
// fromValueDate, toValueDate, fromExecuteDate, toExecuteDate
|
|
453
|
+
// status, fromReturnDate, toReturnDate, isSettlement, orderBy, sortOrder
|
|
454
|
+
```
|
|
278
455
|
|
|
279
|
-
-
|
|
280
|
-
- `paymentType`: (string)
|
|
281
|
-
- `externalId`: (string)
|
|
282
|
-
- `returnFileUrl`: (string)
|
|
283
|
-
- `errorCode`: (string)
|
|
284
|
-
- `errorMessage`: (string)
|
|
285
|
-
- `returnDate`: (Date, optional)
|
|
286
|
-
- `traceNumbers`: (Object)
|
|
287
|
-
- `incomingReturnFile`?: (string, optional)
|
|
288
|
-
- `outgoingReturnFile`: (string, optional)
|
|
289
|
-
- `rawReturnDetails`: (any, optional)
|
|
290
|
-
- `tenantId`: (string, optional)
|
|
456
|
+
### Multi-Tenant Support
|
|
291
457
|
|
|
292
|
-
|
|
458
|
+
The SDK supports multi-tenant operations through tenant context.
|
|
293
459
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
- `clientId`: (number)
|
|
297
|
-
- `resourceId`: (number)
|
|
298
|
-
- `resourceIdentifier`: (string)
|
|
460
|
+
#### Default Tenant Operations
|
|
461
|
+
Uses the `tenantId` from client configuration:
|
|
299
462
|
|
|
300
|
-
|
|
301
|
-
|
|
463
|
+
```javascript
|
|
464
|
+
const payment = await apiClient.payment.create(paymentData).execute();
|
|
465
|
+
const payments = await apiClient.payment.list().execute();
|
|
466
|
+
```
|
|
302
467
|
|
|
303
|
-
|
|
468
|
+
#### Tenant-Specific Operations
|
|
469
|
+
Override tenant for specific operations:
|
|
304
470
|
|
|
305
|
-
|
|
471
|
+
```javascript
|
|
472
|
+
// Create payment for specific tenant
|
|
473
|
+
const payment = await apiClient.tenant('tenant-123').payment.create(paymentData).execute();
|
|
306
474
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
- `url` (String): The url that use to request to get something but not include baseURL
|
|
310
|
-
- `tenantId` (String, optional): Set tenant ID
|
|
475
|
+
// Get payment from specific tenant
|
|
476
|
+
const payment = await apiClient.tenant('tenant-123').payment.get('payment-456').execute();
|
|
311
477
|
|
|
312
|
-
|
|
478
|
+
// Update payment in specific tenant
|
|
479
|
+
await apiClient.tenant('tenant-123').payment.update('payment-456', updateData).execute();
|
|
313
480
|
|
|
314
|
-
|
|
481
|
+
// List payments from specific tenant with filters
|
|
482
|
+
const payments = await apiClient.tenant('tenant-123').payment.list()
|
|
483
|
+
.where('status').eq('DRAFT')
|
|
484
|
+
.limit(10)
|
|
485
|
+
.execute();
|
|
486
|
+
```
|
|
315
487
|
|
|
316
|
-
|
|
488
|
+
## Type Safety & Validation
|
|
317
489
|
|
|
318
|
-
|
|
490
|
+
The SDK uses [Zod](https://zod.dev/) for runtime type validation and TypeScript for compile-time type safety.
|
|
319
491
|
|
|
320
|
-
|
|
492
|
+
### Supported Payment Rails
|
|
493
|
+
- `ACH` - Automated Clearing House
|
|
494
|
+
- `SAMEDAYACH` - Same Day ACH
|
|
495
|
+
- `WIRE` - Domestic Wire Transfer
|
|
496
|
+
- `SWIFT` - International Wire Transfer
|
|
497
|
+
- `INTERNAL` - Internal Transfer
|
|
498
|
+
- `FXPAY` - Foreign Exchange Payment
|
|
499
|
+
- `CARD` - Card Payment
|
|
321
500
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
- `tenantId` (String, optional): Set tenant ID
|
|
501
|
+
### Payment Statuses
|
|
502
|
+
- `DRAFT`, `AML_SCREENING`, `AML_REJECTED`
|
|
503
|
+
- `EXECUTION_SCHEDULED`, `EXECUTION_PROCESSING`, `EXECUTION_SUCCESS`, `EXECUTION_FAILURE`
|
|
504
|
+
- `RETURNED`, `CANCELLED`, `COMPLIANCE_FAILURE`, `DELETED`, `UNKNOWN`
|
|
327
505
|
|
|
328
|
-
|
|
506
|
+
### Validation Features
|
|
507
|
+
- **Input Validation**: All create/update operations validate data structure
|
|
508
|
+
- **Response Validation**: API responses are validated before returning
|
|
509
|
+
- **Custom Rules**: WIRE transfers require recipient address with state/country
|
|
510
|
+
- **Type Safety**: Full TypeScript support with inferred types
|
|
329
511
|
|
|
330
|
-
|
|
512
|
+
## Error Handling
|
|
513
|
+
The library uses a consistent error handling pattern. All API calls may throw the following errors:
|
|
331
514
|
|
|
332
|
-
###
|
|
515
|
+
### Error Types
|
|
516
|
+
- **`CommandError`**: Base error type with `code`, `message`, `statusCode`, and optional `requestId`
|
|
517
|
+
- **Authentication Errors**: Invalid or missing API credentials
|
|
518
|
+
- Invalid JWT secret/signee combination
|
|
519
|
+
- Expired or invalid bearer token
|
|
520
|
+
- OAuth credential authentication failure
|
|
521
|
+
- **Validation Errors**: Invalid parameters provided (uses Zod validation)
|
|
522
|
+
- **API Errors**: Server-side errors with specific error codes
|
|
523
|
+
- **Network Errors**: Network connectivity or timeout issues
|
|
524
|
+
|
|
525
|
+
### Common Authentication Error Scenarios
|
|
526
|
+
- **Missing credentials**: No authentication method provided
|
|
527
|
+
- **Invalid JWT**: Incorrect secret or signee values
|
|
528
|
+
- **Expired token**: Bearer token has expired and needs refresh
|
|
529
|
+
- **OAuth failure**: Invalid username/password or client credentials
|
|
333
530
|
|
|
334
|
-
|
|
531
|
+
## Examples
|
|
335
532
|
|
|
336
|
-
|
|
533
|
+
### Complete Payment Flow Example
|
|
337
534
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
- `commandName` (String, optional): Set command name base on you want beside name CustomGet
|
|
341
|
-
- `url` (String): The url that use to request to get something but not include baseURL
|
|
342
|
-
- `tenantId` (String, optional): Set tenant ID
|
|
535
|
+
```javascript
|
|
536
|
+
import { createClient } from '@mbanq/core-sdk-js';
|
|
343
537
|
|
|
344
|
-
|
|
538
|
+
// Initialize the client
|
|
539
|
+
const apiClient = createClient({
|
|
540
|
+
secret: 'your-secret',
|
|
541
|
+
signee: 'YOUR-SIGNEE',
|
|
542
|
+
baseUrl: 'https://api.cloud.mbanq.com',
|
|
543
|
+
tenantId: 'your-tenant-id'
|
|
544
|
+
});
|
|
345
545
|
|
|
346
|
-
|
|
546
|
+
// Create an ACH payment
|
|
547
|
+
const achPayment = await apiClient.payment.create({
|
|
548
|
+
amount: 1500,
|
|
549
|
+
currency: 'USD',
|
|
550
|
+
paymentRail: 'ACH',
|
|
551
|
+
paymentType: 'CREDIT',
|
|
552
|
+
debtor: {
|
|
553
|
+
name: 'Alice Corporation',
|
|
554
|
+
identifier: '111222333',
|
|
555
|
+
accountType: 'CHECKING',
|
|
556
|
+
agent: {
|
|
557
|
+
name: 'First National Bank',
|
|
558
|
+
identifier: '021000021'
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
creditor: {
|
|
562
|
+
name: 'Bob Enterprises',
|
|
563
|
+
identifier: '444555666',
|
|
564
|
+
accountType: 'CHECKING',
|
|
565
|
+
agent: {
|
|
566
|
+
name: 'Second Federal Bank',
|
|
567
|
+
identifier: '121000248'
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
clientId: 'client-abc123',
|
|
571
|
+
reference: ['Invoice-2025-001']
|
|
572
|
+
}).execute();
|
|
573
|
+
|
|
574
|
+
console.log('Created payment:', achPayment.id);
|
|
575
|
+
|
|
576
|
+
// Create an international WIRE payment
|
|
577
|
+
const wirePayment = await apiClient.payment.create({
|
|
578
|
+
amount: 5000,
|
|
579
|
+
currency: 'USD',
|
|
580
|
+
paymentRail: 'SWIFT',
|
|
581
|
+
paymentType: 'CREDIT',
|
|
582
|
+
debtor: {
|
|
583
|
+
name: 'US Company',
|
|
584
|
+
identifier: '123456789',
|
|
585
|
+
agent: {
|
|
586
|
+
name: 'Chase Bank',
|
|
587
|
+
identifier: 'CHASUS33XXX'
|
|
588
|
+
}
|
|
589
|
+
},
|
|
590
|
+
creditor: {
|
|
591
|
+
name: 'European Partner',
|
|
592
|
+
identifier: '987654321',
|
|
593
|
+
address: {
|
|
594
|
+
streetAddress: '123 Business Ave',
|
|
595
|
+
city: 'London',
|
|
596
|
+
state: 'England',
|
|
597
|
+
country: 'GB',
|
|
598
|
+
postalCode: 'SW1A 1AA'
|
|
599
|
+
},
|
|
600
|
+
agent: {
|
|
601
|
+
name: 'HSBC Bank',
|
|
602
|
+
identifier: 'HBUKGB4BXXX'
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
chargeBearer: 'OUR',
|
|
606
|
+
reference: ['Contract-2025-002'],
|
|
607
|
+
exchangeRate: 0.85
|
|
608
|
+
}).execute();
|
|
609
|
+
|
|
610
|
+
// Retrieve and monitor payments
|
|
611
|
+
const payment = await apiClient.payment.get(achPayment.id).execute();
|
|
612
|
+
console.log('Payment status:', payment.status);
|
|
613
|
+
|
|
614
|
+
// Update payment if needed
|
|
615
|
+
if (payment.status === 'DRAFT') {
|
|
616
|
+
await apiClient.payment.update(payment.id, {
|
|
617
|
+
status: 'EXECUTION_SCHEDULED',
|
|
618
|
+
reference: ['Updated-Reference']
|
|
619
|
+
});
|
|
620
|
+
}
|
|
347
621
|
|
|
348
|
-
|
|
349
|
-
|
|
622
|
+
// List recent payments with filters
|
|
623
|
+
const recentPayments = await apiClient.payment.list()
|
|
624
|
+
.where('status').eq('EXECUTION_SCHEDULED')
|
|
625
|
+
.where('paymentRail').eq('ACH')
|
|
626
|
+
.where('fromExecuteDate').eq('2025-01-01')
|
|
627
|
+
.where('toExecuteDate').eq('2025-01-31')
|
|
628
|
+
.limit(25)
|
|
629
|
+
.execute();
|
|
630
|
+
|
|
631
|
+
console.log(`Found ${recentPayments.length} scheduled ACH payments`);
|
|
632
|
+
|
|
633
|
+
// Multi-tenant example
|
|
634
|
+
const tenantPayment = await apiClient.tenant('different-tenant').payment.create({
|
|
635
|
+
amount: 750,
|
|
636
|
+
currency: 'USD',
|
|
637
|
+
paymentRail: 'INTERNAL',
|
|
638
|
+
paymentType: 'CREDIT',
|
|
639
|
+
debtor: { name: 'Internal Sender', identifier: '111111' },
|
|
640
|
+
creditor: { name: 'Internal Receiver', identifier: '222222' }
|
|
641
|
+
}).execute();
|
|
642
|
+
```
|
|
350
643
|
|
|
351
|
-
|
|
352
|
-
- `ValidationError`: Invalid parameters provided
|
|
353
|
-
- `ApiError`: General API error with specific error code and message
|
|
354
|
-
- `NetworkError`: Network-related issues
|
|
644
|
+
### Error Handling Example
|
|
355
645
|
|
|
356
|
-
## Examples
|
|
357
|
-
### Complete Transfer Flow Example
|
|
358
646
|
```javascript
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
try {
|
|
375
|
-
// Mark as processing
|
|
376
|
-
const markProcessing = MarkAsProcessing({
|
|
377
|
-
externalId: transfer.externalId,
|
|
378
|
-
fileUrl: transfer.fileUrl,
|
|
379
|
-
paymentType: 'ACH',
|
|
380
|
-
traceNumbers: {
|
|
381
|
-
outgoingTransfer: '123456'
|
|
382
|
-
},
|
|
383
|
-
tenantId: 'default'
|
|
384
|
-
})
|
|
385
|
-
await coreSDK.request(markProcessing);
|
|
386
|
-
|
|
387
|
-
// Your processing logic here
|
|
388
|
-
|
|
389
|
-
// If processing fails
|
|
390
|
-
if (/* some condition */) {
|
|
391
|
-
const markFail = MarkAsFail({
|
|
392
|
-
externalId: transfer.externalId,
|
|
393
|
-
errorMessage: 'error testing',
|
|
394
|
-
paymentType: 'ACH',
|
|
395
|
-
tenantId: 'default'
|
|
396
|
-
})
|
|
397
|
-
await coreSDK.request(markFail);
|
|
647
|
+
import { isCommandError } from '@mbanq/core-sdk-js';
|
|
648
|
+
|
|
649
|
+
try {
|
|
650
|
+
const payment = await apiClient.payment.create({
|
|
651
|
+
amount: -100, // Invalid: negative amount
|
|
652
|
+
currency: 'INVALID', // Invalid: not 3-character code
|
|
653
|
+
// Missing required fields
|
|
654
|
+
}).execute();
|
|
655
|
+
} catch (error) {
|
|
656
|
+
if (isCommandError(error)) {
|
|
657
|
+
console.error('Payment creation failed:');
|
|
658
|
+
console.error('Code:', error.code);
|
|
659
|
+
console.error('Message:', error.message);
|
|
660
|
+
if (error.requestId) {
|
|
661
|
+
console.error('Request ID:', error.requestId);
|
|
398
662
|
}
|
|
399
|
-
}
|
|
400
|
-
console.error(
|
|
663
|
+
} else {
|
|
664
|
+
console.error('Unexpected error:', error);
|
|
401
665
|
}
|
|
402
666
|
}
|
|
403
667
|
```
|