xendit-fn 1.0.0 → 1.0.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 +515 -114
- package/lib/index.cjs +1273 -43
- package/lib/index.d.cts +9180 -6479
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.d.ts +9180 -6479
- package/lib/index.esm.js +1273 -43
- package/lib/sdk/balance/index.d.ts +5 -0
- package/lib/sdk/balance/index.d.ts.map +1 -0
- package/lib/sdk/balance/schema.d.ts +170 -0
- package/lib/sdk/balance/schema.d.ts.map +1 -0
- package/lib/sdk/card/index.d.ts +14 -1
- package/lib/sdk/card/index.d.ts.map +1 -1
- package/lib/sdk/card/schema.d.ts +9 -8
- package/lib/sdk/card/schema.d.ts.map +1 -1
- package/lib/sdk/common.d.ts.map +1 -1
- package/lib/sdk/customer/index.d.ts.map +1 -1
- package/lib/sdk/ewallet/create.d.ts +3 -171
- package/lib/sdk/ewallet/create.d.ts.map +1 -1
- package/lib/sdk/index.d.ts +872 -2
- package/lib/sdk/index.d.ts.map +1 -1
- package/lib/sdk/invoice/index.d.ts.map +1 -1
- package/lib/sdk/payment-method/index.d.ts.map +1 -1
- package/lib/sdk/payment-request/index.d.ts +6 -0
- package/lib/sdk/payment-request/index.d.ts.map +1 -0
- package/lib/sdk/payment-request/schema.d.ts +1341 -0
- package/lib/sdk/payment-request/schema.d.ts.map +1 -0
- package/lib/sdk/payout/index.d.ts +7 -0
- package/lib/sdk/payout/index.d.ts.map +1 -0
- package/lib/sdk/payout/schema.d.ts +853 -0
- package/lib/sdk/payout/schema.d.ts.map +1 -0
- package/lib/sdk/refund/index.d.ts +6 -0
- package/lib/sdk/refund/index.d.ts.map +1 -0
- package/lib/sdk/refund/schema.d.ts +178 -0
- package/lib/sdk/refund/schema.d.ts.map +1 -0
- package/lib/utils/pagination.d.ts +1 -1
- package/lib/utils/pagination.d.ts.map +1 -1
- package/lib/utils/rate-limit.d.ts +3 -3
- package/lib/utils/rate-limit.d.ts.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -25,6 +25,11 @@ A modern, production-ready TypeScript SDK for the Xendit payment gateway. Framew
|
|
|
25
25
|
- E-wallet Payments
|
|
26
26
|
- Payment Methods
|
|
27
27
|
- Invoice Management
|
|
28
|
+
- **Payment Request API** (v3) - Unified payment processing
|
|
29
|
+
- **Refund API** - Process refunds
|
|
30
|
+
- **Payout API** - Disbursements and payouts
|
|
31
|
+
- **Balance & Transaction API** - Account balance and transaction history
|
|
32
|
+
- **Card Operations** - Tokenization, charges, and authorizations
|
|
28
33
|
|
|
29
34
|
## Installation
|
|
30
35
|
|
|
@@ -59,22 +64,329 @@ const customer = await xendit.customer.create({
|
|
|
59
64
|
mobile_number: '+639171234567',
|
|
60
65
|
});
|
|
61
66
|
|
|
62
|
-
// Create
|
|
63
|
-
const
|
|
64
|
-
reference_id: '
|
|
67
|
+
// Create a payment request (recommended for new integrations)
|
|
68
|
+
const payment = await xendit.paymentRequest.create({
|
|
69
|
+
reference_id: 'payment_001',
|
|
70
|
+
type: 'PAY',
|
|
71
|
+
country: 'PH',
|
|
65
72
|
currency: 'PHP',
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
request_amount: 10000, // 100.00 PHP
|
|
74
|
+
payment_method: {
|
|
75
|
+
type: 'EWALLET',
|
|
76
|
+
ewallet: {
|
|
77
|
+
channel_code: 'PH_GCASH',
|
|
78
|
+
channel_properties: {
|
|
79
|
+
success_redirect_url: 'https://yourapp.com/success',
|
|
80
|
+
failure_redirect_url: 'https://yourapp.com/failure',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
72
83
|
},
|
|
84
|
+
customer_id: customer.id,
|
|
73
85
|
});
|
|
74
86
|
```
|
|
75
87
|
|
|
76
88
|
## API Reference
|
|
77
89
|
|
|
90
|
+
### Payment Request API (v3) - Recommended
|
|
91
|
+
|
|
92
|
+
The Payment Request API is the unified way to process payments across all payment channels.
|
|
93
|
+
|
|
94
|
+
#### Create Payment Request
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
// E-wallet payment
|
|
98
|
+
const payment = await xendit.paymentRequest.create({
|
|
99
|
+
reference_id: 'payment_001',
|
|
100
|
+
type: 'PAY',
|
|
101
|
+
country: 'PH',
|
|
102
|
+
currency: 'PHP',
|
|
103
|
+
request_amount: 10000,
|
|
104
|
+
payment_method: {
|
|
105
|
+
type: 'EWALLET',
|
|
106
|
+
ewallet: {
|
|
107
|
+
channel_code: 'PH_GCASH',
|
|
108
|
+
channel_properties: {
|
|
109
|
+
success_redirect_url: 'https://yourapp.com/success',
|
|
110
|
+
failure_redirect_url: 'https://yourapp.com/failure',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
description: 'Payment for order #123',
|
|
115
|
+
customer_id: 'cust-12345',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Card payment
|
|
119
|
+
const cardPayment = await xendit.paymentRequest.create({
|
|
120
|
+
reference_id: 'payment_002',
|
|
121
|
+
type: 'PAY',
|
|
122
|
+
country: 'PH',
|
|
123
|
+
currency: 'PHP',
|
|
124
|
+
request_amount: 50000,
|
|
125
|
+
payment_method: {
|
|
126
|
+
type: 'CARD',
|
|
127
|
+
card_information: {
|
|
128
|
+
token_id: 'token-from-xendit-js',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
capture_method: 'AUTOMATIC',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Direct debit payment
|
|
135
|
+
const directDebitPayment = await xendit.paymentRequest.create({
|
|
136
|
+
reference_id: 'payment_003',
|
|
137
|
+
type: 'PAY',
|
|
138
|
+
country: 'ID',
|
|
139
|
+
currency: 'IDR',
|
|
140
|
+
request_amount: 100000,
|
|
141
|
+
payment_method: {
|
|
142
|
+
type: 'DIRECT_DEBIT',
|
|
143
|
+
direct_debit: {
|
|
144
|
+
channel_code: 'BCA_ONEKLIK',
|
|
145
|
+
channel_properties: {
|
|
146
|
+
account_mobile_number: '+6281234567890',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Virtual account payment
|
|
153
|
+
const vaPayment = await xendit.paymentRequest.create({
|
|
154
|
+
reference_id: 'payment_004',
|
|
155
|
+
type: 'PAY',
|
|
156
|
+
country: 'ID',
|
|
157
|
+
currency: 'IDR',
|
|
158
|
+
request_amount: 200000,
|
|
159
|
+
payment_method: {
|
|
160
|
+
type: 'VIRTUAL_ACCOUNT',
|
|
161
|
+
virtual_account: {
|
|
162
|
+
channel_code: 'BCA',
|
|
163
|
+
channel_properties: {
|
|
164
|
+
customer_name: 'John Doe',
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Get Payment Request
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const payment = await xendit.paymentRequest.get({
|
|
175
|
+
id: 'pr-12345',
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### List Payment Requests
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const payments = await xendit.paymentRequest.list({
|
|
183
|
+
status: ['SUCCEEDED', 'PENDING'],
|
|
184
|
+
limit: 50,
|
|
185
|
+
created_after: '2024-01-01T00:00:00Z',
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Refund API
|
|
190
|
+
|
|
191
|
+
Process refunds for successful payment requests.
|
|
192
|
+
|
|
193
|
+
#### Create Refund
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// Full refund
|
|
197
|
+
const refund = await xendit.refund.create({
|
|
198
|
+
payment_request_id: 'pr-12345',
|
|
199
|
+
reason: 'REQUESTED_BY_CUSTOMER',
|
|
200
|
+
metadata: {
|
|
201
|
+
order_id: 'order_123',
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Partial refund
|
|
206
|
+
const partialRefund = await xendit.refund.create({
|
|
207
|
+
payment_request_id: 'pr-12345',
|
|
208
|
+
amount: 5000, // Partial amount
|
|
209
|
+
reason: 'CANCELLATION',
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Get Refund
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const refund = await xendit.refund.get({
|
|
217
|
+
id: 'refund-12345',
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### List Refunds
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const refunds = await xendit.refund.list({
|
|
225
|
+
payment_request_id: 'pr-12345',
|
|
226
|
+
limit: 20,
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Payout API
|
|
231
|
+
|
|
232
|
+
Create and manage payouts/disbursements.
|
|
233
|
+
|
|
234
|
+
#### Create Payout
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// Bank payout
|
|
238
|
+
const payout = await xendit.payout.create({
|
|
239
|
+
reference_id: 'payout_001',
|
|
240
|
+
channel_code: 'BANK',
|
|
241
|
+
channel_properties: {
|
|
242
|
+
channel_code: 'BANK',
|
|
243
|
+
bank_account: {
|
|
244
|
+
account_holder_name: 'John Doe',
|
|
245
|
+
account_number: '1234567890',
|
|
246
|
+
bank_code: 'BCA',
|
|
247
|
+
account_type: 'CHECKING',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
amount: 100000,
|
|
251
|
+
currency: 'IDR',
|
|
252
|
+
description: 'Payout for order #123',
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// E-wallet payout
|
|
256
|
+
const ewalletPayout = await xendit.payout.create({
|
|
257
|
+
reference_id: 'payout_002',
|
|
258
|
+
channel_code: 'EWALLET',
|
|
259
|
+
channel_properties: {
|
|
260
|
+
channel_code: 'EWALLET',
|
|
261
|
+
ewallet: {
|
|
262
|
+
account_holder_name: 'Jane Doe',
|
|
263
|
+
account_number: '+6281234567890',
|
|
264
|
+
ewallet_type: 'OVO',
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
amount: 50000,
|
|
268
|
+
currency: 'IDR',
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### Get Payout
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
const payout = await xendit.payout.get({
|
|
276
|
+
id: 'payout-12345',
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### List Payouts
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
const payouts = await xendit.payout.list({
|
|
284
|
+
status: ['COMPLETED', 'PENDING'],
|
|
285
|
+
channel_code: ['BANK'],
|
|
286
|
+
limit: 50,
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
#### Cancel Payout
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
const cancelledPayout = await xendit.payout.cancel({
|
|
294
|
+
id: 'payout-12345',
|
|
295
|
+
});
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Balance & Transaction API
|
|
299
|
+
|
|
300
|
+
#### Get Balance
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const balance = await xendit.balance.get();
|
|
304
|
+
// Returns: { balance: 1000000, currency: 'IDR' }
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### List Transactions
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const transactions = await xendit.balance.listTransactions({
|
|
311
|
+
types: ['PAYMENT', 'PAYOUT'],
|
|
312
|
+
statuses: ['SUCCEEDED'],
|
|
313
|
+
limit: 100,
|
|
314
|
+
created_after: '2024-01-01T00:00:00Z',
|
|
315
|
+
});
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Card Operations
|
|
319
|
+
|
|
320
|
+
#### Create Token
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
const token = await xendit.card.createToken({
|
|
324
|
+
mid_label: 'merchant_label',
|
|
325
|
+
card_data: {
|
|
326
|
+
account_number: '4111111111111111',
|
|
327
|
+
exp_month: '12',
|
|
328
|
+
exp_year: '2025',
|
|
329
|
+
card_holder_first_name: 'John',
|
|
330
|
+
card_holder_last_name: 'Doe',
|
|
331
|
+
card_holder_email: 'john@example.com',
|
|
332
|
+
card_holder_phone_number: '+639171234567',
|
|
333
|
+
},
|
|
334
|
+
is_multiple_use: true,
|
|
335
|
+
currency: 'PHP',
|
|
336
|
+
});
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
#### Get Token
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
const token = await xendit.card.getToken({
|
|
343
|
+
credit_card_token_id: 'token-12345',
|
|
344
|
+
});
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
#### Authenticate Token
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
const auth = await xendit.card.authenticateToken({
|
|
351
|
+
token_id: 'token-12345',
|
|
352
|
+
amount: '10000',
|
|
353
|
+
currency: 'PHP',
|
|
354
|
+
external_id: 'auth_001',
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### Authorize Token
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
const charge = await xendit.card.authorizeToken({
|
|
362
|
+
token_id: 'token-12345',
|
|
363
|
+
amount: '10000',
|
|
364
|
+
external_id: 'charge_001',
|
|
365
|
+
capture: true,
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
#### Create Charge
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
const charge = await xendit.card.createCharge({
|
|
373
|
+
token_id: 'token-12345',
|
|
374
|
+
external_id: 'charge_001',
|
|
375
|
+
amount: 10000,
|
|
376
|
+
currency: 'PHP',
|
|
377
|
+
capture: true,
|
|
378
|
+
authentication_id: 'auth-12345',
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
#### Get Charge
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
const charge = await xendit.card.getCharge({
|
|
386
|
+
id: 'charge-12345',
|
|
387
|
+
});
|
|
388
|
+
```
|
|
389
|
+
|
|
78
390
|
### Customer Management
|
|
79
391
|
|
|
80
392
|
#### Create Customer
|
|
@@ -178,7 +490,122 @@ const charge = await xendit.ewallet.get({
|
|
|
178
490
|
});
|
|
179
491
|
```
|
|
180
492
|
|
|
181
|
-
###
|
|
493
|
+
### Payment Methods
|
|
494
|
+
|
|
495
|
+
#### Create Payment Method
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
const paymentMethod = await xendit.paymentMethod.create({
|
|
499
|
+
type: 'CARD',
|
|
500
|
+
country: 'PH',
|
|
501
|
+
reusability: 'MULTIPLE_USE',
|
|
502
|
+
card: {
|
|
503
|
+
currency: 'PHP',
|
|
504
|
+
channel_properties: {
|
|
505
|
+
success_return_url: 'https://yourapp.com/success',
|
|
506
|
+
failure_return_url: 'https://yourapp.com/failure',
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
#### Get Payment Method
|
|
513
|
+
|
|
514
|
+
```typescript
|
|
515
|
+
const paymentMethod = await xendit.paymentMethod.get({
|
|
516
|
+
id: 'pm-12345',
|
|
517
|
+
});
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
#### List Payment Methods
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
const paymentMethods = await xendit.paymentMethod.list({
|
|
524
|
+
customer_id: 'cust-12345',
|
|
525
|
+
type: ['CARD', 'EWALLET'],
|
|
526
|
+
status: ['ACTIVE'],
|
|
527
|
+
limit: 50,
|
|
528
|
+
});
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
#### Update Payment Method
|
|
532
|
+
|
|
533
|
+
```typescript
|
|
534
|
+
const updated = await xendit.paymentMethod.update({
|
|
535
|
+
id: 'pm-12345',
|
|
536
|
+
payload: {
|
|
537
|
+
status: 'INACTIVE',
|
|
538
|
+
description: 'Card expired',
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Invoice Management
|
|
544
|
+
|
|
545
|
+
#### Create Invoice
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
const invoice = await xendit.invoice.create({
|
|
549
|
+
external_id: 'invoice-001',
|
|
550
|
+
payer_email: 'customer@example.com',
|
|
551
|
+
amount: 100000,
|
|
552
|
+
description: 'Payment for services',
|
|
553
|
+
invoice_duration: 3600,
|
|
554
|
+
customer: {
|
|
555
|
+
customer_name: 'John Doe',
|
|
556
|
+
customer_email: 'customer@example.com',
|
|
557
|
+
customer_phone: '+639171234567',
|
|
558
|
+
},
|
|
559
|
+
success_redirect_url: 'https://yoursite.com/success',
|
|
560
|
+
failure_redirect_url: 'https://yoursite.com/failure',
|
|
561
|
+
});
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
#### Get Invoice
|
|
565
|
+
|
|
566
|
+
```typescript
|
|
567
|
+
const invoice = await xendit.invoice.get({
|
|
568
|
+
invoice_id: 'invoice-12345',
|
|
569
|
+
});
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
#### List Invoices
|
|
573
|
+
|
|
574
|
+
```typescript
|
|
575
|
+
const invoices = await xendit.invoice.list({
|
|
576
|
+
statuses: ['PAID', 'PENDING'],
|
|
577
|
+
limit: 50,
|
|
578
|
+
created_after: '2024-01-01T00:00:00Z',
|
|
579
|
+
});
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
#### Update Invoice
|
|
583
|
+
|
|
584
|
+
```typescript
|
|
585
|
+
const updated = await xendit.invoice.update({
|
|
586
|
+
invoice_id: 'invoice-12345',
|
|
587
|
+
payload: {
|
|
588
|
+
customer_email: 'newemail@example.com',
|
|
589
|
+
items: [
|
|
590
|
+
{
|
|
591
|
+
name: 'Updated Item',
|
|
592
|
+
quantity: 2,
|
|
593
|
+
price: 50000,
|
|
594
|
+
},
|
|
595
|
+
],
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
#### Expire Invoice
|
|
601
|
+
|
|
602
|
+
```typescript
|
|
603
|
+
const expired = await xendit.invoice.expire({
|
|
604
|
+
invoice_id: 'invoice-12345',
|
|
605
|
+
});
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
## Supported Countries and Currencies
|
|
182
609
|
|
|
183
610
|
- **Philippines (PH)**: PHP
|
|
184
611
|
- **Indonesia (ID)**: IDR
|
|
@@ -186,23 +613,33 @@ const charge = await xendit.ewallet.get({
|
|
|
186
613
|
- **Thailand (TH)**: THB
|
|
187
614
|
- **Vietnam (VN)**: VND
|
|
188
615
|
|
|
189
|
-
|
|
616
|
+
## Supported Payment Channels
|
|
190
617
|
|
|
618
|
+
### E-Wallets
|
|
191
619
|
- **Indonesia**: OVO, DANA, LinkAja, ShopeePay, AstraPay, JENIUSPAY, SakuKu
|
|
192
620
|
- **Philippines**: PayMaya, GCash, GrabPay, ShopeePay
|
|
193
621
|
- **Vietnam**: Appota, MoMo, ShopeePay, VNPTWallet, ViettelPay, ZaloPay
|
|
194
622
|
- **Thailand**: WeChat Pay, LINE Pay, TrueMoney, ShopeePay
|
|
195
623
|
- **Malaysia**: Touch 'n Go, ShopeePay, GrabPay
|
|
196
624
|
|
|
625
|
+
### Cards
|
|
626
|
+
- Visa, Mastercard, JCB, AMEX
|
|
627
|
+
|
|
628
|
+
### Direct Debit
|
|
629
|
+
- BCA OneKlik, Mandiri ClickPay, BRI AutoDebit
|
|
630
|
+
|
|
631
|
+
### Virtual Accounts
|
|
632
|
+
- BCA, BNI, Mandiri, Permata, and more
|
|
633
|
+
|
|
197
634
|
## Error Handling
|
|
198
635
|
|
|
199
636
|
The SDK provides comprehensive error handling with custom error types:
|
|
200
637
|
|
|
201
638
|
```typescript
|
|
202
|
-
import { XenditApiError, ValidationError } from 'xendit-fn
|
|
639
|
+
import { XenditApiError, ValidationError } from 'xendit-fn';
|
|
203
640
|
|
|
204
641
|
try {
|
|
205
|
-
const
|
|
642
|
+
const payment = await xendit.paymentRequest.create(invalidData);
|
|
206
643
|
} catch (error) {
|
|
207
644
|
if (error instanceof ValidationError) {
|
|
208
645
|
console.error('Validation failed:', error.validationErrors);
|
|
@@ -225,73 +662,22 @@ The SDK is built with TypeScript and provides full type definitions:
|
|
|
225
662
|
|
|
226
663
|
```typescript
|
|
227
664
|
import type {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
665
|
+
CreatePaymentRequest,
|
|
666
|
+
PaymentRequestResource,
|
|
667
|
+
CreateRefund,
|
|
668
|
+
RefundResource,
|
|
669
|
+
CreatePayout,
|
|
670
|
+
PayoutResource,
|
|
232
671
|
} from 'xendit-fn';
|
|
233
672
|
|
|
234
673
|
// All parameters and responses are fully typed
|
|
235
|
-
const
|
|
236
|
-
|
|
674
|
+
const createPayment = async (
|
|
675
|
+
data: CreatePaymentRequest
|
|
676
|
+
): Promise<PaymentRequestResource> => {
|
|
677
|
+
return await xendit.paymentRequest.create(data);
|
|
237
678
|
};
|
|
238
679
|
```
|
|
239
680
|
|
|
240
|
-
## Development
|
|
241
|
-
|
|
242
|
-
### Setup
|
|
243
|
-
|
|
244
|
-
```bash
|
|
245
|
-
# Install dependencies
|
|
246
|
-
bun install
|
|
247
|
-
|
|
248
|
-
# Run type checking
|
|
249
|
-
bun run typecheck
|
|
250
|
-
|
|
251
|
-
# Run linting
|
|
252
|
-
bun run lint
|
|
253
|
-
|
|
254
|
-
# Run tests
|
|
255
|
-
bun run test
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### Building
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
# Build the package
|
|
262
|
-
bun run build
|
|
263
|
-
|
|
264
|
-
# Start development mode
|
|
265
|
-
bun run dev
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Environment Variables
|
|
269
|
-
|
|
270
|
-
For testing, create a `.env` file:
|
|
271
|
-
|
|
272
|
-
```env
|
|
273
|
-
XENDIT_SK=your_xendit_secret_key_here
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
## Contributing
|
|
277
|
-
|
|
278
|
-
1. Fork the repository
|
|
279
|
-
2. Create a feature branch
|
|
280
|
-
3. Make your changes
|
|
281
|
-
4. Add tests for new functionality
|
|
282
|
-
5. Run the test suite
|
|
283
|
-
6. Submit a pull request
|
|
284
|
-
|
|
285
|
-
## License
|
|
286
|
-
|
|
287
|
-
MIT License - see [LICENSE](LICENSE) file for details.
|
|
288
|
-
|
|
289
|
-
## Related Projects
|
|
290
|
-
|
|
291
|
-
- [Xendit API Documentation](https://developers.xendit.co/)
|
|
292
|
-
- [TypeScript](https://typescriptlang.org/)
|
|
293
|
-
- [Zod](https://zod.dev/)
|
|
294
|
-
|
|
295
681
|
## Production-Ready Features
|
|
296
682
|
|
|
297
683
|
### Rate Limiting
|
|
@@ -319,7 +705,6 @@ Secure webhook processing with signature verification:
|
|
|
319
705
|
import {
|
|
320
706
|
createWebhookProcessor,
|
|
321
707
|
WebhookHandlers,
|
|
322
|
-
parseWebhookEvent
|
|
323
708
|
} from 'xendit-fn';
|
|
324
709
|
|
|
325
710
|
// Create webhook processor
|
|
@@ -331,14 +716,18 @@ const webhookProcessor = createWebhookProcessor({
|
|
|
331
716
|
|
|
332
717
|
// Define event handlers
|
|
333
718
|
const handlers: WebhookHandlers = {
|
|
334
|
-
'
|
|
335
|
-
console.log('
|
|
719
|
+
'payment_request.succeeded': async (event) => {
|
|
720
|
+
console.log('Payment succeeded:', event.data);
|
|
336
721
|
// Process payment success
|
|
337
722
|
},
|
|
338
|
-
'
|
|
723
|
+
'payment_request.failed': async (event) => {
|
|
339
724
|
console.log('Payment failed:', event.data);
|
|
340
725
|
// Handle payment failure
|
|
341
|
-
}
|
|
726
|
+
},
|
|
727
|
+
'refund.succeeded': async (event) => {
|
|
728
|
+
console.log('Refund processed:', event.data);
|
|
729
|
+
// Handle refund
|
|
730
|
+
},
|
|
342
731
|
};
|
|
343
732
|
|
|
344
733
|
// Process webhook in your endpoint
|
|
@@ -382,56 +771,68 @@ for await (const invoice of iterateItems(
|
|
|
382
771
|
}
|
|
383
772
|
```
|
|
384
773
|
|
|
385
|
-
|
|
774
|
+
## Development
|
|
386
775
|
|
|
387
|
-
|
|
776
|
+
### Setup
|
|
388
777
|
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
customer_id: 'customer-id',
|
|
393
|
-
type: 'DEBIT_CARD',
|
|
394
|
-
properties: {
|
|
395
|
-
id: 'card-token-from-xendit-js',
|
|
396
|
-
},
|
|
397
|
-
});
|
|
778
|
+
```bash
|
|
779
|
+
# Install dependencies
|
|
780
|
+
bun install
|
|
398
781
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
782
|
+
# Run type checking
|
|
783
|
+
bun run typecheck
|
|
784
|
+
|
|
785
|
+
# Run linting
|
|
786
|
+
bun run lint
|
|
787
|
+
|
|
788
|
+
# Run tests
|
|
789
|
+
bun run test
|
|
403
790
|
```
|
|
404
791
|
|
|
405
|
-
|
|
792
|
+
### Building
|
|
406
793
|
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
external_id: 'invoice-001',
|
|
411
|
-
amount: 100000,
|
|
412
|
-
description: 'Payment for services',
|
|
413
|
-
invoice_duration: 3600,
|
|
414
|
-
customer: {
|
|
415
|
-
given_names: 'John',
|
|
416
|
-
email: 'customer@example.com',
|
|
417
|
-
},
|
|
418
|
-
success_redirect_url: 'https://yoursite.com/success',
|
|
419
|
-
failure_redirect_url: 'https://yoursite.com/failure',
|
|
420
|
-
});
|
|
794
|
+
```bash
|
|
795
|
+
# Build the package
|
|
796
|
+
bun run build
|
|
421
797
|
|
|
422
|
-
|
|
423
|
-
|
|
798
|
+
# Start development mode
|
|
799
|
+
bun run dev
|
|
424
800
|
```
|
|
425
801
|
|
|
426
|
-
### Environment
|
|
802
|
+
### Environment Variables
|
|
803
|
+
|
|
804
|
+
For testing, create a `.env` file:
|
|
805
|
+
|
|
806
|
+
```env
|
|
807
|
+
XENDIT_SK=your_xendit_secret_key_here
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
## Contributing
|
|
811
|
+
|
|
812
|
+
1. Fork the repository
|
|
813
|
+
2. Create a feature branch
|
|
814
|
+
3. Make your changes
|
|
815
|
+
4. Add tests for new functionality
|
|
816
|
+
5. Run the test suite
|
|
817
|
+
6. Submit a pull request
|
|
818
|
+
|
|
819
|
+
## License
|
|
820
|
+
|
|
821
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
822
|
+
|
|
823
|
+
## Related Projects
|
|
824
|
+
|
|
825
|
+
- [Xendit API Documentation](https://developers.xendit.co/)
|
|
826
|
+
- [TypeScript](https://typescriptlang.org/)
|
|
827
|
+
- [Zod](https://zod.dev/)
|
|
828
|
+
|
|
829
|
+
## Environment Configuration
|
|
427
830
|
|
|
428
831
|
The SDK automatically detects test mode:
|
|
429
832
|
|
|
430
833
|
```typescript
|
|
431
834
|
// Test mode (automatically detected)
|
|
432
835
|
const xendit = Xendit('xnd_development_...');
|
|
433
|
-
//
|
|
434
|
-
|
|
435
836
|
|
|
436
837
|
// Production mode
|
|
437
838
|
const xendit = Xendit('xnd_production_...');
|