xendit-fn 1.0.6 → 1.0.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/lib/index.cjs CHANGED
@@ -255,14 +255,17 @@ const CountrySchema = zod.z.union([
255
255
  zod.z.literal("ID"),
256
256
  zod.z.literal("MY"),
257
257
  zod.z.literal("TH"),
258
- zod.z.literal("VN")
258
+ zod.z.literal("VN"),
259
+ zod.z.literal("SG")
259
260
  ]);
260
261
  const CurrencySchema = zod.z.union([
261
262
  zod.z.literal("PHP"),
262
263
  zod.z.literal("IDR"),
263
264
  zod.z.literal("MYR"),
264
265
  zod.z.literal("THB"),
265
- zod.z.literal("VND")
266
+ zod.z.literal("VND"),
267
+ zod.z.literal("SGD"),
268
+ zod.z.literal("USD")
266
269
  ]);
267
270
  const BillingDetailSchema = zod.z.object({
268
271
  given_names: zod.z.string(),
@@ -276,7 +279,7 @@ zod.z.union([
276
279
  zod.z.literal("INDIVIDUAL"),
277
280
  zod.z.literal("BUSINESS")
278
281
  ]);
279
- const IndividualDetailSchema = zod.z.object({
282
+ const IndividualDetailSchema$1 = zod.z.object({
280
283
  given_names: zod.z.string(),
281
284
  surname: zod.z.string().optional(),
282
285
  nationality: zod.z.string().optional(),
@@ -406,7 +409,7 @@ const KYCDocumentSchema = zod.z.object({
406
409
  document_images: zod.z.array(zod.z.string())
407
410
  });
408
411
  const CommonCustomerResourceSchema = zod.z.object({
409
- individual_detail: IndividualDetailSchema.optional(),
412
+ individual_detail: IndividualDetailSchema$1.optional(),
410
413
  business_detail: BusinessDetailSchema.optional(),
411
414
  email: zod.z.string().email().optional(),
412
415
  mobile_number: PhoneSchema.optional(),
@@ -425,7 +428,7 @@ const CustomerSchema = zod.z.discriminatedUnion("type", [
425
428
  zod.z.object({
426
429
  type: zod.z.literal("INDIVIDUAL"),
427
430
  reference_id: zod.z.string(),
428
- individual_detail: IndividualDetailSchema,
431
+ individual_detail: IndividualDetailSchema$1,
429
432
  business_detail: zod.z.undefined().optional(),
430
433
  email: zod.z.string().email().optional(),
431
434
  mobile_number: PhoneSchema.optional(),
@@ -466,7 +469,7 @@ const CustomerResourceSchema = zod.z.discriminatedUnion("type", [
466
469
  type: zod.z.literal("INDIVIDUAL"),
467
470
  id: zod.z.string(),
468
471
  reference_id: zod.z.string(),
469
- individual_detail: IndividualDetailSchema,
472
+ individual_detail: IndividualDetailSchema$1,
470
473
  business_detail: zod.z.undefined().optional(),
471
474
  email: zod.z.string().email().optional(),
472
475
  mobile_number: PhoneSchema.optional(),
@@ -613,7 +616,7 @@ const ChannelsSchema = zod.z.object({
613
616
  zod.z.literal("REDEEM_NONE")
614
617
  ]).default("REDEEM_NONE").optional()
615
618
  });
616
- const ChannelPropertiesSchema$1 = zod.z.discriminatedUnion("channel_code", [
619
+ const ChannelPropertiesSchema$2 = zod.z.discriminatedUnion("channel_code", [
617
620
  zod.z.object({
618
621
  channel_code: zod.z.literal("ID_OVO"),
619
622
  channel_properties: OVOChannelSchema
@@ -748,7 +751,7 @@ const EWalletChargeResourceSchema = zod.z.object({
748
751
  refunded_amount: zod.z.number().nullable(),
749
752
  checkout_method: CheckoutMethodSchema,
750
753
  channel_code: ChannelCodeSchema,
751
- channel_properties: ChannelPropertiesSchema$1,
754
+ channel_properties: ChannelPropertiesSchema$2,
752
755
  actions: EWalletResourceActionsSchema.optional(),
753
756
  is_redirect_required: zod.z.boolean(),
754
757
  callback_url: zod.z.string(),
@@ -1389,7 +1392,7 @@ const PaymentRequestTypeSchema = zod.z.union([
1389
1392
  zod.z.literal("REUSABLE_PAYMENT_CODE")
1390
1393
  ]);
1391
1394
  // Capture Method
1392
- const CaptureMethodSchema = zod.z.union([
1395
+ const CaptureMethodSchema$1 = zod.z.union([
1393
1396
  zod.z.literal("AUTOMATIC"),
1394
1397
  zod.z.literal("MANUAL")
1395
1398
  ]);
@@ -1410,7 +1413,7 @@ zod.z.union([
1410
1413
  zod.z.literal("SHOPEEPAY")
1411
1414
  ]);
1412
1415
  // Channel Properties
1413
- const ChannelPropertiesSchema = zod.z.object({
1416
+ const ChannelPropertiesSchema$1 = zod.z.object({
1414
1417
  failure_return_url: zod.z.string().url().min(8).max(2000),
1415
1418
  success_return_url: zod.z.string().url().min(8).max(2000),
1416
1419
  enable_otp: zod.z.boolean().optional()
@@ -1423,23 +1426,23 @@ const PaymentMethodSchema = zod.z.object({
1423
1426
  }).optional(),
1424
1427
  ewallet: zod.z.object({
1425
1428
  channel_code: zod.z.string(),
1426
- channel_properties: ChannelPropertiesSchema.optional()
1429
+ channel_properties: ChannelPropertiesSchema$1.optional()
1427
1430
  }).optional(),
1428
1431
  direct_debit: zod.z.object({
1429
1432
  channel_code: zod.z.string(),
1430
- channel_properties: ChannelPropertiesSchema.optional()
1433
+ channel_properties: ChannelPropertiesSchema$1.optional()
1431
1434
  }).optional(),
1432
1435
  over_the_counter: zod.z.object({
1433
1436
  channel_code: zod.z.string(),
1434
- channel_properties: ChannelPropertiesSchema.optional()
1437
+ channel_properties: ChannelPropertiesSchema$1.optional()
1435
1438
  }).optional(),
1436
1439
  qr_code: zod.z.object({
1437
1440
  channel_code: zod.z.string(),
1438
- channel_properties: ChannelPropertiesSchema.optional()
1441
+ channel_properties: ChannelPropertiesSchema$1.optional()
1439
1442
  }).optional(),
1440
1443
  virtual_account: zod.z.object({
1441
1444
  channel_code: zod.z.string(),
1442
- channel_properties: ChannelPropertiesSchema.optional()
1445
+ channel_properties: ChannelPropertiesSchema$1.optional()
1443
1446
  }).optional()
1444
1447
  });
1445
1448
  // Create Payment Request Schema
@@ -1476,7 +1479,7 @@ const CreatePaymentRequestSchema = zod.z.object({
1476
1479
  reference_id: zod.z.string().optional(),
1477
1480
  url: zod.z.string().url().optional()
1478
1481
  })).optional(),
1479
- capture_method: CaptureMethodSchema.optional(),
1482
+ capture_method: CaptureMethodSchema$1.optional(),
1480
1483
  success_redirect_url: zod.z.string().url().optional(),
1481
1484
  failure_redirect_url: zod.z.string().url().optional()
1482
1485
  });
@@ -2365,6 +2368,175 @@ const getCharge = async (params, axiosInstance, config)=>{
2365
2368
  }
2366
2369
  };
2367
2370
 
2371
+ // Session Type
2372
+ const SessionTypeSchema = zod.z.union([
2373
+ zod.z.literal("SAVE"),
2374
+ zod.z.literal("PAY")
2375
+ ]);
2376
+ // Allow Save Payment Method
2377
+ const AllowSavePaymentMethodSchema = zod.z.union([
2378
+ zod.z.literal("DISABLED"),
2379
+ zod.z.literal("OPTIONAL"),
2380
+ zod.z.literal("FORCED")
2381
+ ]);
2382
+ // Session Mode
2383
+ const SessionModeSchema = zod.z.union([
2384
+ zod.z.literal("PAYMENT_LINK"),
2385
+ zod.z.literal("COMPONENTS")
2386
+ ]);
2387
+ // Capture Method
2388
+ const CaptureMethodSchema = zod.z.union([
2389
+ zod.z.literal("AUTOMATIC"),
2390
+ zod.z.literal("MANUAL")
2391
+ ]);
2392
+ // Session Status
2393
+ const SessionStatusSchema = zod.z.union([
2394
+ zod.z.literal("ACTIVE"),
2395
+ zod.z.literal("COMPLETED"),
2396
+ zod.z.literal("EXPIRED"),
2397
+ zod.z.literal("CANCELED")
2398
+ ]);
2399
+ // Item Type
2400
+ const ItemTypeSchema = zod.z.union([
2401
+ zod.z.literal("DIGITAL_PRODUCT"),
2402
+ zod.z.literal("PHYSICAL_PRODUCT"),
2403
+ zod.z.literal("DIGITAL_SERVICE"),
2404
+ zod.z.literal("PHYSICAL_SERVICE"),
2405
+ zod.z.literal("FEE")
2406
+ ]);
2407
+ // Gender
2408
+ const GenderSchema = zod.z.union([
2409
+ zod.z.literal("MALE"),
2410
+ zod.z.literal("FEMALE"),
2411
+ zod.z.literal("OTHER")
2412
+ ]);
2413
+ // Individual Detail
2414
+ const IndividualDetailSchema = zod.z.object({
2415
+ given_names: zod.z.string().min(1).max(50),
2416
+ surname: zod.z.string().min(1).max(50).optional(),
2417
+ nationality: zod.z.string().length(2).optional(),
2418
+ place_of_birth: zod.z.string().min(1).max(60).optional(),
2419
+ date_of_birth: zod.z.string().length(10).optional(),
2420
+ gender: GenderSchema.optional()
2421
+ });
2422
+ // Customer Details
2423
+ const PaymentSessionCustomerDetailsSchema = zod.z.object({
2424
+ type: zod.z.literal("INDIVIDUAL"),
2425
+ reference_id: zod.z.string().min(1).max(255),
2426
+ email: zod.z.string().email().min(4).max(50).optional(),
2427
+ mobile_number: zod.z.string().min(1).max(50).optional(),
2428
+ individual_detail: IndividualDetailSchema
2429
+ });
2430
+ // Item Schema
2431
+ const PaymentSessionItemSchema = zod.z.object({
2432
+ reference_id: zod.z.string().min(1).max(255),
2433
+ type: ItemTypeSchema.optional(),
2434
+ name: zod.z.string().min(1).max(255),
2435
+ description: zod.z.string().max(255).optional(),
2436
+ net_unit_amount: zod.z.number(),
2437
+ quantity: zod.z.number().int().min(1),
2438
+ currency: CurrencySchema,
2439
+ url: zod.z.string().url().optional(),
2440
+ image_url: zod.z.string().url().optional(),
2441
+ category: zod.z.string().max(255),
2442
+ subcategory: zod.z.string().max(255).optional(),
2443
+ metadata: zod.z.record(zod.z.string(), zod.z.string()).optional()
2444
+ });
2445
+ // Channel Properties
2446
+ const ChannelPropertiesSchema = zod.z.object({
2447
+ allowed_payment_channels: zod.z.array(zod.z.string()).optional()
2448
+ });
2449
+ // Metadata
2450
+ const MerchantMetadataSchema = zod.z.record(zod.z.string().max(40), zod.z.string().max(500)).refine((obj)=>Object.keys(obj).length <= 50, "Metadata can have at most 50 keys").nullable().optional();
2451
+ // Create Session Schema
2452
+ const CreateSessionSchema = zod.z.object({
2453
+ reference_id: zod.z.string().min(1).max(64),
2454
+ customer_id: zod.z.string().min(41).max(41).optional(),
2455
+ customer: PaymentSessionCustomerDetailsSchema.optional(),
2456
+ session_type: SessionTypeSchema,
2457
+ allow_save_payment_method: AllowSavePaymentMethodSchema.optional(),
2458
+ currency: CurrencySchema,
2459
+ amount: zod.z.number().min(0),
2460
+ mode: SessionModeSchema,
2461
+ capture_method: CaptureMethodSchema.optional(),
2462
+ country: CountrySchema,
2463
+ channel_properties: ChannelPropertiesSchema.optional(),
2464
+ expires_at: zod.z.string().datetime().optional(),
2465
+ locale: zod.z.string().optional(),
2466
+ metadata: MerchantMetadataSchema,
2467
+ description: zod.z.string().min(1).max(1000).optional(),
2468
+ items: zod.z.array(PaymentSessionItemSchema).nullable().optional(),
2469
+ success_return_url: zod.z.string().url().optional(),
2470
+ cancel_return_url: zod.z.string().url().optional()
2471
+ }).refine((data)=>{
2472
+ // For SAVE session_type, amount must be 0
2473
+ if (data.session_type === "SAVE" && data.amount !== 0) {
2474
+ return false;
2475
+ }
2476
+ return true;
2477
+ }, {
2478
+ message: "For SAVE session_type, amount must be 0",
2479
+ path: [
2480
+ "amount"
2481
+ ]
2482
+ }).refine((data)=>{
2483
+ // Either customer_id or customer must be provided
2484
+ return data.customer_id !== undefined || data.customer !== undefined;
2485
+ }, {
2486
+ message: "Either customer_id or customer must be provided",
2487
+ path: [
2488
+ "customer"
2489
+ ]
2490
+ });
2491
+ // Session Resource Schema
2492
+ const SessionResourceSchema = zod.z.object({
2493
+ payment_session_id: zod.z.string().min(27).max(27),
2494
+ created: zod.z.string().datetime(),
2495
+ updated: zod.z.string().datetime(),
2496
+ reference_id: zod.z.string().min(1).max(64),
2497
+ customer_id: zod.z.string().min(41).max(41).optional(),
2498
+ session_type: SessionTypeSchema,
2499
+ allow_save_payment_method: AllowSavePaymentMethodSchema.optional(),
2500
+ currency: CurrencySchema,
2501
+ amount: zod.z.number().min(0),
2502
+ country: CountrySchema,
2503
+ mode: SessionModeSchema,
2504
+ capture_method: CaptureMethodSchema.optional(),
2505
+ channel_properties: ChannelPropertiesSchema.optional(),
2506
+ allowed_payment_channels: zod.z.array(zod.z.string()).optional(),
2507
+ expires_at: zod.z.string().datetime().optional(),
2508
+ locale: zod.z.string().optional(),
2509
+ metadata: MerchantMetadataSchema,
2510
+ description: zod.z.string().min(1).max(1000).optional(),
2511
+ items: zod.z.array(PaymentSessionItemSchema).nullable().optional(),
2512
+ success_return_url: zod.z.string().url().optional(),
2513
+ cancel_return_url: zod.z.string().url().optional(),
2514
+ status: SessionStatusSchema,
2515
+ payment_link_url: zod.z.string().url().nullable(),
2516
+ payment_token_id: zod.z.string().nullable(),
2517
+ payment_id: zod.z.string().nullable(),
2518
+ payment_request_id: zod.z.string().nullable(),
2519
+ business_id: zod.z.string()
2520
+ });
2521
+
2522
+ const createSession = async (params, axiosInstance, config)=>{
2523
+ try {
2524
+ const validatedParams = validateInput(CreateSessionSchema, params, "session params");
2525
+ const response = await axiosInstance.post(config?.url ?? "/sessions", validatedParams, {
2526
+ ...config,
2527
+ headers: {
2528
+ ...config?.headers
2529
+ }
2530
+ });
2531
+ return validateInput(SessionResourceSchema, response.data, "session response");
2532
+ } catch (error) {
2533
+ if (error instanceof Error && error.name === "AxiosError") {
2534
+ handleAxiosError(error);
2535
+ }
2536
+ throw error;
2537
+ }
2538
+ };
2539
+
2368
2540
  const btoa = (string)=>{
2369
2541
  if (typeof window === "undefined") {
2370
2542
  return Buffer.from(string).toString("base64");
@@ -2440,6 +2612,9 @@ const Xendit = (key, options = {})=>{
2440
2612
  reverseAuthorization: createFn(reverseAuthorization, axiosInstance),
2441
2613
  createCharge: createFn(createCharge, axiosInstance),
2442
2614
  getCharge: createFn(getCharge, axiosInstance)
2615
+ },
2616
+ session: {
2617
+ create: createFn(createSession, axiosInstance)
2443
2618
  }
2444
2619
  };
2445
2620
  };