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/lib/index.cjs
CHANGED
|
@@ -264,7 +264,7 @@ const CurrencySchema = zod.z.union([
|
|
|
264
264
|
zod.z.literal("THB"),
|
|
265
265
|
zod.z.literal("VND")
|
|
266
266
|
]);
|
|
267
|
-
zod.z.object({
|
|
267
|
+
const BillingDetailSchema = zod.z.object({
|
|
268
268
|
given_names: zod.z.string(),
|
|
269
269
|
surname: zod.z.string().optional(),
|
|
270
270
|
email: zod.z.string().email().optional(),
|
|
@@ -326,7 +326,7 @@ const AccountTypeSchema = zod.z.union([
|
|
|
326
326
|
zod.z.literal("QR_CODE"),
|
|
327
327
|
zod.z.literal("SOCIAL_MEDIA")
|
|
328
328
|
]);
|
|
329
|
-
const BankAccountSchema = zod.z.object({
|
|
329
|
+
const BankAccountSchema$1 = zod.z.object({
|
|
330
330
|
account_number: zod.z.string(),
|
|
331
331
|
account_holder_name: zod.z.string(),
|
|
332
332
|
swift_code: zod.z.string().optional(),
|
|
@@ -361,7 +361,7 @@ const SocialMediaAccountSchema = zod.z.object({
|
|
|
361
361
|
const PropertiesSchema = zod.z.discriminatedUnion("type", [
|
|
362
362
|
zod.z.object({
|
|
363
363
|
type: zod.z.literal("BANK_ACCOUNT"),
|
|
364
|
-
properties: BankAccountSchema
|
|
364
|
+
properties: BankAccountSchema$1
|
|
365
365
|
}),
|
|
366
366
|
zod.z.object({
|
|
367
367
|
type: zod.z.literal("EWALLET"),
|
|
@@ -569,8 +569,228 @@ const updateCustomer = async (params, axiosInstance, config)=>{
|
|
|
569
569
|
}
|
|
570
570
|
};
|
|
571
571
|
|
|
572
|
-
const
|
|
573
|
-
|
|
572
|
+
const CheckoutMethodSchema = zod.z.union([
|
|
573
|
+
zod.z.literal("ONE_TIME_PAYMENT"),
|
|
574
|
+
zod.z.literal("TOKENIZED_PAYMENT")
|
|
575
|
+
]);
|
|
576
|
+
const ChannelCodeSchema = zod.z.union([
|
|
577
|
+
zod.z.literal("ID_OVO"),
|
|
578
|
+
zod.z.literal("ID_DANA"),
|
|
579
|
+
zod.z.literal("ID_LINKAJA"),
|
|
580
|
+
zod.z.literal("ID_SHOPEEPAY"),
|
|
581
|
+
zod.z.literal("ID_ASTRAPAY"),
|
|
582
|
+
zod.z.literal("ID_JENIUSPAY"),
|
|
583
|
+
zod.z.literal("ID_SAKUKU"),
|
|
584
|
+
zod.z.literal("PH_PAYMAYA"),
|
|
585
|
+
zod.z.literal("PH_GCASH"),
|
|
586
|
+
zod.z.literal("PH_GRABPAY"),
|
|
587
|
+
zod.z.literal("PH_SHOPEEPAY"),
|
|
588
|
+
zod.z.literal("VN_APPOTA"),
|
|
589
|
+
zod.z.literal("VN_MOMO"),
|
|
590
|
+
zod.z.literal("VN_SHOPEEPAY"),
|
|
591
|
+
zod.z.literal("VN_VNPTWALLET"),
|
|
592
|
+
zod.z.literal("VN_VIETTELPAY"),
|
|
593
|
+
zod.z.literal("VN_ZALOPAY"),
|
|
594
|
+
zod.z.literal("TH_WECHATPAY"),
|
|
595
|
+
zod.z.literal("TH_LINEPAY"),
|
|
596
|
+
zod.z.literal("TH_TRUEMONEY"),
|
|
597
|
+
zod.z.literal("TH_SHOPEEPAY"),
|
|
598
|
+
zod.z.literal("MY_TOUCHNGO"),
|
|
599
|
+
zod.z.literal("MY_SHOPEEPAY"),
|
|
600
|
+
zod.z.literal("MY_GRABPAY")
|
|
601
|
+
]);
|
|
602
|
+
const OVOChannelSchema = zod.z.object({
|
|
603
|
+
mobile_number: PhoneSchema
|
|
604
|
+
});
|
|
605
|
+
const ChannelsSchema = zod.z.object({
|
|
606
|
+
cashtag: zod.z.string().refine((value)=>value.startsWith("$")).optional(),
|
|
607
|
+
mobile_number: PhoneSchema.optional(),
|
|
608
|
+
success_redirect_url: zod.z.string().url().optional(),
|
|
609
|
+
failure_redirect_url: zod.z.string().url().optional(),
|
|
610
|
+
cancel_redirect_url: zod.z.string().url().optional(),
|
|
611
|
+
redeem_points: zod.z.union([
|
|
612
|
+
zod.z.literal("REDEEM_ALL"),
|
|
613
|
+
zod.z.literal("REDEEM_NONE")
|
|
614
|
+
]).default("REDEEM_NONE").optional()
|
|
615
|
+
});
|
|
616
|
+
const ChannelPropertiesSchema$1 = zod.z.discriminatedUnion("channel_code", [
|
|
617
|
+
zod.z.object({
|
|
618
|
+
channel_code: zod.z.literal("ID_OVO"),
|
|
619
|
+
channel_properties: OVOChannelSchema
|
|
620
|
+
}),
|
|
621
|
+
zod.z.object({
|
|
622
|
+
channel_code: zod.z.literal("ID_JENIUSPAY"),
|
|
623
|
+
properties: zod.z.discriminatedUnion("method", [
|
|
624
|
+
zod.z.object({
|
|
625
|
+
method: zod.z.literal("ONE_TIME_PAYMENT"),
|
|
626
|
+
properties: zod.z.object({
|
|
627
|
+
cashtag: zod.z.string().refine((value)=>value.startsWith("$"))
|
|
628
|
+
})
|
|
629
|
+
}),
|
|
630
|
+
zod.z.object({
|
|
631
|
+
method: zod.z.literal("TOKENIZED_PAYMENT"),
|
|
632
|
+
properties: zod.z.object({
|
|
633
|
+
success_redirect_url: zod.z.string().url(),
|
|
634
|
+
failure_redirect_url: zod.z.string().url(),
|
|
635
|
+
redeem_points: zod.z.union([
|
|
636
|
+
zod.z.literal("REDEEM_ALL"),
|
|
637
|
+
zod.z.literal("REDEEM_NONE")
|
|
638
|
+
]).default("REDEEM_NONE").optional()
|
|
639
|
+
})
|
|
640
|
+
})
|
|
641
|
+
])
|
|
642
|
+
}),
|
|
643
|
+
zod.z.object({
|
|
644
|
+
channel_code: zod.z.union([
|
|
645
|
+
zod.z.literal("ID_DANA"),
|
|
646
|
+
zod.z.literal("ID_LINKAJA"),
|
|
647
|
+
zod.z.literal("ID_SHOPEEPAY"),
|
|
648
|
+
zod.z.literal("PH_SHOPEEPAY"),
|
|
649
|
+
zod.z.literal("TH_SHOPEEPAY"),
|
|
650
|
+
zod.z.literal("TH_WECHATPAY"),
|
|
651
|
+
zod.z.literal("TH_TOUCHNGO"),
|
|
652
|
+
zod.z.literal("TH_TRUEMONEY"),
|
|
653
|
+
zod.z.literal("ID_SAKUKU")
|
|
654
|
+
]),
|
|
655
|
+
properties: zod.z.discriminatedUnion("method", [
|
|
656
|
+
zod.z.object({
|
|
657
|
+
method: zod.z.literal("ONE_TIME_PAYMENT"),
|
|
658
|
+
properties: zod.z.object({
|
|
659
|
+
success_redirect_url: zod.z.string().url()
|
|
660
|
+
})
|
|
661
|
+
}),
|
|
662
|
+
zod.z.object({
|
|
663
|
+
method: zod.z.literal("TOKENIZED_PAYMENT"),
|
|
664
|
+
properties: zod.z.object({
|
|
665
|
+
success_redirect_url: zod.z.string().url(),
|
|
666
|
+
failure_redirect_url: zod.z.string().url(),
|
|
667
|
+
redeem_points: zod.z.union([
|
|
668
|
+
zod.z.literal("REDEEM_ALL"),
|
|
669
|
+
zod.z.literal("REDEEM_NONE")
|
|
670
|
+
]).default("REDEEM_NONE").optional()
|
|
671
|
+
})
|
|
672
|
+
})
|
|
673
|
+
])
|
|
674
|
+
}),
|
|
675
|
+
zod.z.object({
|
|
676
|
+
channel_code: zod.z.literal("PH_PAYMAYA"),
|
|
677
|
+
properties: zod.z.object({
|
|
678
|
+
success_redirect_url: zod.z.string().url(),
|
|
679
|
+
failure_redirect_url: zod.z.string().url(),
|
|
680
|
+
cancel_redirect_url: zod.z.string().url()
|
|
681
|
+
})
|
|
682
|
+
})
|
|
683
|
+
]);
|
|
684
|
+
const LineItemSchema = zod.z.object({
|
|
685
|
+
reference_id: zod.z.string(),
|
|
686
|
+
name: zod.z.string(),
|
|
687
|
+
category: zod.z.string(),
|
|
688
|
+
currency: CurrencySchema,
|
|
689
|
+
price: zod.z.number(),
|
|
690
|
+
quantity: zod.z.number(),
|
|
691
|
+
type: zod.z.union([
|
|
692
|
+
zod.z.literal("PRODUCT"),
|
|
693
|
+
zod.z.literal("SERVICE")
|
|
694
|
+
]),
|
|
695
|
+
url: zod.z.string().url().optional(),
|
|
696
|
+
description: zod.z.string().optional(),
|
|
697
|
+
subcategory: zod.z.string().optional(),
|
|
698
|
+
metadata: zod.z.object({}).optional()
|
|
699
|
+
});
|
|
700
|
+
// Create a discriminated union based on checkout method
|
|
701
|
+
const EWalletChargeSchema = zod.z.discriminatedUnion("checkout_method", [
|
|
702
|
+
zod.z.object({
|
|
703
|
+
reference_id: zod.z.string(),
|
|
704
|
+
currency: CurrencySchema,
|
|
705
|
+
amount: zod.z.number(),
|
|
706
|
+
checkout_method: zod.z.literal("ONE_TIME_PAYMENT"),
|
|
707
|
+
channel_code: ChannelCodeSchema,
|
|
708
|
+
channel_properties: ChannelsSchema,
|
|
709
|
+
payment_method_id: zod.z.undefined().optional(),
|
|
710
|
+
customer_id: zod.z.string().optional(),
|
|
711
|
+
basket: zod.z.array(LineItemSchema).optional(),
|
|
712
|
+
metadata: zod.z.object({}).optional()
|
|
713
|
+
}),
|
|
714
|
+
zod.z.object({
|
|
715
|
+
reference_id: zod.z.string(),
|
|
716
|
+
currency: CurrencySchema,
|
|
717
|
+
amount: zod.z.number(),
|
|
718
|
+
checkout_method: zod.z.literal("TOKENIZED_PAYMENT"),
|
|
719
|
+
channel_code: ChannelCodeSchema.optional(),
|
|
720
|
+
channel_properties: ChannelsSchema,
|
|
721
|
+
payment_method_id: zod.z.string(),
|
|
722
|
+
customer_id: zod.z.string().optional(),
|
|
723
|
+
basket: zod.z.array(LineItemSchema).optional(),
|
|
724
|
+
metadata: zod.z.object({}).optional()
|
|
725
|
+
})
|
|
726
|
+
]);
|
|
727
|
+
const EWalletStatusSchema = zod.z.union([
|
|
728
|
+
zod.z.literal("SUCCEEDED"),
|
|
729
|
+
zod.z.literal("PENDING"),
|
|
730
|
+
zod.z.literal("FAILED"),
|
|
731
|
+
zod.z.literal("VOIDED"),
|
|
732
|
+
zod.z.literal("REFUNDED")
|
|
733
|
+
]);
|
|
734
|
+
const EWalletResourceActionsSchema = zod.z.object({
|
|
735
|
+
desktop_web_checkout_url: zod.z.string().url().optional(),
|
|
736
|
+
mobile_web_checkout_url: zod.z.string().url().optional(),
|
|
737
|
+
mobile_deeplink_checkout_url: zod.z.string().url().optional(),
|
|
738
|
+
qr_checkout_string: zod.z.string().url().optional()
|
|
739
|
+
});
|
|
740
|
+
const EWalletChargeResourceSchema = zod.z.object({
|
|
741
|
+
id: zod.z.string(),
|
|
742
|
+
business_id: zod.z.string(),
|
|
743
|
+
reference_id: zod.z.string(),
|
|
744
|
+
status: EWalletStatusSchema,
|
|
745
|
+
currency: CurrencySchema,
|
|
746
|
+
charge_amount: zod.z.number(),
|
|
747
|
+
capture_amount: zod.z.number().optional(),
|
|
748
|
+
refunded_amount: zod.z.number().nullable(),
|
|
749
|
+
checkout_method: CheckoutMethodSchema,
|
|
750
|
+
channel_code: ChannelCodeSchema,
|
|
751
|
+
channel_properties: ChannelPropertiesSchema$1,
|
|
752
|
+
actions: EWalletResourceActionsSchema.optional(),
|
|
753
|
+
is_redirect_required: zod.z.boolean(),
|
|
754
|
+
callback_url: zod.z.string(),
|
|
755
|
+
created: zod.z.string().datetime(),
|
|
756
|
+
updated: zod.z.string().datetime(),
|
|
757
|
+
void_status: zod.z.string().nullable(),
|
|
758
|
+
voided_at: zod.z.string().nullable(),
|
|
759
|
+
capture_now: zod.z.boolean(),
|
|
760
|
+
customer_id: zod.z.string().nullable(),
|
|
761
|
+
payment_method_id: zod.z.string().nullable(),
|
|
762
|
+
failure_code: zod.z.string().nullable(),
|
|
763
|
+
basket: zod.z.array(LineItemSchema).optional(),
|
|
764
|
+
metadata: zod.z.object({}).optional()
|
|
765
|
+
});
|
|
766
|
+
const GetEWalletChargeSchema = zod.z.object({
|
|
767
|
+
id: zod.z.string().startsWith("ewc")
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
const createEwalletCharge = async (params, axiosInstance, config)=>{
|
|
771
|
+
try {
|
|
772
|
+
const validatedParams = validateInput(EWalletChargeSchema, params, "ewallet charge params");
|
|
773
|
+
const response = await axiosInstance.post(config?.url ?? "/ewallets/charges", validatedParams, config);
|
|
774
|
+
return validateInput(EWalletChargeResourceSchema, response.data, "ewallet charge response");
|
|
775
|
+
} catch (error) {
|
|
776
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
777
|
+
handleAxiosError(error);
|
|
778
|
+
}
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
const getEwalletCharge = async (params, axiosInstance, config)=>{
|
|
783
|
+
try {
|
|
784
|
+
const validatedParams = validateInput(GetEWalletChargeSchema, params, "get ewallet charge params");
|
|
785
|
+
const response = await axiosInstance.get(config?.url ?? `/ewallets/charges/${validatedParams.id}`, config);
|
|
786
|
+
return validateInput(EWalletChargeResourceSchema, response.data, "ewallet charge response");
|
|
787
|
+
} catch (error) {
|
|
788
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
789
|
+
handleAxiosError(error);
|
|
790
|
+
}
|
|
791
|
+
throw error;
|
|
792
|
+
}
|
|
793
|
+
};
|
|
574
794
|
|
|
575
795
|
// Payment Method Types
|
|
576
796
|
const PaymentMethodTypeSchema = zod.z.union([
|
|
@@ -806,6 +1026,9 @@ const listPaymentMethods = async (params, axiosInstance, config)=>{
|
|
|
806
1026
|
}
|
|
807
1027
|
const queryString = queryParams.toString();
|
|
808
1028
|
const url = queryString ? `/v2/payment_methods?${queryString}` : "/v2/payment_methods";
|
|
1029
|
+
if (!axiosInstance) {
|
|
1030
|
+
throw new Error("axiosInstance is required");
|
|
1031
|
+
}
|
|
809
1032
|
const response = await axiosInstance.get(config?.url ?? url, config);
|
|
810
1033
|
return response.data;
|
|
811
1034
|
} catch (error) {
|
|
@@ -1122,6 +1345,9 @@ const listInvoices = async (params, axiosInstance, config)=>{
|
|
|
1122
1345
|
}
|
|
1123
1346
|
const queryString = queryParams.toString();
|
|
1124
1347
|
const url = queryString ? `/v2/invoices?${queryString}` : "/v2/invoices";
|
|
1348
|
+
if (!axiosInstance) {
|
|
1349
|
+
throw new Error("axiosInstance is required");
|
|
1350
|
+
}
|
|
1125
1351
|
const response = await axiosInstance.get(config?.url ?? url, config);
|
|
1126
1352
|
return response.data;
|
|
1127
1353
|
} catch (error) {
|
|
@@ -1156,51 +1382,1055 @@ const expireInvoice = async (params, axiosInstance, config)=>{
|
|
|
1156
1382
|
}
|
|
1157
1383
|
};
|
|
1158
1384
|
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1385
|
+
// Payment Request Types
|
|
1386
|
+
const PaymentRequestTypeSchema = zod.z.union([
|
|
1387
|
+
zod.z.literal("PAY"),
|
|
1388
|
+
zod.z.literal("PAY_AND_SAVE"),
|
|
1389
|
+
zod.z.literal("REUSABLE_PAYMENT_CODE")
|
|
1390
|
+
]);
|
|
1391
|
+
// Capture Method
|
|
1392
|
+
const CaptureMethodSchema = zod.z.union([
|
|
1393
|
+
zod.z.literal("AUTOMATIC"),
|
|
1394
|
+
zod.z.literal("MANUAL")
|
|
1395
|
+
]);
|
|
1396
|
+
// Payment Request Status
|
|
1397
|
+
const PaymentRequestStatusSchema = zod.z.union([
|
|
1398
|
+
zod.z.literal("PENDING"),
|
|
1399
|
+
zod.z.literal("REQUIRES_ACTION"),
|
|
1400
|
+
zod.z.literal("SUCCEEDED"),
|
|
1401
|
+
zod.z.literal("FAILED"),
|
|
1402
|
+
zod.z.literal("VOIDED"),
|
|
1403
|
+
zod.z.literal("CANCELED")
|
|
1404
|
+
]);
|
|
1405
|
+
// Channel Code (simplified - can be expanded)
|
|
1406
|
+
zod.z.string();
|
|
1407
|
+
// Channel Properties
|
|
1408
|
+
const ChannelPropertiesSchema = zod.z.record(zod.z.unknown());
|
|
1409
|
+
// Payment Method
|
|
1410
|
+
const PaymentMethodSchema = zod.z.object({
|
|
1411
|
+
type: zod.z.string(),
|
|
1412
|
+
card_information: zod.z.object({
|
|
1413
|
+
token_id: zod.z.string()
|
|
1414
|
+
}).optional(),
|
|
1415
|
+
ewallet: zod.z.object({
|
|
1416
|
+
channel_code: zod.z.string(),
|
|
1417
|
+
channel_properties: ChannelPropertiesSchema.optional()
|
|
1418
|
+
}).optional(),
|
|
1419
|
+
direct_debit: zod.z.object({
|
|
1420
|
+
channel_code: zod.z.string(),
|
|
1421
|
+
channel_properties: ChannelPropertiesSchema.optional()
|
|
1422
|
+
}).optional(),
|
|
1423
|
+
over_the_counter: zod.z.object({
|
|
1424
|
+
channel_code: zod.z.string(),
|
|
1425
|
+
channel_properties: ChannelPropertiesSchema.optional()
|
|
1426
|
+
}).optional(),
|
|
1427
|
+
qr_code: zod.z.object({
|
|
1428
|
+
channel_code: zod.z.string(),
|
|
1429
|
+
channel_properties: ChannelPropertiesSchema.optional()
|
|
1430
|
+
}).optional(),
|
|
1431
|
+
virtual_account: zod.z.object({
|
|
1432
|
+
channel_code: zod.z.string(),
|
|
1433
|
+
channel_properties: ChannelPropertiesSchema.optional()
|
|
1434
|
+
}).optional()
|
|
1435
|
+
});
|
|
1436
|
+
// Create Payment Request Schema
|
|
1437
|
+
const CreatePaymentRequestSchema = zod.z.object({
|
|
1438
|
+
reference_id: zod.z.string(),
|
|
1439
|
+
type: PaymentRequestTypeSchema,
|
|
1440
|
+
country: CountrySchema,
|
|
1441
|
+
currency: CurrencySchema,
|
|
1442
|
+
request_amount: zod.z.number().positive(),
|
|
1443
|
+
payment_method: PaymentMethodSchema,
|
|
1444
|
+
description: zod.z.string().optional(),
|
|
1445
|
+
metadata: zod.z.record(zod.z.unknown()).optional(),
|
|
1446
|
+
customer_id: zod.z.string().optional(),
|
|
1447
|
+
customer: zod.z.object({
|
|
1448
|
+
given_names: zod.z.string(),
|
|
1449
|
+
surname: zod.z.string().optional(),
|
|
1450
|
+
email: zod.z.string().email().optional(),
|
|
1451
|
+
mobile_number: zod.z.string().optional()
|
|
1452
|
+
}).optional(),
|
|
1453
|
+
shipping_information: zod.z.object({
|
|
1454
|
+
name: zod.z.string(),
|
|
1455
|
+
phone_number: zod.z.string().optional(),
|
|
1456
|
+
address: zod.z.string().optional(),
|
|
1457
|
+
city: zod.z.string().optional(),
|
|
1458
|
+
province: zod.z.string().optional(),
|
|
1459
|
+
postal_code: zod.z.string().optional(),
|
|
1460
|
+
country_code: CountrySchema.optional()
|
|
1461
|
+
}).optional(),
|
|
1462
|
+
items: zod.z.array(zod.z.object({
|
|
1463
|
+
name: zod.z.string(),
|
|
1464
|
+
quantity: zod.z.number().positive(),
|
|
1465
|
+
price: zod.z.number().positive(),
|
|
1466
|
+
category: zod.z.string().optional(),
|
|
1467
|
+
reference_id: zod.z.string().optional(),
|
|
1468
|
+
url: zod.z.string().url().optional()
|
|
1469
|
+
})).optional(),
|
|
1470
|
+
capture_method: CaptureMethodSchema.optional(),
|
|
1471
|
+
success_redirect_url: zod.z.string().url().optional(),
|
|
1472
|
+
failure_redirect_url: zod.z.string().url().optional()
|
|
1473
|
+
});
|
|
1474
|
+
// Payment Request Resource
|
|
1475
|
+
const PaymentRequestResourceSchema = zod.z.object({
|
|
1476
|
+
id: zod.z.string(),
|
|
1477
|
+
reference_id: zod.z.string(),
|
|
1478
|
+
type: PaymentRequestTypeSchema,
|
|
1479
|
+
country: CountrySchema,
|
|
1480
|
+
currency: CurrencySchema,
|
|
1481
|
+
request_amount: zod.z.number(),
|
|
1482
|
+
paid_amount: zod.z.number().optional(),
|
|
1483
|
+
status: PaymentRequestStatusSchema,
|
|
1484
|
+
payment_method: PaymentMethodSchema,
|
|
1485
|
+
description: zod.z.string().optional(),
|
|
1486
|
+
metadata: zod.z.record(zod.z.unknown()).optional(),
|
|
1487
|
+
customer_id: zod.z.string().optional(),
|
|
1488
|
+
customer: zod.z.object({
|
|
1489
|
+
given_names: zod.z.string(),
|
|
1490
|
+
surname: zod.z.string().optional(),
|
|
1491
|
+
email: zod.z.string().email().optional(),
|
|
1492
|
+
mobile_number: zod.z.string().optional()
|
|
1493
|
+
}).optional(),
|
|
1494
|
+
shipping_information: zod.z.object({
|
|
1495
|
+
name: zod.z.string(),
|
|
1496
|
+
phone_number: zod.z.string().optional(),
|
|
1497
|
+
address: zod.z.string().optional(),
|
|
1498
|
+
city: zod.z.string().optional(),
|
|
1499
|
+
province: zod.z.string().optional(),
|
|
1500
|
+
postal_code: zod.z.string().optional(),
|
|
1501
|
+
country_code: CountrySchema.optional()
|
|
1502
|
+
}).optional(),
|
|
1503
|
+
items: zod.z.array(zod.z.object({
|
|
1504
|
+
name: zod.z.string(),
|
|
1505
|
+
quantity: zod.z.number().positive(),
|
|
1506
|
+
price: zod.z.number().positive(),
|
|
1507
|
+
category: zod.z.string().optional(),
|
|
1508
|
+
reference_id: zod.z.string().optional(),
|
|
1509
|
+
url: zod.z.string().url().optional()
|
|
1510
|
+
})).optional(),
|
|
1511
|
+
actions: zod.z.object({
|
|
1512
|
+
desktop_web_checkout_url: zod.z.string().url().optional(),
|
|
1513
|
+
mobile_web_checkout_url: zod.z.string().url().optional(),
|
|
1514
|
+
mobile_deeplink_checkout_url: zod.z.string().url().optional(),
|
|
1515
|
+
qr_checkout_string: zod.z.string().optional()
|
|
1516
|
+
}).optional(),
|
|
1517
|
+
created: zod.z.string().datetime(),
|
|
1518
|
+
updated: zod.z.string().datetime(),
|
|
1519
|
+
failure_reason: zod.z.string().optional(),
|
|
1520
|
+
payment_request_id: zod.z.string().optional()
|
|
1521
|
+
});
|
|
1522
|
+
// Get Payment Request Schema
|
|
1523
|
+
const GetPaymentRequestSchema = zod.z.object({
|
|
1524
|
+
id: zod.z.string()
|
|
1525
|
+
});
|
|
1526
|
+
// List Payment Requests Schema
|
|
1527
|
+
const ListPaymentRequestsSchema = zod.z.object({
|
|
1528
|
+
reference_id: zod.z.string().optional(),
|
|
1529
|
+
customer_id: zod.z.string().optional(),
|
|
1530
|
+
status: zod.z.array(PaymentRequestStatusSchema).optional(),
|
|
1531
|
+
limit: zod.z.number().min(1).max(100).optional(),
|
|
1532
|
+
after_id: zod.z.string().optional(),
|
|
1533
|
+
before_id: zod.z.string().optional(),
|
|
1534
|
+
created_after: zod.z.string().datetime().optional(),
|
|
1535
|
+
created_before: zod.z.string().datetime().optional()
|
|
1536
|
+
});
|
|
1537
|
+
// List Payment Requests Response
|
|
1538
|
+
zod.z.object({
|
|
1539
|
+
data: zod.z.array(PaymentRequestResourceSchema),
|
|
1540
|
+
has_more: zod.z.boolean(),
|
|
1541
|
+
links: zod.z.array(zod.z.object({
|
|
1542
|
+
href: zod.z.string(),
|
|
1543
|
+
rel: zod.z.string(),
|
|
1544
|
+
method: zod.z.string()
|
|
1545
|
+
})).optional()
|
|
1546
|
+
});
|
|
1547
|
+
|
|
1548
|
+
const createPaymentRequest = async (params, axiosInstance, config)=>{
|
|
1549
|
+
try {
|
|
1550
|
+
const validatedParams = validateInput(CreatePaymentRequestSchema, params, "payment request params");
|
|
1551
|
+
const response = await axiosInstance.post(config?.url ?? "/v3/payment_requests", validatedParams, {
|
|
1552
|
+
...config,
|
|
1553
|
+
headers: {
|
|
1554
|
+
"api-version": "2024-11-11",
|
|
1555
|
+
...config?.headers
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
return validateInput(PaymentRequestResourceSchema, response.data, "payment request response");
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1561
|
+
handleAxiosError(error);
|
|
1562
|
+
}
|
|
1563
|
+
throw error;
|
|
1162
1564
|
}
|
|
1163
|
-
return window.btoa(string);
|
|
1164
1565
|
};
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1566
|
+
const getPaymentRequest = async (params, axiosInstance, config)=>{
|
|
1567
|
+
try {
|
|
1568
|
+
const validatedParams = validateInput(GetPaymentRequestSchema, params, "get payment request params");
|
|
1569
|
+
const response = await axiosInstance.get(config?.url ?? `/v3/payment_requests/${validatedParams.id}`, {
|
|
1570
|
+
...config,
|
|
1571
|
+
headers: {
|
|
1572
|
+
"api-version": "2024-11-11",
|
|
1573
|
+
...config?.headers
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
return validateInput(PaymentRequestResourceSchema, response.data, "payment request response");
|
|
1577
|
+
} catch (error) {
|
|
1578
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1579
|
+
handleAxiosError(error);
|
|
1580
|
+
}
|
|
1581
|
+
throw error;
|
|
1582
|
+
}
|
|
1167
1583
|
};
|
|
1168
|
-
const
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1584
|
+
const listPaymentRequests = async (params, axiosInstance, config)=>{
|
|
1585
|
+
try {
|
|
1586
|
+
const validatedParams = params ? validateInput(ListPaymentRequestsSchema, params, "list payment requests params") : {};
|
|
1587
|
+
const queryParams = new URLSearchParams();
|
|
1588
|
+
if (validatedParams.reference_id) {
|
|
1589
|
+
queryParams.append("reference_id", validatedParams.reference_id);
|
|
1172
1590
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1591
|
+
if (validatedParams.customer_id) {
|
|
1592
|
+
queryParams.append("customer_id", validatedParams.customer_id);
|
|
1593
|
+
}
|
|
1594
|
+
if (validatedParams.status) {
|
|
1595
|
+
validatedParams.status.forEach((status)=>queryParams.append("status[]", status));
|
|
1596
|
+
}
|
|
1597
|
+
if (validatedParams.limit) {
|
|
1598
|
+
queryParams.append("limit", validatedParams.limit.toString());
|
|
1599
|
+
}
|
|
1600
|
+
if (validatedParams.after_id) {
|
|
1601
|
+
queryParams.append("after_id", validatedParams.after_id);
|
|
1602
|
+
}
|
|
1603
|
+
if (validatedParams.before_id) {
|
|
1604
|
+
queryParams.append("before_id", validatedParams.before_id);
|
|
1605
|
+
}
|
|
1606
|
+
if (validatedParams.created_after) {
|
|
1607
|
+
queryParams.append("created_after", validatedParams.created_after);
|
|
1608
|
+
}
|
|
1609
|
+
if (validatedParams.created_before) {
|
|
1610
|
+
queryParams.append("created_before", validatedParams.created_before);
|
|
1611
|
+
}
|
|
1612
|
+
const queryString = queryParams.toString();
|
|
1613
|
+
const url = queryString ? `/v3/payment_requests?${queryString}` : "/v3/payment_requests";
|
|
1614
|
+
if (!axiosInstance) {
|
|
1615
|
+
throw new Error("axiosInstance is required");
|
|
1616
|
+
}
|
|
1617
|
+
const response = await axiosInstance.get(config?.url ?? url, {
|
|
1618
|
+
...config,
|
|
1619
|
+
headers: {
|
|
1620
|
+
"api-version": "2024-11-11",
|
|
1621
|
+
...config?.headers
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
return response.data;
|
|
1625
|
+
} catch (error) {
|
|
1626
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1627
|
+
handleAxiosError(error);
|
|
1628
|
+
}
|
|
1629
|
+
throw error;
|
|
1177
1630
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
// Refund Reason
|
|
1634
|
+
const RefundReasonSchema = zod.z.union([
|
|
1635
|
+
zod.z.literal("REQUESTED_BY_CUSTOMER"),
|
|
1636
|
+
zod.z.literal("FRAUDULENT"),
|
|
1637
|
+
zod.z.literal("DUPLICATE"),
|
|
1638
|
+
zod.z.literal("CANCELLATION"),
|
|
1639
|
+
zod.z.literal("OTHERS")
|
|
1640
|
+
]);
|
|
1641
|
+
// Refund Status
|
|
1642
|
+
const RefundStatusSchema = zod.z.union([
|
|
1643
|
+
zod.z.literal("PENDING"),
|
|
1644
|
+
zod.z.literal("SUCCEEDED"),
|
|
1645
|
+
zod.z.literal("FAILED")
|
|
1646
|
+
]);
|
|
1647
|
+
// Create Refund Schema
|
|
1648
|
+
const CreateRefundSchema = zod.z.object({
|
|
1649
|
+
payment_request_id: zod.z.string(),
|
|
1650
|
+
amount: zod.z.number().positive().optional(),
|
|
1651
|
+
reason: RefundReasonSchema,
|
|
1652
|
+
metadata: zod.z.record(zod.z.unknown()).optional()
|
|
1653
|
+
});
|
|
1654
|
+
// Refund Resource
|
|
1655
|
+
const RefundResourceSchema = zod.z.object({
|
|
1656
|
+
id: zod.z.string(),
|
|
1657
|
+
payment_request_id: zod.z.string(),
|
|
1658
|
+
amount: zod.z.number(),
|
|
1659
|
+
currency: zod.z.string(),
|
|
1660
|
+
reason: RefundReasonSchema,
|
|
1661
|
+
status: RefundStatusSchema,
|
|
1662
|
+
metadata: zod.z.record(zod.z.unknown()).optional(),
|
|
1663
|
+
created: zod.z.string().datetime(),
|
|
1664
|
+
updated: zod.z.string().datetime(),
|
|
1665
|
+
failure_reason: zod.z.string().optional()
|
|
1666
|
+
});
|
|
1667
|
+
// Get Refund Schema
|
|
1668
|
+
const GetRefundSchema = zod.z.object({
|
|
1669
|
+
id: zod.z.string()
|
|
1670
|
+
});
|
|
1671
|
+
// List Refunds Schema
|
|
1672
|
+
const ListRefundsSchema = zod.z.object({
|
|
1673
|
+
payment_request_id: zod.z.string().optional(),
|
|
1674
|
+
limit: zod.z.number().min(1).max(100).optional(),
|
|
1675
|
+
after_id: zod.z.string().optional(),
|
|
1676
|
+
before_id: zod.z.string().optional(),
|
|
1677
|
+
created_after: zod.z.string().datetime().optional(),
|
|
1678
|
+
created_before: zod.z.string().datetime().optional()
|
|
1679
|
+
});
|
|
1680
|
+
// List Refunds Response
|
|
1681
|
+
zod.z.object({
|
|
1682
|
+
data: zod.z.array(RefundResourceSchema),
|
|
1683
|
+
has_more: zod.z.boolean(),
|
|
1684
|
+
links: zod.z.array(zod.z.object({
|
|
1685
|
+
href: zod.z.string(),
|
|
1686
|
+
rel: zod.z.string(),
|
|
1687
|
+
method: zod.z.string()
|
|
1688
|
+
})).optional()
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
const createRefund = async (params, axiosInstance, config)=>{
|
|
1692
|
+
try {
|
|
1693
|
+
const validatedParams = validateInput(CreateRefundSchema, params, "refund params");
|
|
1694
|
+
const response = await axiosInstance.post(config?.url ?? "/v3/refunds", validatedParams, {
|
|
1695
|
+
...config,
|
|
1696
|
+
headers: {
|
|
1697
|
+
"api-version": "2024-11-11",
|
|
1698
|
+
...config?.headers
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
return validateInput(RefundResourceSchema, response.data, "refund response");
|
|
1702
|
+
} catch (error) {
|
|
1703
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1704
|
+
handleAxiosError(error);
|
|
1705
|
+
}
|
|
1706
|
+
throw error;
|
|
1180
1707
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1708
|
+
};
|
|
1709
|
+
const getRefund = async (params, axiosInstance, config)=>{
|
|
1710
|
+
try {
|
|
1711
|
+
const validatedParams = validateInput(GetRefundSchema, params, "get refund params");
|
|
1712
|
+
const response = await axiosInstance.get(config?.url ?? `/v3/refunds/${validatedParams.id}`, {
|
|
1713
|
+
...config,
|
|
1714
|
+
headers: {
|
|
1715
|
+
"api-version": "2024-11-11",
|
|
1716
|
+
...config?.headers
|
|
1717
|
+
}
|
|
1718
|
+
});
|
|
1719
|
+
return validateInput(RefundResourceSchema, response.data, "refund response");
|
|
1720
|
+
} catch (error) {
|
|
1721
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1722
|
+
handleAxiosError(error);
|
|
1723
|
+
}
|
|
1724
|
+
throw error;
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
const listRefunds = async (params, axiosInstance, config)=>{
|
|
1728
|
+
try {
|
|
1729
|
+
const validatedParams = params ? validateInput(ListRefundsSchema, params, "list refunds params") : {};
|
|
1730
|
+
const queryParams = new URLSearchParams();
|
|
1731
|
+
if (validatedParams.payment_request_id) {
|
|
1732
|
+
queryParams.append("payment_request_id", validatedParams.payment_request_id);
|
|
1733
|
+
}
|
|
1734
|
+
if (validatedParams.limit) {
|
|
1735
|
+
queryParams.append("limit", validatedParams.limit.toString());
|
|
1736
|
+
}
|
|
1737
|
+
if (validatedParams.after_id) {
|
|
1738
|
+
queryParams.append("after_id", validatedParams.after_id);
|
|
1739
|
+
}
|
|
1740
|
+
if (validatedParams.before_id) {
|
|
1741
|
+
queryParams.append("before_id", validatedParams.before_id);
|
|
1742
|
+
}
|
|
1743
|
+
if (validatedParams.created_after) {
|
|
1744
|
+
queryParams.append("created_after", validatedParams.created_after);
|
|
1745
|
+
}
|
|
1746
|
+
if (validatedParams.created_before) {
|
|
1747
|
+
queryParams.append("created_before", validatedParams.created_before);
|
|
1748
|
+
}
|
|
1749
|
+
const queryString = queryParams.toString();
|
|
1750
|
+
const url = queryString ? `/v3/refunds?${queryString}` : "/v3/refunds";
|
|
1751
|
+
if (!axiosInstance) {
|
|
1752
|
+
throw new Error("axiosInstance is required");
|
|
1753
|
+
}
|
|
1754
|
+
const response = await axiosInstance.get(config?.url ?? url, {
|
|
1755
|
+
...config,
|
|
1756
|
+
headers: {
|
|
1757
|
+
"api-version": "2024-11-11",
|
|
1758
|
+
...config?.headers
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1761
|
+
return response.data;
|
|
1762
|
+
} catch (error) {
|
|
1763
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1764
|
+
handleAxiosError(error);
|
|
1765
|
+
}
|
|
1766
|
+
throw error;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
|
|
1770
|
+
// Payout Status
|
|
1771
|
+
const PayoutStatusSchema = zod.z.union([
|
|
1772
|
+
zod.z.literal("ACCEPTED"),
|
|
1773
|
+
zod.z.literal("PENDING"),
|
|
1774
|
+
zod.z.literal("PROCESSING"),
|
|
1775
|
+
zod.z.literal("COMPLETED"),
|
|
1776
|
+
zod.z.literal("FAILED"),
|
|
1777
|
+
zod.z.literal("CANCELLED"),
|
|
1778
|
+
zod.z.literal("REVERSED")
|
|
1779
|
+
]);
|
|
1780
|
+
// Payout Channel Code
|
|
1781
|
+
const PayoutChannelCodeSchema = zod.z.union([
|
|
1782
|
+
zod.z.literal("BANK"),
|
|
1783
|
+
zod.z.literal("EWALLET"),
|
|
1784
|
+
zod.z.literal("CASH")
|
|
1785
|
+
]);
|
|
1786
|
+
// Bank Account
|
|
1787
|
+
const BankAccountSchema = zod.z.object({
|
|
1788
|
+
account_holder_name: zod.z.string(),
|
|
1789
|
+
account_number: zod.z.string(),
|
|
1790
|
+
bank_code: zod.z.string(),
|
|
1791
|
+
account_type: zod.z.string().optional()
|
|
1792
|
+
});
|
|
1793
|
+
// E-wallet Account
|
|
1794
|
+
const EwalletAccountSchema = zod.z.object({
|
|
1795
|
+
account_holder_name: zod.z.string(),
|
|
1796
|
+
account_number: zod.z.string(),
|
|
1797
|
+
ewallet_type: zod.z.string()
|
|
1798
|
+
});
|
|
1799
|
+
// Payout Method
|
|
1800
|
+
const PayoutMethodSchema = zod.z.discriminatedUnion("channel_code", [
|
|
1801
|
+
zod.z.object({
|
|
1802
|
+
channel_code: zod.z.literal("BANK"),
|
|
1803
|
+
bank_account: BankAccountSchema
|
|
1804
|
+
}),
|
|
1805
|
+
zod.z.object({
|
|
1806
|
+
channel_code: zod.z.literal("EWALLET"),
|
|
1807
|
+
ewallet: EwalletAccountSchema
|
|
1808
|
+
}),
|
|
1809
|
+
zod.z.object({
|
|
1810
|
+
channel_code: zod.z.literal("CASH"),
|
|
1811
|
+
cash: zod.z.object({
|
|
1812
|
+
account_holder_name: zod.z.string(),
|
|
1813
|
+
account_number: zod.z.string()
|
|
1814
|
+
})
|
|
1815
|
+
})
|
|
1816
|
+
]);
|
|
1817
|
+
// Create Payout Schema
|
|
1818
|
+
const CreatePayoutSchema = zod.z.object({
|
|
1819
|
+
reference_id: zod.z.string(),
|
|
1820
|
+
channel_code: PayoutChannelCodeSchema,
|
|
1821
|
+
channel_properties: PayoutMethodSchema,
|
|
1822
|
+
amount: zod.z.number().positive(),
|
|
1823
|
+
currency: CurrencySchema,
|
|
1824
|
+
description: zod.z.string().optional(),
|
|
1825
|
+
metadata: zod.z.record(zod.z.unknown()).optional(),
|
|
1826
|
+
receipt_notification: zod.z.object({
|
|
1827
|
+
email_to: zod.z.array(zod.z.string().email()).optional(),
|
|
1828
|
+
email_cc: zod.z.array(zod.z.string().email()).optional(),
|
|
1829
|
+
email_bcc: zod.z.array(zod.z.string().email()).optional()
|
|
1830
|
+
}).optional()
|
|
1831
|
+
});
|
|
1832
|
+
// Payout Resource
|
|
1833
|
+
const PayoutResourceSchema = zod.z.object({
|
|
1834
|
+
id: zod.z.string(),
|
|
1835
|
+
reference_id: zod.z.string(),
|
|
1836
|
+
channel_code: PayoutChannelCodeSchema,
|
|
1837
|
+
channel_properties: PayoutMethodSchema,
|
|
1838
|
+
amount: zod.z.number(),
|
|
1839
|
+
currency: CurrencySchema,
|
|
1840
|
+
status: PayoutStatusSchema,
|
|
1841
|
+
description: zod.z.string().optional(),
|
|
1842
|
+
metadata: zod.z.record(zod.z.unknown()).optional(),
|
|
1843
|
+
created: zod.z.string().datetime(),
|
|
1844
|
+
updated: zod.z.string().datetime(),
|
|
1845
|
+
failure_reason: zod.z.string().optional(),
|
|
1846
|
+
estimated_arrival_time: zod.z.string().datetime().optional(),
|
|
1847
|
+
receipt_notification: zod.z.object({
|
|
1848
|
+
email_to: zod.z.array(zod.z.string().email()).optional(),
|
|
1849
|
+
email_cc: zod.z.array(zod.z.string().email()).optional(),
|
|
1850
|
+
email_bcc: zod.z.array(zod.z.string().email()).optional()
|
|
1851
|
+
}).optional()
|
|
1852
|
+
});
|
|
1853
|
+
// Get Payout Schema
|
|
1854
|
+
const GetPayoutSchema = zod.z.object({
|
|
1855
|
+
id: zod.z.string()
|
|
1856
|
+
});
|
|
1857
|
+
// List Payouts Schema
|
|
1858
|
+
const ListPayoutsSchema = zod.z.object({
|
|
1859
|
+
reference_id: zod.z.string().optional(),
|
|
1860
|
+
channel_code: zod.z.array(PayoutChannelCodeSchema).optional(),
|
|
1861
|
+
status: zod.z.array(PayoutStatusSchema).optional(),
|
|
1862
|
+
limit: zod.z.number().min(1).max(100).optional(),
|
|
1863
|
+
after_id: zod.z.string().optional(),
|
|
1864
|
+
before_id: zod.z.string().optional(),
|
|
1865
|
+
created_after: zod.z.string().datetime().optional(),
|
|
1866
|
+
created_before: zod.z.string().datetime().optional()
|
|
1867
|
+
});
|
|
1868
|
+
// List Payouts Response
|
|
1869
|
+
zod.z.object({
|
|
1870
|
+
data: zod.z.array(PayoutResourceSchema),
|
|
1871
|
+
has_more: zod.z.boolean(),
|
|
1872
|
+
links: zod.z.array(zod.z.object({
|
|
1873
|
+
href: zod.z.string(),
|
|
1874
|
+
rel: zod.z.string(),
|
|
1875
|
+
method: zod.z.string()
|
|
1876
|
+
})).optional()
|
|
1877
|
+
});
|
|
1878
|
+
// Cancel Payout Schema
|
|
1879
|
+
const CancelPayoutSchema = zod.z.object({
|
|
1880
|
+
id: zod.z.string()
|
|
1881
|
+
});
|
|
1882
|
+
|
|
1883
|
+
const createPayout = async (params, axiosInstance, config)=>{
|
|
1884
|
+
try {
|
|
1885
|
+
const validatedParams = validateInput(CreatePayoutSchema, params, "payout params");
|
|
1886
|
+
const response = await axiosInstance.post(config?.url ?? "/v2/payouts", validatedParams, config);
|
|
1887
|
+
return validateInput(PayoutResourceSchema, response.data, "payout response");
|
|
1888
|
+
} catch (error) {
|
|
1889
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1890
|
+
handleAxiosError(error);
|
|
1891
|
+
}
|
|
1892
|
+
throw error;
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
const getPayout = async (params, axiosInstance, config)=>{
|
|
1896
|
+
try {
|
|
1897
|
+
const validatedParams = validateInput(GetPayoutSchema, params, "get payout params");
|
|
1898
|
+
const response = await axiosInstance.get(config?.url ?? `/v2/payouts/${validatedParams.id}`, config);
|
|
1899
|
+
return validateInput(PayoutResourceSchema, response.data, "payout response");
|
|
1900
|
+
} catch (error) {
|
|
1901
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1902
|
+
handleAxiosError(error);
|
|
1903
|
+
}
|
|
1904
|
+
throw error;
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
const listPayouts = async (params, axiosInstance, config)=>{
|
|
1908
|
+
try {
|
|
1909
|
+
const validatedParams = params ? validateInput(ListPayoutsSchema, params, "list payouts params") : {};
|
|
1910
|
+
const queryParams = new URLSearchParams();
|
|
1911
|
+
if (validatedParams.reference_id) {
|
|
1912
|
+
queryParams.append("reference_id", validatedParams.reference_id);
|
|
1913
|
+
}
|
|
1914
|
+
if (validatedParams.channel_code) {
|
|
1915
|
+
validatedParams.channel_code.forEach((code)=>queryParams.append("channel_code[]", code));
|
|
1916
|
+
}
|
|
1917
|
+
if (validatedParams.status) {
|
|
1918
|
+
validatedParams.status.forEach((status)=>queryParams.append("status[]", status));
|
|
1919
|
+
}
|
|
1920
|
+
if (validatedParams.limit) {
|
|
1921
|
+
queryParams.append("limit", validatedParams.limit.toString());
|
|
1922
|
+
}
|
|
1923
|
+
if (validatedParams.after_id) {
|
|
1924
|
+
queryParams.append("after_id", validatedParams.after_id);
|
|
1925
|
+
}
|
|
1926
|
+
if (validatedParams.before_id) {
|
|
1927
|
+
queryParams.append("before_id", validatedParams.before_id);
|
|
1928
|
+
}
|
|
1929
|
+
if (validatedParams.created_after) {
|
|
1930
|
+
queryParams.append("created_after", validatedParams.created_after);
|
|
1931
|
+
}
|
|
1932
|
+
if (validatedParams.created_before) {
|
|
1933
|
+
queryParams.append("created_before", validatedParams.created_before);
|
|
1934
|
+
}
|
|
1935
|
+
const queryString = queryParams.toString();
|
|
1936
|
+
const url = queryString ? `/v2/payouts?${queryString}` : "/v2/payouts";
|
|
1937
|
+
if (!axiosInstance) {
|
|
1938
|
+
throw new Error("axiosInstance is required");
|
|
1939
|
+
}
|
|
1940
|
+
const response = await axiosInstance.get(config?.url ?? url, config);
|
|
1941
|
+
return response.data;
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1944
|
+
handleAxiosError(error);
|
|
1945
|
+
}
|
|
1946
|
+
throw error;
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
const cancelPayout = async (params, axiosInstance, config)=>{
|
|
1950
|
+
try {
|
|
1951
|
+
const validatedParams = validateInput(CancelPayoutSchema, params, "cancel payout params");
|
|
1952
|
+
const response = await axiosInstance.post(config?.url ?? `/v2/payouts/${validatedParams.id}/cancel`, {}, config);
|
|
1953
|
+
return validateInput(PayoutResourceSchema, response.data, "payout response");
|
|
1954
|
+
} catch (error) {
|
|
1955
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
1956
|
+
handleAxiosError(error);
|
|
1957
|
+
}
|
|
1958
|
+
throw error;
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1962
|
+
// Balance Resource
|
|
1963
|
+
const BalanceResourceSchema = zod.z.object({
|
|
1964
|
+
balance: zod.z.number(),
|
|
1965
|
+
currency: CurrencySchema,
|
|
1966
|
+
account_type: zod.z.string().optional()
|
|
1967
|
+
});
|
|
1968
|
+
// Transaction Type
|
|
1969
|
+
const TransactionTypeSchema = zod.z.union([
|
|
1970
|
+
zod.z.literal("PAYMENT"),
|
|
1971
|
+
zod.z.literal("PAYOUT"),
|
|
1972
|
+
zod.z.literal("REFUND"),
|
|
1973
|
+
zod.z.literal("FEE"),
|
|
1974
|
+
zod.z.literal("ADJUSTMENT")
|
|
1975
|
+
]);
|
|
1976
|
+
// Transaction Status
|
|
1977
|
+
const TransactionStatusSchema = zod.z.union([
|
|
1978
|
+
zod.z.literal("PENDING"),
|
|
1979
|
+
zod.z.literal("SUCCEEDED"),
|
|
1980
|
+
zod.z.literal("FAILED"),
|
|
1981
|
+
zod.z.literal("CANCELLED")
|
|
1982
|
+
]);
|
|
1983
|
+
// Transaction Resource
|
|
1984
|
+
const TransactionResourceSchema = zod.z.object({
|
|
1985
|
+
id: zod.z.string(),
|
|
1986
|
+
reference_id: zod.z.string().optional(),
|
|
1987
|
+
type: TransactionTypeSchema,
|
|
1988
|
+
status: TransactionStatusSchema,
|
|
1989
|
+
amount: zod.z.number(),
|
|
1990
|
+
currency: CurrencySchema,
|
|
1991
|
+
created: zod.z.string().datetime(),
|
|
1992
|
+
updated: zod.z.string().datetime(),
|
|
1993
|
+
description: zod.z.string().optional(),
|
|
1994
|
+
metadata: zod.z.record(zod.z.unknown()).optional()
|
|
1995
|
+
});
|
|
1996
|
+
// List Transactions Schema
|
|
1997
|
+
const ListTransactionsSchema = zod.z.object({
|
|
1998
|
+
types: zod.z.array(TransactionTypeSchema).optional(),
|
|
1999
|
+
statuses: zod.z.array(TransactionStatusSchema).optional(),
|
|
2000
|
+
limit: zod.z.number().min(1).max(100).optional(),
|
|
2001
|
+
after_id: zod.z.string().optional(),
|
|
2002
|
+
before_id: zod.z.string().optional(),
|
|
2003
|
+
created_after: zod.z.string().datetime().optional(),
|
|
2004
|
+
created_before: zod.z.string().datetime().optional()
|
|
2005
|
+
});
|
|
2006
|
+
// List Transactions Response
|
|
2007
|
+
zod.z.object({
|
|
2008
|
+
data: zod.z.array(TransactionResourceSchema),
|
|
2009
|
+
has_more: zod.z.boolean(),
|
|
2010
|
+
links: zod.z.array(zod.z.object({
|
|
2011
|
+
href: zod.z.string(),
|
|
2012
|
+
rel: zod.z.string(),
|
|
2013
|
+
method: zod.z.string()
|
|
2014
|
+
})).optional()
|
|
2015
|
+
});
|
|
2016
|
+
|
|
2017
|
+
const getBalance = async (axiosInstance, config)=>{
|
|
2018
|
+
try {
|
|
2019
|
+
const response = await axiosInstance.get(config?.url ?? "/balance", config);
|
|
2020
|
+
return validateInput(BalanceResourceSchema, response.data, "balance response");
|
|
2021
|
+
} catch (error) {
|
|
2022
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2023
|
+
handleAxiosError(error);
|
|
2024
|
+
}
|
|
2025
|
+
throw error;
|
|
2026
|
+
}
|
|
2027
|
+
};
|
|
2028
|
+
const listTransactions = async (params, axiosInstance, config)=>{
|
|
2029
|
+
try {
|
|
2030
|
+
const validatedParams = params ? validateInput(ListTransactionsSchema, params, "list transactions params") : {};
|
|
2031
|
+
const queryParams = new URLSearchParams();
|
|
2032
|
+
if (validatedParams.types) {
|
|
2033
|
+
validatedParams.types.forEach((type)=>queryParams.append("types[]", type));
|
|
2034
|
+
}
|
|
2035
|
+
if (validatedParams.statuses) {
|
|
2036
|
+
validatedParams.statuses.forEach((status)=>queryParams.append("statuses[]", status));
|
|
2037
|
+
}
|
|
2038
|
+
if (validatedParams.limit) {
|
|
2039
|
+
queryParams.append("limit", validatedParams.limit.toString());
|
|
2040
|
+
}
|
|
2041
|
+
if (validatedParams.after_id) {
|
|
2042
|
+
queryParams.append("after_id", validatedParams.after_id);
|
|
2043
|
+
}
|
|
2044
|
+
if (validatedParams.before_id) {
|
|
2045
|
+
queryParams.append("before_id", validatedParams.before_id);
|
|
2046
|
+
}
|
|
2047
|
+
if (validatedParams.created_after) {
|
|
2048
|
+
queryParams.append("created_after", validatedParams.created_after);
|
|
2049
|
+
}
|
|
2050
|
+
if (validatedParams.created_before) {
|
|
2051
|
+
queryParams.append("created_before", validatedParams.created_before);
|
|
2052
|
+
}
|
|
2053
|
+
const queryString = queryParams.toString();
|
|
2054
|
+
const url = queryString ? `/transactions?${queryString}` : "/transactions";
|
|
2055
|
+
if (!axiosInstance) {
|
|
2056
|
+
throw new Error("axiosInstance is required");
|
|
2057
|
+
}
|
|
2058
|
+
const response = await axiosInstance.get(config?.url ?? url, config);
|
|
2059
|
+
return response.data;
|
|
2060
|
+
} catch (error) {
|
|
2061
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2062
|
+
handleAxiosError(error);
|
|
2063
|
+
}
|
|
2064
|
+
throw error;
|
|
2065
|
+
}
|
|
2066
|
+
};
|
|
2067
|
+
|
|
2068
|
+
const CardDataSchema = zod.z.object({
|
|
2069
|
+
account_number: zod.z.string(),
|
|
2070
|
+
exp_month: zod.z.string(),
|
|
2071
|
+
exp_year: zod.z.string(),
|
|
2072
|
+
card_holder_first_name: zod.z.string(),
|
|
2073
|
+
card_holder_last_name: zod.z.string(),
|
|
2074
|
+
card_holder_email: zod.z.string().email(),
|
|
2075
|
+
card_holder_phone_number: PhoneSchema
|
|
2076
|
+
});
|
|
2077
|
+
const TokenParamsSchema = zod.z.object({
|
|
2078
|
+
amount: zod.z.string().optional(),
|
|
2079
|
+
card_data: CardDataSchema.optional(),
|
|
2080
|
+
external_id: zod.z.string().optional(),
|
|
2081
|
+
card_cvn: zod.z.string().min(3).max(3).optional(),
|
|
2082
|
+
is_multiple_use: zod.z.boolean().optional().default(false),
|
|
2083
|
+
currency: CurrencySchema.optional(),
|
|
2084
|
+
should_authenticate: zod.z.boolean().default(true),
|
|
2085
|
+
billing_details: AddressSchema.optional(),
|
|
2086
|
+
mid_label: zod.z.string()
|
|
2087
|
+
});
|
|
2088
|
+
const TokenStatusSchema = zod.z.union([
|
|
2089
|
+
zod.z.literal("IN_REVIEW"),
|
|
2090
|
+
zod.z.literal("VERIFIED"),
|
|
2091
|
+
zod.z.literal("FAILED"),
|
|
2092
|
+
zod.z.literal("SUCCEEDED"),
|
|
2093
|
+
zod.z.literal("CAPTURED"),
|
|
2094
|
+
zod.z.literal("REVERSED"),
|
|
2095
|
+
zod.z.literal("AUTHORISED")
|
|
2096
|
+
]);
|
|
2097
|
+
const CardTypeSchema = zod.z.union([
|
|
2098
|
+
zod.z.literal("CREDIT"),
|
|
2099
|
+
zod.z.literal("DEBIT"),
|
|
2100
|
+
zod.z.literal("PREPAID"),
|
|
2101
|
+
zod.z.literal("UNKNOWN")
|
|
2102
|
+
]);
|
|
2103
|
+
const CardBrandSchema = zod.z.union([
|
|
2104
|
+
zod.z.literal("VISA"),
|
|
2105
|
+
zod.z.literal("MASTERCARD"),
|
|
2106
|
+
zod.z.literal("JCB"),
|
|
2107
|
+
zod.z.literal("AMEX")
|
|
2108
|
+
]);
|
|
2109
|
+
const TokenFailureReasonSchema = zod.z.union([
|
|
2110
|
+
zod.z.literal("AUTHENTICATION_FAILED"),
|
|
2111
|
+
zod.z.literal("REVERSE_AUTHORIZATION_REJECTED_BY_BANK"),
|
|
2112
|
+
zod.z.literal("PROCESSOR_ERROR")
|
|
2113
|
+
]);
|
|
2114
|
+
zod.z.union([
|
|
2115
|
+
zod.z.literal("API_VALIDATION_ERROR"),
|
|
2116
|
+
zod.z.literal("INVALID_JSON_FORMAT"),
|
|
2117
|
+
zod.z.literal("ACCOUNT_NUMBER_INVALID_ERROR"),
|
|
2118
|
+
zod.z.literal("VALIDATION_ERROR"),
|
|
2119
|
+
zod.z.literal("BRAND_NOT_SUPPORTED_ERROR"),
|
|
2120
|
+
zod.z.literal("AUTHENTICATION_REQUIRED_ERROR"),
|
|
2121
|
+
zod.z.literal("REQUEST_FORBIDDEN_ERROR"),
|
|
2122
|
+
zod.z.literal("VERIFICATION_TIMEOUT_ERROR"),
|
|
2123
|
+
zod.z.literal("TEMPORARY_SERVICE_ERROR"),
|
|
2124
|
+
zod.z.literal("CONNECTION_ERROR")
|
|
2125
|
+
]);
|
|
2126
|
+
const CardInfoSchema = zod.z.object({
|
|
2127
|
+
bank: zod.z.string().optional(),
|
|
2128
|
+
country: CountrySchema.optional(),
|
|
2129
|
+
type: CardTypeSchema.optional(),
|
|
2130
|
+
brand: CardBrandSchema.optional(),
|
|
2131
|
+
fingerprint: zod.z.string().optional(),
|
|
2132
|
+
card_art_url: zod.z.string().url().optional()
|
|
2133
|
+
});
|
|
2134
|
+
const TokenResourceSchema = zod.z.object({
|
|
2135
|
+
id: zod.z.string(),
|
|
2136
|
+
business_id: zod.z.string().optional(),
|
|
2137
|
+
created: zod.z.string().datetime(),
|
|
2138
|
+
authentication_id: zod.z.string(),
|
|
2139
|
+
external_id: zod.z.string(),
|
|
2140
|
+
masked_card_number: zod.z.string(),
|
|
2141
|
+
status: zod.z.string(),
|
|
2142
|
+
payer_authentication_url: zod.z.string().url().optional(),
|
|
2143
|
+
failure_reason: zod.z.string().optional(),
|
|
2144
|
+
card_info: CardInfoSchema.optional()
|
|
2145
|
+
});
|
|
2146
|
+
const GetTokemParamsSchema = zod.z.object({
|
|
2147
|
+
credit_card_token_id: zod.z.string()
|
|
2148
|
+
});
|
|
2149
|
+
const TokenAuthenticationSchema = zod.z.object({
|
|
2150
|
+
amount: zod.z.string().optional(),
|
|
2151
|
+
token_id: zod.z.string().optional(),
|
|
2152
|
+
card_data: CardDataSchema.optional(),
|
|
2153
|
+
external_id: zod.z.string().optional(),
|
|
2154
|
+
currency: CurrencySchema.optional(),
|
|
2155
|
+
mid_label: zod.z.string().optional()
|
|
2156
|
+
});
|
|
2157
|
+
const TokenAuthenticationResourceSchema = zod.z.object({
|
|
2158
|
+
id: zod.z.string(),
|
|
2159
|
+
status: TokenStatusSchema,
|
|
2160
|
+
external_id: zod.z.string().optional(),
|
|
2161
|
+
payer_authentication_url: zod.z.string().url().optional(),
|
|
2162
|
+
mid_label: zod.z.string().optional(),
|
|
2163
|
+
failure_reason: TokenFailureReasonSchema.optional()
|
|
2164
|
+
});
|
|
2165
|
+
const TokenAuthorizationSchema = zod.z.object({
|
|
2166
|
+
amount: zod.z.string().optional(),
|
|
2167
|
+
token_id: zod.z.string().optional(),
|
|
2168
|
+
capture: zod.z.boolean().default(false),
|
|
2169
|
+
external_id: zod.z.string().optional(),
|
|
2170
|
+
authentication_id: zod.z.string().optional()
|
|
2171
|
+
});
|
|
2172
|
+
const ZeroAuthorizationSchema = zod.z.object({
|
|
2173
|
+
amount: zod.z.string().default("0"),
|
|
2174
|
+
token_id: zod.z.string().optional(),
|
|
2175
|
+
capture: zod.z.boolean().default(false),
|
|
2176
|
+
external_id: zod.z.string().optional(),
|
|
2177
|
+
authentication_id: zod.z.string().optional()
|
|
2178
|
+
});
|
|
2179
|
+
const ReverseAuthorizationSchema = zod.z.object({
|
|
2180
|
+
external_id: zod.z.string()
|
|
2181
|
+
});
|
|
2182
|
+
const PromotionSummarySchema = zod.z.object({
|
|
2183
|
+
reference_id: zod.z.string(),
|
|
2184
|
+
original_amount: zod.z.number()
|
|
2185
|
+
});
|
|
2186
|
+
const IntervalSchema = zod.z.literal("month");
|
|
2187
|
+
const InstallmentSummary = zod.z.object({
|
|
2188
|
+
count: zod.z.number().optional(),
|
|
2189
|
+
interval: IntervalSchema.optional()
|
|
2190
|
+
});
|
|
2191
|
+
const ECICodeSchema = zod.z.union([
|
|
2192
|
+
zod.z.literal("0"),
|
|
2193
|
+
zod.z.literal("1"),
|
|
2194
|
+
zod.z.literal("2"),
|
|
2195
|
+
zod.z.literal("3"),
|
|
2196
|
+
zod.z.literal("4"),
|
|
2197
|
+
zod.z.literal("5")
|
|
2198
|
+
]);
|
|
2199
|
+
const CVNCodeSchema = zod.z.union([
|
|
2200
|
+
zod.z.literal("M"),
|
|
2201
|
+
zod.z.literal("N"),
|
|
2202
|
+
zod.z.literal("P")
|
|
2203
|
+
]);
|
|
2204
|
+
const CreateChargeSchema = zod.z.object({
|
|
2205
|
+
token_id: zod.z.string(),
|
|
2206
|
+
external_id: zod.z.string(),
|
|
2207
|
+
amount: zod.z.number(),
|
|
2208
|
+
authentication_id: zod.z.string().optional(),
|
|
2209
|
+
capture: zod.z.boolean().optional().default(false),
|
|
2210
|
+
descriptor: zod.z.string().optional(),
|
|
2211
|
+
currency: CurrencySchema.optional(),
|
|
2212
|
+
mid_label: zod.z.string().optional(),
|
|
2213
|
+
billing_details: BillingDetailSchema.optional(),
|
|
2214
|
+
promotion: PromotionSummarySchema.optional(),
|
|
2215
|
+
installment: InstallmentSummary.optional(),
|
|
2216
|
+
metadata: zod.z.object({}).optional()
|
|
2217
|
+
});
|
|
2218
|
+
const ChargeFailureReasonSchema = zod.z.union([
|
|
2219
|
+
zod.z.literal("AUTHENTICATION_FAILED"),
|
|
2220
|
+
zod.z.literal("DECLINED_BY_ISSUER"),
|
|
2221
|
+
zod.z.literal("DECLINED_BY_PROCESSOR"),
|
|
2222
|
+
zod.z.literal("EXPIRED_CARD"),
|
|
2223
|
+
zod.z.literal("ISSUER_SUSPECT_FRAUD"),
|
|
2224
|
+
zod.z.literal("INACTIVE_OR_UNAUTHORIZED_CARD"),
|
|
2225
|
+
zod.z.literal("INSUFFICIENT_BALANCE"),
|
|
2226
|
+
zod.z.literal("INVALID_CARD"),
|
|
2227
|
+
zod.z.literal("INVALID_CVV"),
|
|
2228
|
+
zod.z.literal("ISSUER_UNAVAILABLE"),
|
|
2229
|
+
zod.z.literal("PROCESSOR_ERROR"),
|
|
2230
|
+
zod.z.literal("STOLEN_CARD"),
|
|
2231
|
+
zod.z.literal("PROCESSOR_TIMEOUT"),
|
|
2232
|
+
zod.z.literal("FRAUD_RISK_BLOCKED")
|
|
2233
|
+
]);
|
|
2234
|
+
const ChargeTypeSchema = zod.z.union([
|
|
2235
|
+
zod.z.literal("SINGLE_USE_TOKEN"),
|
|
2236
|
+
zod.z.literal("MULTIPLE_USE_TOKEN"),
|
|
2237
|
+
zod.z.literal("RECURRING")
|
|
2238
|
+
]);
|
|
2239
|
+
const ChargeResourceSchema = zod.z.object({
|
|
2240
|
+
created: zod.z.string().datetime(),
|
|
2241
|
+
status: TokenStatusSchema,
|
|
2242
|
+
business_id: zod.z.string(),
|
|
2243
|
+
authorized_amount: zod.z.number(),
|
|
2244
|
+
external_id: zod.z.string(),
|
|
2245
|
+
merchant_id: zod.z.string(),
|
|
2246
|
+
merchant_reference_code: zod.z.string(),
|
|
2247
|
+
card_type: CardTypeSchema,
|
|
2248
|
+
masked_card_number: zod.z.string(),
|
|
2249
|
+
charge_type: ChargeTypeSchema,
|
|
2250
|
+
card_brand: CardBrandSchema,
|
|
2251
|
+
bank_reconciliation_id: zod.z.string(),
|
|
2252
|
+
failure_reason: ChargeFailureReasonSchema.optional(),
|
|
2253
|
+
eci: ECICodeSchema.optional(),
|
|
2254
|
+
cvn_code: CVNCodeSchema.optional(),
|
|
2255
|
+
capture_amount: zod.z.number().optional(),
|
|
2256
|
+
descriptor: zod.z.string().optional(),
|
|
2257
|
+
id: zod.z.string(),
|
|
2258
|
+
mid_label: zod.z.string().optional(),
|
|
2259
|
+
promotion: PromotionSummarySchema.optional(),
|
|
2260
|
+
installment: InstallmentSummary.optional()
|
|
2261
|
+
});
|
|
2262
|
+
|
|
2263
|
+
const createToken = async (params, axiosInstance, config)=>{
|
|
2264
|
+
try {
|
|
2265
|
+
const validatedParams = validateInput(TokenParamsSchema, params, "token params");
|
|
2266
|
+
const response = await axiosInstance.post(config?.url ?? "/credit_card_tokens", validatedParams, config);
|
|
2267
|
+
return validateInput(TokenResourceSchema, response.data, "token response");
|
|
2268
|
+
} catch (error) {
|
|
2269
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2270
|
+
handleAxiosError(error);
|
|
2271
|
+
}
|
|
2272
|
+
throw error;
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
const getToken = async (params, axiosInstance, config)=>{
|
|
2276
|
+
try {
|
|
2277
|
+
const validatedParams = validateInput(GetTokemParamsSchema, params, "get token params");
|
|
2278
|
+
const response = await axiosInstance.get(config?.url ?? `/credit_card_tokens/${validatedParams.credit_card_token_id}`, config);
|
|
2279
|
+
return validateInput(TokenResourceSchema, response.data, "token response");
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2282
|
+
handleAxiosError(error);
|
|
2283
|
+
}
|
|
2284
|
+
throw error;
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
const authenticateToken = async (params, axiosInstance, config)=>{
|
|
2288
|
+
try {
|
|
2289
|
+
const validatedParams = validateInput(TokenAuthenticationSchema, params, "token authentication params");
|
|
2290
|
+
const response = await axiosInstance.post(config?.url ?? "/credit_card_tokens/authenticate", validatedParams, config);
|
|
2291
|
+
return validateInput(TokenAuthenticationResourceSchema, response.data, "token authentication response");
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2294
|
+
handleAxiosError(error);
|
|
2295
|
+
}
|
|
2296
|
+
throw error;
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
const authorizeToken = async (params, axiosInstance, config)=>{
|
|
2300
|
+
try {
|
|
2301
|
+
const validatedParams = validateInput(TokenAuthorizationSchema, params, "token authorization params");
|
|
2302
|
+
const response = await axiosInstance.post(config?.url ?? "/credit_card_charges", validatedParams, config);
|
|
2303
|
+
return validateInput(ChargeResourceSchema, response.data, "charge response");
|
|
2304
|
+
} catch (error) {
|
|
2305
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2306
|
+
handleAxiosError(error);
|
|
2307
|
+
}
|
|
2308
|
+
throw error;
|
|
2309
|
+
}
|
|
2310
|
+
};
|
|
2311
|
+
const zeroAuthorization = async (params, axiosInstance, config)=>{
|
|
2312
|
+
try {
|
|
2313
|
+
const validatedParams = validateInput(ZeroAuthorizationSchema, params, "zero authorization params");
|
|
2314
|
+
const response = await axiosInstance.post(config?.url ?? "/credit_card_charges", validatedParams, config);
|
|
2315
|
+
return validateInput(ChargeResourceSchema, response.data, "charge response");
|
|
2316
|
+
} catch (error) {
|
|
2317
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2318
|
+
handleAxiosError(error);
|
|
2319
|
+
}
|
|
2320
|
+
throw error;
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
const reverseAuthorization = async (params, axiosInstance, config)=>{
|
|
2324
|
+
try {
|
|
2325
|
+
const validatedParams = validateInput(ReverseAuthorizationSchema, params, "reverse authorization params");
|
|
2326
|
+
const response = await axiosInstance.post(config?.url ?? `/credit_card_charges/${validatedParams.external_id}/reverse_authorization`, {}, config);
|
|
2327
|
+
return validateInput(ChargeResourceSchema, response.data, "charge response");
|
|
2328
|
+
} catch (error) {
|
|
2329
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2330
|
+
handleAxiosError(error);
|
|
2331
|
+
}
|
|
2332
|
+
throw error;
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
const createCharge = async (params, axiosInstance, config)=>{
|
|
2336
|
+
try {
|
|
2337
|
+
const validatedParams = validateInput(CreateChargeSchema, params, "charge params");
|
|
2338
|
+
const response = await axiosInstance.post(config?.url ?? "/credit_card_charges", validatedParams, config);
|
|
2339
|
+
return validateInput(ChargeResourceSchema, response.data, "charge response");
|
|
2340
|
+
} catch (error) {
|
|
2341
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2342
|
+
handleAxiosError(error);
|
|
2343
|
+
}
|
|
2344
|
+
throw error;
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
const getCharge = async (params, axiosInstance, config)=>{
|
|
2348
|
+
try {
|
|
2349
|
+
const response = await axiosInstance.get(config?.url ?? `/credit_card_charges/${params.id}`, config);
|
|
2350
|
+
return validateInput(ChargeResourceSchema, response.data, "charge response");
|
|
2351
|
+
} catch (error) {
|
|
2352
|
+
if (error instanceof Error && error.name === "AxiosError") {
|
|
2353
|
+
handleAxiosError(error);
|
|
2354
|
+
}
|
|
2355
|
+
throw error;
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
|
|
2359
|
+
const btoa = (string)=>{
|
|
2360
|
+
if (typeof window === "undefined") {
|
|
2361
|
+
return Buffer.from(string).toString("base64");
|
|
2362
|
+
}
|
|
2363
|
+
return window.btoa(string);
|
|
2364
|
+
};
|
|
2365
|
+
const createFn = (fn, axiosInstance)=>{
|
|
2366
|
+
return (data)=>fn(data, axiosInstance);
|
|
2367
|
+
};
|
|
2368
|
+
const Xendit = (key, options = {})=>{
|
|
2369
|
+
const axiosInstance = createAxiosInstance({
|
|
2370
|
+
headers: {
|
|
2371
|
+
Authorization: `Basic ${btoa(key + ":")}`
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
// Apply rate limiting if configured
|
|
2375
|
+
if (options.rateLimit) {
|
|
2376
|
+
setupRateLimit(axiosInstance, options.rateLimit);
|
|
2377
|
+
}
|
|
2378
|
+
if (key.includes("development")) {
|
|
2379
|
+
console.log("👾 You are on → TEST MODE");
|
|
2380
|
+
}
|
|
2381
|
+
return {
|
|
2382
|
+
customer: {
|
|
2383
|
+
create: createFn(createCustomer, axiosInstance),
|
|
2384
|
+
getById: createFn(getCustomerId, axiosInstance),
|
|
2385
|
+
getByRefId: createFn(getCustomerRefId, axiosInstance),
|
|
2386
|
+
update: createFn(updateCustomer, axiosInstance)
|
|
2387
|
+
},
|
|
2388
|
+
ewallet: {
|
|
2389
|
+
charge: createFn(createEwalletCharge, axiosInstance),
|
|
2390
|
+
get: createFn(getEwalletCharge, axiosInstance)
|
|
2391
|
+
},
|
|
2392
|
+
paymentMethod: {
|
|
2393
|
+
create: createFn(createPaymentMethod, axiosInstance),
|
|
2394
|
+
get: createFn(getPaymentMethod, axiosInstance),
|
|
2395
|
+
list: (params)=>listPaymentMethods(params, axiosInstance),
|
|
2396
|
+
update: createFn(updatePaymentMethod, axiosInstance)
|
|
2397
|
+
},
|
|
2398
|
+
invoice: {
|
|
2399
|
+
create: createFn(createInvoice, axiosInstance),
|
|
2400
|
+
get: createFn(getInvoice, axiosInstance),
|
|
2401
|
+
list: (params)=>listInvoices(params, axiosInstance),
|
|
2402
|
+
update: createFn(updateInvoice, axiosInstance),
|
|
1203
2403
|
expire: createFn(expireInvoice, axiosInstance)
|
|
2404
|
+
},
|
|
2405
|
+
paymentRequest: {
|
|
2406
|
+
create: createFn(createPaymentRequest, axiosInstance),
|
|
2407
|
+
get: createFn(getPaymentRequest, axiosInstance),
|
|
2408
|
+
list: (params)=>listPaymentRequests(params, axiosInstance)
|
|
2409
|
+
},
|
|
2410
|
+
refund: {
|
|
2411
|
+
create: createFn(createRefund, axiosInstance),
|
|
2412
|
+
get: createFn(getRefund, axiosInstance),
|
|
2413
|
+
list: (params)=>listRefunds(params, axiosInstance)
|
|
2414
|
+
},
|
|
2415
|
+
payout: {
|
|
2416
|
+
create: createFn(createPayout, axiosInstance),
|
|
2417
|
+
get: createFn(getPayout, axiosInstance),
|
|
2418
|
+
list: (params)=>listPayouts(params, axiosInstance),
|
|
2419
|
+
cancel: createFn(cancelPayout, axiosInstance)
|
|
2420
|
+
},
|
|
2421
|
+
balance: {
|
|
2422
|
+
get: ()=>getBalance(axiosInstance),
|
|
2423
|
+
listTransactions: (params)=>listTransactions(params, axiosInstance)
|
|
2424
|
+
},
|
|
2425
|
+
card: {
|
|
2426
|
+
createToken: createFn(createToken, axiosInstance),
|
|
2427
|
+
getToken: createFn(getToken, axiosInstance),
|
|
2428
|
+
authenticateToken: createFn(authenticateToken, axiosInstance),
|
|
2429
|
+
authorizeToken: createFn(authorizeToken, axiosInstance),
|
|
2430
|
+
zeroAuthorization: createFn(zeroAuthorization, axiosInstance),
|
|
2431
|
+
reverseAuthorization: createFn(reverseAuthorization, axiosInstance),
|
|
2432
|
+
createCharge: createFn(createCharge, axiosInstance),
|
|
2433
|
+
getCharge: createFn(getCharge, axiosInstance)
|
|
1204
2434
|
}
|
|
1205
2435
|
};
|
|
1206
2436
|
};
|