@xpayeg/sdk 2.4.0 → 3.0.0

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.
@@ -0,0 +1,1635 @@
1
+ /**
2
+ * Generated by orval 🍺
3
+ * Do not edit manually.
4
+ * XPay Checkout API
5
+ * API for the XPay checkout flow — client endpoints and SSR
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ interface AdjustableQuantityDto {
9
+ /** Whether adjustable quantity is enabled */
10
+ enabled: boolean;
11
+ /**
12
+ * Minimum quantity allowed
13
+ * @nullable
14
+ */
15
+ minimum?: number | null;
16
+ /**
17
+ * Maximum quantity allowed
18
+ * @nullable
19
+ */
20
+ maximum?: number | null;
21
+ }
22
+ /**
23
+ * Generated by orval 🍺
24
+ * Do not edit manually.
25
+ * XPay Checkout API
26
+ * API for the XPay checkout flow — client endpoints and SSR
27
+ * OpenAPI spec version: 1.0
28
+ */
29
+ /**
30
+ * Border style for inputs, buttons, cards
31
+ * @nullable
32
+ */
33
+ type BrandingSettingsResponseDtoBorderStyle = (typeof BrandingSettingsResponseDtoBorderStyle)[keyof typeof BrandingSettingsResponseDtoBorderStyle] | null;
34
+ declare const BrandingSettingsResponseDtoBorderStyle: {
35
+ readonly rounded: "rounded";
36
+ readonly sharp: "sharp";
37
+ readonly pill: "pill";
38
+ };
39
+ /**
40
+ * Generated by orval 🍺
41
+ * Do not edit manually.
42
+ * XPay Checkout API
43
+ * API for the XPay checkout flow — client endpoints and SSR
44
+ * OpenAPI spec version: 1.0
45
+ */
46
+ /**
47
+ * Dark mode preference
48
+ * @nullable
49
+ */
50
+ type BrandingSettingsResponseDtoColorMode = (typeof BrandingSettingsResponseDtoColorMode)[keyof typeof BrandingSettingsResponseDtoColorMode] | null;
51
+ declare const BrandingSettingsResponseDtoColorMode: {
52
+ readonly light: "light";
53
+ readonly dark: "dark";
54
+ readonly system: "system";
55
+ };
56
+ /**
57
+ * Generated by orval 🍺
58
+ * Do not edit manually.
59
+ * XPay Checkout API
60
+ * API for the XPay checkout flow — client endpoints and SSR
61
+ * OpenAPI spec version: 1.0
62
+ */
63
+ /**
64
+ * Form layout density
65
+ * @nullable
66
+ */
67
+ type BrandingSettingsResponseDtoFormLayout = (typeof BrandingSettingsResponseDtoFormLayout)[keyof typeof BrandingSettingsResponseDtoFormLayout] | null;
68
+ declare const BrandingSettingsResponseDtoFormLayout: {
69
+ readonly compact: "compact";
70
+ readonly spacious: "spacious";
71
+ };
72
+ /**
73
+ * Generated by orval 🍺
74
+ * Do not edit manually.
75
+ * XPay Checkout API
76
+ * API for the XPay checkout flow — client endpoints and SSR
77
+ * OpenAPI spec version: 1.0
78
+ */
79
+ /**
80
+ * Input field size
81
+ * @nullable
82
+ */
83
+ type BrandingSettingsResponseDtoInputSize = (typeof BrandingSettingsResponseDtoInputSize)[keyof typeof BrandingSettingsResponseDtoInputSize] | null;
84
+ declare const BrandingSettingsResponseDtoInputSize: {
85
+ readonly small: "small";
86
+ readonly medium: "medium";
87
+ readonly large: "large";
88
+ };
89
+ /**
90
+ * Generated by orval 🍺
91
+ * Do not edit manually.
92
+ * XPay Checkout API
93
+ * API for the XPay checkout flow — client endpoints and SSR
94
+ * OpenAPI spec version: 1.0
95
+ */
96
+ /**
97
+ * Input field style
98
+ * @nullable
99
+ */
100
+ type BrandingSettingsResponseDtoInputStyle = (typeof BrandingSettingsResponseDtoInputStyle)[keyof typeof BrandingSettingsResponseDtoInputStyle] | null;
101
+ declare const BrandingSettingsResponseDtoInputStyle: {
102
+ readonly flat: "flat";
103
+ readonly outlined: "outlined";
104
+ readonly filled: "filled";
105
+ };
106
+ /**
107
+ * Generated by orval 🍺
108
+ * Do not edit manually.
109
+ * XPay Checkout API
110
+ * API for the XPay checkout flow — client endpoints and SSR
111
+ * OpenAPI spec version: 1.0
112
+ */
113
+ /**
114
+ * Spacing density
115
+ * @nullable
116
+ */
117
+ type BrandingSettingsResponseDtoSpacing = (typeof BrandingSettingsResponseDtoSpacing)[keyof typeof BrandingSettingsResponseDtoSpacing] | null;
118
+ declare const BrandingSettingsResponseDtoSpacing: {
119
+ readonly condensed: "condensed";
120
+ readonly normal: "normal";
121
+ readonly spacious: "spacious";
122
+ };
123
+ /**
124
+ * Generated by orval 🍺
125
+ * Do not edit manually.
126
+ * XPay Checkout API
127
+ * API for the XPay checkout flow — client endpoints and SSR
128
+ * OpenAPI spec version: 1.0
129
+ */
130
+ interface ColorCustomizationResponseDto {
131
+ /**
132
+ * Primary brand color (buttons, links, accents). Hex only.
133
+ * @nullable
134
+ */
135
+ primary?: string | null;
136
+ /**
137
+ * Primary foreground (text on primary background). Hex only.
138
+ * @nullable
139
+ */
140
+ primaryForeground?: string | null;
141
+ /**
142
+ * Page background color. Hex only.
143
+ * @nullable
144
+ */
145
+ background?: string | null;
146
+ /**
147
+ * Main text color. Hex only.
148
+ * @nullable
149
+ */
150
+ foreground?: string | null;
151
+ /**
152
+ * Border color. Hex only.
153
+ * @nullable
154
+ */
155
+ border?: string | null;
156
+ /**
157
+ * Input, button, and dropdown border color. Hex only.
158
+ * @nullable
159
+ */
160
+ input?: string | null;
161
+ /**
162
+ * Focus ring color. Hex only.
163
+ * @nullable
164
+ */
165
+ ring?: string | null;
166
+ /**
167
+ * Muted/secondary background. Hex only.
168
+ * @nullable
169
+ */
170
+ muted?: string | null;
171
+ /**
172
+ * Muted text color. Hex only.
173
+ * @nullable
174
+ */
175
+ mutedForeground?: string | null;
176
+ /**
177
+ * Accent background. Hex only.
178
+ * @nullable
179
+ */
180
+ accent?: string | null;
181
+ /**
182
+ * Accent text color. Hex only.
183
+ * @nullable
184
+ */
185
+ accentForeground?: string | null;
186
+ /**
187
+ * Destructive/error color. Hex only.
188
+ * @nullable
189
+ */
190
+ destructive?: string | null;
191
+ }
192
+ interface BrandingSettingsResponseDto {
193
+ /**
194
+ * Dark mode preference
195
+ * @nullable
196
+ */
197
+ colorMode?: BrandingSettingsResponseDtoColorMode;
198
+ /**
199
+ * Border style for inputs, buttons, cards
200
+ * @nullable
201
+ */
202
+ borderStyle?: BrandingSettingsResponseDtoBorderStyle;
203
+ /**
204
+ * Spacing density
205
+ * @nullable
206
+ */
207
+ spacing?: BrandingSettingsResponseDtoSpacing;
208
+ /**
209
+ * Input field size
210
+ * @nullable
211
+ */
212
+ inputSize?: BrandingSettingsResponseDtoInputSize;
213
+ /**
214
+ * Input field style
215
+ * @nullable
216
+ */
217
+ inputStyle?: BrandingSettingsResponseDtoInputStyle;
218
+ /**
219
+ * Form layout density
220
+ * @nullable
221
+ */
222
+ formLayout?: BrandingSettingsResponseDtoFormLayout;
223
+ /** Color customization options */
224
+ colors?: ColorCustomizationResponseDto | null;
225
+ /**
226
+ * Font family override
227
+ * @nullable
228
+ */
229
+ fontFamily?: string | null;
230
+ }
231
+ /**
232
+ * Generated by orval 🍺
233
+ * Do not edit manually.
234
+ * XPay Checkout API
235
+ * API for the XPay checkout flow — client endpoints and SSR
236
+ * OpenAPI spec version: 1.0
237
+ */
238
+ interface CardInfoResponseDto {
239
+ brand: string;
240
+ isOnUs: boolean;
241
+ isInternational: boolean;
242
+ }
243
+ /**
244
+ * Generated by orval 🍺
245
+ * Do not edit manually.
246
+ * XPay Checkout API
247
+ * API for the XPay checkout flow — client endpoints and SSR
248
+ * OpenAPI spec version: 1.0
249
+ */
250
+ /**
251
+ * @nullable
252
+ */
253
+ type CatalogRecurringDtoInterval = (typeof CatalogRecurringDtoInterval)[keyof typeof CatalogRecurringDtoInterval] | null;
254
+ declare const CatalogRecurringDtoInterval: {
255
+ readonly DAY: "DAY";
256
+ readonly WEEK: "WEEK";
257
+ readonly MONTH: "MONTH";
258
+ readonly YEAR: "YEAR";
259
+ readonly CUSTOM: "CUSTOM";
260
+ };
261
+ interface CatalogRecurringDto {
262
+ /** @nullable */
263
+ interval?: CatalogRecurringDtoInterval;
264
+ /** @nullable */
265
+ intervalCount?: number | null;
266
+ }
267
+ /**
268
+ * Generated by orval 🍺
269
+ * Do not edit manually.
270
+ * XPay Checkout API
271
+ * API for the XPay checkout flow — client endpoints and SSR
272
+ * OpenAPI spec version: 1.0
273
+ */
274
+ type CouponResponseDtoCurrency = (typeof CouponResponseDtoCurrency)[keyof typeof CouponResponseDtoCurrency];
275
+ declare const CouponResponseDtoCurrency: {
276
+ readonly EGP: "EGP";
277
+ readonly USD: "USD";
278
+ readonly EUR: "EUR";
279
+ readonly GBP: "GBP";
280
+ readonly SAR: "SAR";
281
+ readonly AED: "AED";
282
+ readonly QAR: "QAR";
283
+ readonly KWD: "KWD";
284
+ readonly JOD: "JOD";
285
+ readonly OMR: "OMR";
286
+ readonly BHD: "BHD";
287
+ readonly LYD: "LYD";
288
+ readonly AUD: "AUD";
289
+ readonly CAD: "CAD";
290
+ readonly CNY: "CNY";
291
+ };
292
+ /**
293
+ * Generated by orval 🍺
294
+ * Do not edit manually.
295
+ * XPay Checkout API
296
+ * API for the XPay checkout flow — client endpoints and SSR
297
+ * OpenAPI spec version: 1.0
298
+ */
299
+ /**
300
+ * Discount type
301
+ */
302
+ type CouponResponseDtoDiscountType = (typeof CouponResponseDtoDiscountType)[keyof typeof CouponResponseDtoDiscountType];
303
+ declare const CouponResponseDtoDiscountType: {
304
+ readonly percentage: "percentage";
305
+ readonly fixed_amount: "fixed_amount";
306
+ };
307
+ /**
308
+ * Generated by orval 🍺
309
+ * Do not edit manually.
310
+ * XPay Checkout API
311
+ * API for the XPay checkout flow — client endpoints and SSR
312
+ * OpenAPI spec version: 1.0
313
+ */
314
+ /**
315
+ * Duration
316
+ */
317
+ type CouponResponseDtoDuration = (typeof CouponResponseDtoDuration)[keyof typeof CouponResponseDtoDuration];
318
+ declare const CouponResponseDtoDuration: {
319
+ readonly once: "once";
320
+ readonly repeating: "repeating";
321
+ readonly forever: "forever";
322
+ };
323
+ /**
324
+ * Generated by orval 🍺
325
+ * Do not edit manually.
326
+ * XPay Checkout API
327
+ * API for the XPay checkout flow — client endpoints and SSR
328
+ * OpenAPI spec version: 1.0
329
+ */
330
+ /**
331
+ * Custom metadata
332
+ */
333
+ type CouponResponseDtoMetadata = {
334
+ [key: string]: unknown;
335
+ };
336
+ /**
337
+ * Generated by orval 🍺
338
+ * Do not edit manually.
339
+ * XPay Checkout API
340
+ * API for the XPay checkout flow — client endpoints and SSR
341
+ * OpenAPI spec version: 1.0
342
+ */
343
+ /**
344
+ * Object type
345
+ */
346
+ type CouponResponseDtoObject = (typeof CouponResponseDtoObject)[keyof typeof CouponResponseDtoObject];
347
+ declare const CouponResponseDtoObject: {
348
+ readonly coupon: "coupon";
349
+ };
350
+ /**
351
+ * A Coupon defines a reusable discount you can apply to Checkout Sessions and PaymentIntents. Coupons can grant either a percentage off (`percentOff`) or a fixed amount off (`amountOff`), and can apply once, forever, or repeating for a number of billing cycles. You can also cap how many times a Coupon may be redeemed and when it expires.
352
+ *
353
+ * Coupons are the reusable template. Each concrete application of a Coupon to a customer's purchase is recorded as a Discount. To give customers a redeemable code (e.g. `SUMMER25`) instead of applying the Coupon directly, create one or more Promotion Codes that map to this Coupon — a single Coupon can have many Promotion Codes, each with its own per-code restrictions. You receive `coupon.*` and `promotion_code.*` webhook events for each as they are created or changed.
354
+ */
355
+ interface CouponResponseDto {
356
+ /** Coupon ID */
357
+ id: string;
358
+ /** Object type */
359
+ object: CouponResponseDtoObject;
360
+ /** Created timestamp (ISO 8601) */
361
+ createdAt: string;
362
+ /** Discount type */
363
+ discountType: CouponResponseDtoDiscountType;
364
+ /** Percentage off (0.01-100) */
365
+ percentOff?: number;
366
+ /** Fixed amount off in smallest currency unit */
367
+ amountOff?: number;
368
+ currency?: CouponResponseDtoCurrency;
369
+ /** Duration */
370
+ duration: CouponResponseDtoDuration;
371
+ /** Number of months for repeating duration */
372
+ durationInMonths?: number;
373
+ /** Display name */
374
+ name?: string;
375
+ /** Maximum discount amount for percentage coupons (caps the discount) */
376
+ maxDiscountAmount?: number;
377
+ /** Minimum order subtotal required to use this coupon */
378
+ minValue?: number;
379
+ /** Maximum total redemptions */
380
+ maxRedemptions?: number;
381
+ /** Maximum times a single customer can redeem */
382
+ customerMaxRedemptions?: number;
383
+ /** Number of times redeemed */
384
+ timesRedeemed: number;
385
+ /** Redemption deadline (ISO 8601) */
386
+ redeemBy?: string;
387
+ /** Whether the coupon is currently valid (computed) */
388
+ valid: boolean;
389
+ /** Whether the coupon is active */
390
+ active: boolean;
391
+ /** Product IDs this coupon applies to */
392
+ appliesToProductIds?: string[];
393
+ /** Custom metadata */
394
+ metadata?: CouponResponseDtoMetadata;
395
+ /** Merchant ID */
396
+ merchantId: string;
397
+ /** Whether this is live mode */
398
+ livemode: boolean;
399
+ }
400
+ /**
401
+ * Generated by orval 🍺
402
+ * Do not edit manually.
403
+ * XPay Checkout API
404
+ * API for the XPay checkout flow — client endpoints and SSR
405
+ * OpenAPI spec version: 1.0
406
+ */
407
+ /**
408
+ * Object type
409
+ */
410
+ type DiscountResponseDtoObject = (typeof DiscountResponseDtoObject)[keyof typeof DiscountResponseDtoObject];
411
+ declare const DiscountResponseDtoObject: {
412
+ readonly discount: "discount";
413
+ };
414
+ /**
415
+ * A Discount records a single application of a Coupon to a specific Checkout Session, PaymentIntent, or Customer. Where a Coupon is the reusable template, a Discount captures the concrete redemption: which Coupon was applied, when it became active, when it expires, and (when applicable) which Promotion Code the customer entered to claim it.
416
+ */
417
+ interface DiscountResponseDto {
418
+ /** Discount ID */
419
+ id: string;
420
+ /** Object type */
421
+ object: DiscountResponseDtoObject;
422
+ /** The coupon that was applied */
423
+ coupon: CouponResponseDto;
424
+ /** Promotion code ID used (null if direct coupon application) */
425
+ promotionCodeId?: string;
426
+ /** Customer-facing promotion code string (e.g. SUMMER25) */
427
+ promotionCodeCode?: string;
428
+ /** Checkout session this discount was applied to */
429
+ checkoutSessionId: string;
430
+ /** Customer who received the discount */
431
+ customerId?: string;
432
+ /** When the discount became active (ISO 8601) */
433
+ start: string;
434
+ /** When the discount ends (ISO 8601) */
435
+ end?: string;
436
+ }
437
+ /**
438
+ * Generated by orval 🍺
439
+ * Do not edit manually.
440
+ * XPay Checkout API
441
+ * API for the XPay checkout flow — client endpoints and SSR
442
+ * OpenAPI spec version: 1.0
443
+ */
444
+ type PendingCouponResponseDtoObject = (typeof PendingCouponResponseDtoObject)[keyof typeof PendingCouponResponseDtoObject];
445
+ declare const PendingCouponResponseDtoObject: {
446
+ readonly coupon: "coupon";
447
+ };
448
+ /**
449
+ * The Coupon selected for a Checkout Session before payment completes. It contains the discount terms used to calculate the session total; the Coupon has not yet been redeemed.
450
+ */
451
+ interface PendingCouponResponseDto {
452
+ id: string;
453
+ object: PendingCouponResponseDtoObject;
454
+ /** @nullable */
455
+ name?: string | null;
456
+ discountType: string;
457
+ /** @nullable */
458
+ percentOff?: number | null;
459
+ /** @nullable */
460
+ amountOff?: string | null;
461
+ /** @nullable */
462
+ currency?: string | null;
463
+ valid: true;
464
+ livemode: boolean;
465
+ }
466
+ /**
467
+ * Generated by orval 🍺
468
+ * Do not edit manually.
469
+ * XPay Checkout API
470
+ * API for the XPay checkout flow — client endpoints and SSR
471
+ * OpenAPI spec version: 1.0
472
+ */
473
+ type PendingDiscountResponseDtoId = (typeof PendingDiscountResponseDtoId)[keyof typeof PendingDiscountResponseDtoId];
474
+ declare const PendingDiscountResponseDtoId: {
475
+ readonly pending: "pending";
476
+ };
477
+ /**
478
+ * Generated by orval 🍺
479
+ * Do not edit manually.
480
+ * XPay Checkout API
481
+ * API for the XPay checkout flow — client endpoints and SSR
482
+ * OpenAPI spec version: 1.0
483
+ */
484
+ /**
485
+ * Object type
486
+ */
487
+ type PendingDiscountResponseDtoObject = (typeof PendingDiscountResponseDtoObject)[keyof typeof PendingDiscountResponseDtoObject];
488
+ declare const PendingDiscountResponseDtoObject: {
489
+ readonly discount: "discount";
490
+ };
491
+ /**
492
+ * A Discount selected for a Checkout Session before payment completes. Its ID is pending until the discount is redeemed, and it includes the selected Coupon and any Promotion Code used.
493
+ */
494
+ interface PendingDiscountResponseDto {
495
+ id: PendingDiscountResponseDtoId;
496
+ /** Object type */
497
+ object: PendingDiscountResponseDtoObject;
498
+ coupon: PendingCouponResponseDto;
499
+ /** @nullable */
500
+ promotionCodeId?: string | null;
501
+ /** @nullable */
502
+ promotionCodeCode?: string | null;
503
+ /** Checkout session this discount was applied to */
504
+ checkoutSessionId: string;
505
+ /** Customer who received the discount */
506
+ customerId?: string;
507
+ /** When the discount became active (ISO 8601) */
508
+ start: string;
509
+ /** When the discount ends (ISO 8601) */
510
+ end?: string;
511
+ }
512
+ type CheckoutDiscountResponseDto = DiscountResponseDto | PendingDiscountResponseDto;
513
+ /**
514
+ * Generated by orval 🍺
515
+ * Do not edit manually.
516
+ * XPay Checkout API
517
+ * API for the XPay checkout flow — client endpoints and SSR
518
+ * OpenAPI spec version: 1.0
519
+ */
520
+ /**
521
+ * Currency code (ISO 4217)
522
+ * @nullable
523
+ */
524
+ type CheckoutSessionResponseDtoCurrency = (typeof CheckoutSessionResponseDtoCurrency)[keyof typeof CheckoutSessionResponseDtoCurrency] | null;
525
+ declare const CheckoutSessionResponseDtoCurrency: {
526
+ readonly EGP: "EGP";
527
+ readonly USD: "USD";
528
+ readonly EUR: "EUR";
529
+ readonly GBP: "GBP";
530
+ readonly SAR: "SAR";
531
+ readonly AED: "AED";
532
+ readonly QAR: "QAR";
533
+ readonly KWD: "KWD";
534
+ readonly JOD: "JOD";
535
+ readonly OMR: "OMR";
536
+ readonly BHD: "BHD";
537
+ readonly LYD: "LYD";
538
+ readonly AUD: "AUD";
539
+ readonly CAD: "CAD";
540
+ readonly CNY: "CNY";
541
+ };
542
+ /**
543
+ * Generated by orval 🍺
544
+ * Do not edit manually.
545
+ * XPay Checkout API
546
+ * API for the XPay checkout flow — client endpoints and SSR
547
+ * OpenAPI spec version: 1.0
548
+ */
549
+ /**
550
+ * Whether the money has arrived. `paid` means fulfil; `unpaid` on a `complete` session means the customer still has to pay a reference. Never fulfil on `status` alone.
551
+ */
552
+ type CheckoutSessionResponseDtoPaymentStatus = (typeof CheckoutSessionResponseDtoPaymentStatus)[keyof typeof CheckoutSessionResponseDtoPaymentStatus];
553
+ declare const CheckoutSessionResponseDtoPaymentStatus: {
554
+ readonly paid: "paid";
555
+ readonly unpaid: "unpaid";
556
+ readonly no_payment_required: "no_payment_required";
557
+ };
558
+ interface FeesResponseDto {
559
+ paymentMethodType: string;
560
+ feeAmount: number;
561
+ feePercentage: number;
562
+ vatAmount?: number;
563
+ totalAmount: number;
564
+ cardInfo?: CardInfoResponseDto;
565
+ }
566
+ /**
567
+ * Generated by orval 🍺
568
+ * Do not edit manually.
569
+ * XPay Checkout API
570
+ * API for the XPay checkout flow — client endpoints and SSR
571
+ * OpenAPI spec version: 1.0
572
+ */
573
+ /**
574
+ * Currency of this line's amount fields
575
+ * @nullable
576
+ */
577
+ type LineItemDtoCurrency = (typeof LineItemDtoCurrency)[keyof typeof LineItemDtoCurrency] | null;
578
+ declare const LineItemDtoCurrency: {
579
+ readonly EGP: "EGP";
580
+ readonly USD: "USD";
581
+ readonly EUR: "EUR";
582
+ readonly GBP: "GBP";
583
+ readonly SAR: "SAR";
584
+ readonly AED: "AED";
585
+ readonly QAR: "QAR";
586
+ readonly KWD: "KWD";
587
+ readonly JOD: "JOD";
588
+ readonly OMR: "OMR";
589
+ readonly BHD: "BHD";
590
+ readonly LYD: "LYD";
591
+ readonly AUD: "AUD";
592
+ readonly CAD: "CAD";
593
+ readonly CNY: "CNY";
594
+ };
595
+ /**
596
+ * Generated by orval 🍺
597
+ * Do not edit manually.
598
+ * XPay Checkout API
599
+ * API for the XPay checkout flow — client endpoints and SSR
600
+ * OpenAPI spec version: 1.0
601
+ */
602
+ /**
603
+ * Presentment currency matching the session
604
+ */
605
+ type LineItemPresentmentDetailsDtoCurrency = (typeof LineItemPresentmentDetailsDtoCurrency)[keyof typeof LineItemPresentmentDetailsDtoCurrency];
606
+ declare const LineItemPresentmentDetailsDtoCurrency: {
607
+ readonly EGP: "EGP";
608
+ readonly USD: "USD";
609
+ readonly EUR: "EUR";
610
+ readonly GBP: "GBP";
611
+ readonly SAR: "SAR";
612
+ readonly AED: "AED";
613
+ readonly QAR: "QAR";
614
+ readonly KWD: "KWD";
615
+ readonly JOD: "JOD";
616
+ readonly OMR: "OMR";
617
+ readonly BHD: "BHD";
618
+ readonly LYD: "LYD";
619
+ readonly AUD: "AUD";
620
+ readonly CAD: "CAD";
621
+ readonly CNY: "CNY";
622
+ };
623
+ interface LineItemPresentmentDetailsDto {
624
+ /** Unit amount in presentment smallest units */
625
+ unitAmount: number;
626
+ /** Line subtotal in presentment smallest units */
627
+ amountSubtotal: number;
628
+ /** Allocated line discount in presentment smallest units */
629
+ amountDiscount: number;
630
+ /** Line total after discount and tax, in presentment smallest units */
631
+ amountTotal: number;
632
+ /** Presentment currency matching the session */
633
+ currency: LineItemPresentmentDetailsDtoCurrency;
634
+ }
635
+ /**
636
+ * Generated by orval 🍺
637
+ * Do not edit manually.
638
+ * XPay Checkout API
639
+ * API for the XPay checkout flow — client endpoints and SSR
640
+ * OpenAPI spec version: 1.0
641
+ */
642
+ interface CustomUnitAmountResponseDto {
643
+ /**
644
+ * Minimum amount the customer may enter (minor units).
645
+ * @nullable
646
+ */
647
+ minimum?: number | null;
648
+ /**
649
+ * Maximum amount the customer may enter (minor units).
650
+ * @nullable
651
+ */
652
+ maximum?: number | null;
653
+ /**
654
+ * Suggested amount pre-filled for the customer (minor units).
655
+ * @nullable
656
+ */
657
+ preset?: number | null;
658
+ }
659
+ type CustomUnitAmountDto = CustomUnitAmountResponseDto;
660
+ /**
661
+ * Generated by orval 🍺
662
+ * Do not edit manually.
663
+ * XPay Checkout API
664
+ * API for the XPay checkout flow — client endpoints and SSR
665
+ * OpenAPI spec version: 1.0
666
+ */
667
+ /**
668
+ * Price currency
669
+ */
670
+ type PriceDtoCurrency = (typeof PriceDtoCurrency)[keyof typeof PriceDtoCurrency];
671
+ declare const PriceDtoCurrency: {
672
+ readonly EGP: "EGP";
673
+ readonly USD: "USD";
674
+ readonly EUR: "EUR";
675
+ readonly GBP: "GBP";
676
+ readonly SAR: "SAR";
677
+ readonly AED: "AED";
678
+ readonly QAR: "QAR";
679
+ readonly KWD: "KWD";
680
+ readonly JOD: "JOD";
681
+ readonly OMR: "OMR";
682
+ readonly BHD: "BHD";
683
+ readonly LYD: "LYD";
684
+ readonly AUD: "AUD";
685
+ readonly CAD: "CAD";
686
+ readonly CNY: "CNY";
687
+ };
688
+ /**
689
+ * Generated by orval 🍺
690
+ * Do not edit manually.
691
+ * XPay Checkout API
692
+ * API for the XPay checkout flow — client endpoints and SSR
693
+ * OpenAPI spec version: 1.0
694
+ */
695
+ /**
696
+ * Price type
697
+ */
698
+ type PriceDtoType = (typeof PriceDtoType)[keyof typeof PriceDtoType];
699
+ declare const PriceDtoType: {
700
+ readonly ONE_TIME: "ONE_TIME";
701
+ readonly RECURRING: "RECURRING";
702
+ readonly CUSTOM: "CUSTOM";
703
+ };
704
+ /**
705
+ * Generated by orval 🍺
706
+ * Do not edit manually.
707
+ * XPay Checkout API
708
+ * API for the XPay checkout flow — client endpoints and SSR
709
+ * OpenAPI spec version: 1.0
710
+ */
711
+ interface ProductDto {
712
+ /** Product ID */
713
+ id: string;
714
+ /** Product name */
715
+ name: string;
716
+ /**
717
+ * Product description
718
+ * @nullable
719
+ */
720
+ description?: string | null;
721
+ /**
722
+ * Product image identifier
723
+ * @nullable
724
+ */
725
+ image?: string | null;
726
+ /**
727
+ * Unit label, such as seat or license
728
+ * @nullable
729
+ */
730
+ unitLabel?: string | null;
731
+ /** Whether the product is available; inline products surface as active */
732
+ active: boolean;
733
+ }
734
+ type RecurringDto = CatalogRecurringDto;
735
+ interface PriceDto {
736
+ /** Price ID */
737
+ id: string;
738
+ /** Unit amount in smallest currency units */
739
+ unitAmount?: number;
740
+ /** Price currency */
741
+ currency: PriceDtoCurrency;
742
+ /** Price type */
743
+ type: PriceDtoType;
744
+ recurring?: RecurringDto;
745
+ customUnitAmount?: CustomUnitAmountDto;
746
+ /**
747
+ * Creation timestamp
748
+ * @pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
749
+ */
750
+ createdAt: string;
751
+ /** Whether the price is available; inline prices surface as active */
752
+ active: boolean;
753
+ /**
754
+ * Remaining stock; null means unlimited and negative means oversold
755
+ * @nullable
756
+ */
757
+ stock?: number | null;
758
+ /**
759
+ * Earliest checkout availability
760
+ * @nullable
761
+ * @pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
762
+ */
763
+ startDate?: string | null;
764
+ /**
765
+ * Checkout availability ends at this time
766
+ * @nullable
767
+ * @pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
768
+ */
769
+ expirationDate?: string | null;
770
+ product: ProductDto;
771
+ }
772
+ interface LineItemDto {
773
+ /** Line item ID */
774
+ id: string;
775
+ /** Quantity; zero represents an optional item */
776
+ quantity: number;
777
+ price: PriceDto;
778
+ adjustableQuantity?: AdjustableQuantityDto;
779
+ /** Subtotal before discounts and taxes */
780
+ amountSubtotal?: number;
781
+ /** Total after discounts and taxes */
782
+ amountTotal?: number;
783
+ /** Allocated discount */
784
+ amountDiscount?: number;
785
+ /** Allocated tax */
786
+ amountTax?: number;
787
+ /**
788
+ * Currency of this line's amount fields
789
+ * @nullable
790
+ */
791
+ currency?: LineItemDtoCurrency;
792
+ /** Line item description */
793
+ description?: string;
794
+ presentmentDetails?: LineItemPresentmentDetailsDto;
795
+ }
796
+ /**
797
+ * Generated by orval 🍺
798
+ * Do not edit manually.
799
+ * XPay Checkout API
800
+ * API for the XPay checkout flow — client endpoints and SSR
801
+ * OpenAPI spec version: 1.0
802
+ */
803
+ interface PaymentMethodTypeResponseDto {
804
+ /** Concrete payment method type */
805
+ type: string;
806
+ /** Display name */
807
+ displayName: string;
808
+ /** UI grouping category */
809
+ category?: string;
810
+ /**
811
+ * Minimum transaction amount in smallest currency units
812
+ * @nullable
813
+ */
814
+ minTransactionAmount?: string | null;
815
+ /**
816
+ * Maximum transaction amount in smallest currency units
817
+ * @nullable
818
+ */
819
+ maxTransactionAmount?: string | null;
820
+ /** @nullable */
821
+ requiredCustomerFields?: string[] | null;
822
+ supportsRefund?: boolean;
823
+ supportsPartialRefund?: boolean;
824
+ supportsPartialCapture?: boolean;
825
+ paymentConfirmation?: string;
826
+ }
827
+ /**
828
+ * Generated by orval 🍺
829
+ * Do not edit manually.
830
+ * XPay Checkout API
831
+ * API for the XPay checkout flow — client endpoints and SSR
832
+ * OpenAPI spec version: 1.0
833
+ */
834
+ /**
835
+ * Customer's currency code (ISO 4217)
836
+ */
837
+ type SessionPresentmentDetailsDtoCurrency = (typeof SessionPresentmentDetailsDtoCurrency)[keyof typeof SessionPresentmentDetailsDtoCurrency];
838
+ declare const SessionPresentmentDetailsDtoCurrency: {
839
+ readonly EGP: "EGP";
840
+ readonly USD: "USD";
841
+ readonly EUR: "EUR";
842
+ readonly GBP: "GBP";
843
+ readonly SAR: "SAR";
844
+ readonly AED: "AED";
845
+ readonly QAR: "QAR";
846
+ readonly KWD: "KWD";
847
+ readonly JOD: "JOD";
848
+ readonly OMR: "OMR";
849
+ readonly BHD: "BHD";
850
+ readonly LYD: "LYD";
851
+ readonly AUD: "AUD";
852
+ readonly CAD: "CAD";
853
+ readonly CNY: "CNY";
854
+ };
855
+ interface SessionPresentmentDetailsDto {
856
+ /** Amount in the customer's currency, in the smallest unit */
857
+ amount: number;
858
+ /** Customer's currency code (ISO 4217) */
859
+ currency: SessionPresentmentDetailsDtoCurrency;
860
+ /** Locked rate: presentment major units × rate = processing major units */
861
+ exchangeRate: number;
862
+ /** Immutable exchange-rate record ID */
863
+ exchangeRateId: string;
864
+ /** Subtotal before discounts and fees, in presentment smallest units */
865
+ amountSubtotal: number;
866
+ /** Final total in presentment smallest units */
867
+ amountTotal: number;
868
+ /** Discount in presentment smallest units */
869
+ amountDiscount: number;
870
+ /** Collected VAT when collection is enabled */
871
+ amountCollectedVat?: number;
872
+ /** Platform fee when fees are passed through */
873
+ amountPlatformFee?: number;
874
+ /** Tax when charged */
875
+ amountTax?: number;
876
+ }
877
+ /**
878
+ * Generated by orval 🍺
879
+ * Do not edit manually.
880
+ * XPay Checkout API
881
+ * API for the XPay checkout flow — client endpoints and SSR
882
+ * OpenAPI spec version: 1.0
883
+ */
884
+ interface TotalDetailsResponseDto {
885
+ /** Discount amount */
886
+ amountDiscount: number;
887
+ /** Shipping amount */
888
+ amountShipping?: number;
889
+ /** Tax amount */
890
+ amountTax: number;
891
+ /** Platform fee passed through to the customer */
892
+ amountPlatformFee?: number;
893
+ /** Collected VAT amount */
894
+ amountCollectedVat?: number;
895
+ }
896
+ /**
897
+ * Information about an available payment method.
898
+ *
899
+ * @example
900
+ * ```ts
901
+ * checkout.paymentMethods.forEach(pm => {
902
+ * console.log(pm.type); // "card", "valu", "fawry"
903
+ * console.log(pm.displayName); // "Card", "ValU", "Fawry"
904
+ * console.log(pm.category); // "card", "bnpl", "kiosk", "wallet"
905
+ * });
906
+ * ```
907
+ */
908
+ type PaymentMethodInfo = Required<Pick<PaymentMethodTypeResponseDto, "type" | "displayName">> & {
909
+ /** Payment method category for grouping in UI */
910
+ category: "card" | "bnpl" | "kiosk" | "wallet";
911
+ /** Icon URL for the payment method */
912
+ icon?: string;
913
+ /** Description of the next step (e.g., "You will be redirected to complete payment") */
914
+ nextActionText?: string;
915
+ };
916
+ /**
917
+ * Appearance overrides for the checkout UI.
918
+ * Merged with the session's server-side `brandingSettings`.
919
+ *
920
+ * @example
921
+ * ```ts
922
+ * const elements = xpay.elements({
923
+ * clientSecret,
924
+ * appearance: {
925
+ * colorMode: "dark",
926
+ * borderStyle: "rounded",
927
+ * inputStyle: "outlined",
928
+ * },
929
+ * });
930
+ * ```
931
+ */
932
+ type Appearance = Pick<BrandingSettingsResponseDto, "colorMode" | "borderStyle" | "spacing" | "inputSize" | "inputStyle" | "formLayout" | "colors" | "fontFamily">;
933
+ /**
934
+ * Structured session status — tagged union for exhaustive checking.
935
+ *
936
+ * @example
937
+ * ```ts
938
+ * switch (checkout.status.type) {
939
+ * case "open": // ready for payment
940
+ * case "expired": // session timed out
941
+ * case "complete": // payment completed — check paymentStatus
942
+ * }
943
+ * ```
944
+ */
945
+ /**
946
+ * `complete` means the customer is done with checkout, not that the money has
947
+ * arrived. Cards and other instant methods complete as `paid`; a method the customer
948
+ * pays afterwards (a Fawry reference) completes as `unpaid`, and the session turns
949
+ * `paid` later — announced by `checkout.session.async_payment_succeeded`. Fulfil on
950
+ * `paymentStatus === "paid"`, never on `type === "complete"` alone.
951
+ */
952
+ type SessionStatus = {
953
+ type: "open";
954
+ } | {
955
+ type: "expired";
956
+ } | {
957
+ type: "complete";
958
+ paymentStatus: CheckoutSessionResponseDtoPaymentStatus;
959
+ };
960
+ /**
961
+ * Checkout session data exposed to merchants.
962
+ *
963
+ * Contains everything needed to render a checkout UI: amounts, currency,
964
+ * available payment methods, line items, fees, and discounts.
965
+ *
966
+ * @example
967
+ * ```ts
968
+ * const state = useCheckout();
969
+ * if (state.type === "success") {
970
+ * const { checkout } = state;
971
+ * console.log(checkout.amountTotal); // "10000" (in minor units)
972
+ * console.log(checkout.currency); // "EGP"
973
+ * console.log(checkout.status.type); // "open"
974
+ * console.log(checkout.paymentMethods); // [{type: "card", ...}, ...]
975
+ * }
976
+ * ```
977
+ */
978
+ type CheckoutSession = {
979
+ id?: string;
980
+ amountSubtotal?: number;
981
+ amountTotal?: number;
982
+ currency?: CheckoutSessionResponseDtoCurrency;
983
+ merchantName?: string | null;
984
+ livemode: boolean;
985
+ expiresAt?: string;
986
+ /** Structured session status */
987
+ status: SessionStatus;
988
+ /** Whether the session is ready for confirmation */
989
+ canConfirm: boolean;
990
+ /** Available payment methods */
991
+ paymentMethods: PaymentMethodInfo[];
992
+ /**
993
+ * Customer-facing amounts, present only when the merchant prices in a
994
+ * currency other than the processing currency — read amounts
995
+ * presentment-first (`presentmentDetails.amountTotal` when present,
996
+ * top-level `amountTotal` otherwise).
997
+ */
998
+ presentmentDetails?: SessionPresentmentDetailsDto | undefined;
999
+ /** Line items in the session */
1000
+ lineItems?: LineItemDto[] | undefined;
1001
+ /** Totals breakdown (subtotal, tax, shipping, etc.) */
1002
+ totalDetails?: TotalDetailsResponseDto | undefined;
1003
+ /** Fee breakdown (when feesPassThrough is enabled) */
1004
+ fees?: FeesResponseDto | undefined;
1005
+ /** Applied discounts / promotion codes */
1006
+ discounts?: CheckoutDiscountResponseDto[] | undefined;
1007
+ };
1008
+ /** Line item in a checkout session */
1009
+ type CheckoutLineItem = LineItemDto;
1010
+ /** Totals breakdown (subtotal, tax, shipping, discount amounts) */
1011
+ type CheckoutTotalDetails = TotalDetailsResponseDto;
1012
+ /** Fee breakdown for pass-through fees */
1013
+ type CheckoutFees = FeesResponseDto;
1014
+ /** Applied discount / promotion code */
1015
+ type CheckoutDiscount = CheckoutDiscountResponseDto;
1016
+ /**
1017
+ * Result of an action (confirm, promo, quantity update, etc.).
1018
+ * Tagged union — check `result.type` to determine success or failure.
1019
+ *
1020
+ * @example
1021
+ * ```ts
1022
+ * const result = await checkout.applyPromotionCode("SAVE10");
1023
+ * if (result.type === "success") {
1024
+ * console.log(result.session.amountTotal); // updated amount
1025
+ * } else {
1026
+ * console.log(result.error.message); // "Invalid promotion code"
1027
+ * }
1028
+ * ```
1029
+ */
1030
+ type ActionResult<E = XPayError> = {
1031
+ type: "success";
1032
+ session: CheckoutSession;
1033
+ } | {
1034
+ type: "error";
1035
+ error: E;
1036
+ };
1037
+ /**
1038
+ * Unified error type for ALL SDK operations (Stripe-style).
1039
+ *
1040
+ * Same type for `confirm()`, `applyPromotionCode()`, `updateLineItemQuantity()`, etc.
1041
+ * Payment-specific fields (`declineCode`, `adviceCode`, `chargeId`, `paymentMethod`) are
1042
+ * `null` for non-payment errors.
1043
+ *
1044
+ * @example Payment decline:
1045
+ * ```ts
1046
+ * const result = await checkout.confirm({ customerDetails: { email } });
1047
+ * if (result.type === "error") {
1048
+ * console.log(result.error.type); // "card_error"
1049
+ * console.log(result.error.code); // "card_declined"
1050
+ * console.log(result.error.declineCode); // "insufficient_funds"
1051
+ * console.log(result.error.adviceCode); // "try_again_later"
1052
+ * console.log(result.error.message); // "Your card has insufficient funds."
1053
+ * }
1054
+ * ```
1055
+ *
1056
+ * @example API error (promo code, quantity, session):
1057
+ * ```ts
1058
+ * const result = await checkout.applyPromotionCode("INVALID");
1059
+ * if (result.type === "error") {
1060
+ * console.log(result.error.type); // "invalid_request_error"
1061
+ * console.log(result.error.code); // "promotion_code_not_found"
1062
+ * console.log(result.error.param); // "promotionCode"
1063
+ * console.log(result.error.docUrl); // "https://docs.xpay.app/api/errors#promotion_code_not_found"
1064
+ * console.log(result.error.message); // "No promotion code found for 'INVALID'"
1065
+ * }
1066
+ * ```
1067
+ */
1068
+ interface XPayError {
1069
+ /** Error category: "card_error" | "payment_method_error" | "invalid_request_error" | "api_error" | ... */
1070
+ type: string;
1071
+ /** Machine-readable error code: "card_declined" | "checkout_session_expired" | "promotion_code_not_found" | ... */
1072
+ code: string | null;
1073
+ /** Human-readable error message */
1074
+ message: string;
1075
+ /** Parameter that caused the error (e.g., "promotionCode", "quantity") — null for payment errors */
1076
+ param?: string | null;
1077
+ /** Documentation URL for this error code */
1078
+ docUrl?: string | null;
1079
+ /** Decline code — WHY it failed specifically ("insufficient_funds", "generic_decline") — null for non-payment errors */
1080
+ declineCode?: string | null;
1081
+ /** Retry advice ("try_again_later" | "do_not_try_again" | "confirm_card_data") — null for non-payment errors */
1082
+ adviceCode?: string | null;
1083
+ /** Failed charge ID — null for non-payment errors */
1084
+ chargeId?: string | null;
1085
+ /** Failed payment method ID — null for non-payment errors */
1086
+ paymentMethodId?: string | null;
1087
+ /** Payment method type ("card" | "valu" | "fawry") — null for non-payment errors */
1088
+ paymentMethodType?: string | null;
1089
+ /** Payment method snapshot at time of failure — null for non-payment errors */
1090
+ paymentMethod?: Record<string, unknown> | null;
1091
+ }
1092
+ /**
1093
+ * The XPay SDK instance returned by `loadXPay()`.
1094
+ *
1095
+ * @example
1096
+ * ```ts
1097
+ * import { loadXPay } from "@xpayeg/sdk";
1098
+ *
1099
+ * const xpay = await loadXPay("pk_test_xxx");
1100
+ * const elements = xpay.elements({ clientSecret: "cs_test_abc_secret_xyz" });
1101
+ * ```
1102
+ */
1103
+ interface XPayInstance {
1104
+ /**
1105
+ * Create an Elements instance for custom checkout UI.
1106
+ * Use with `PaymentElement` to render the payment form.
1107
+ *
1108
+ * @param options - Must include `clientSecret` from a checkout session
1109
+ * @returns An Elements instance for creating and managing payment elements
1110
+ */
1111
+ elements(options: ElementsOptions): Elements;
1112
+ /**
1113
+ * Create a drop-in checkout modal or inline embed.
1114
+ *
1115
+ * @param options - Configuration including `clientSecret` and event handlers
1116
+ * @returns A checkout instance with `open()`, `close()`, and `destroy()` methods
1117
+ */
1118
+ checkout(options: CheckoutOptions): CheckoutInstance;
1119
+ /**
1120
+ * Confirm a payment using the data collected by Elements.
1121
+ *
1122
+ * @param options - Must include `elements` and optionally `customerDetails`
1123
+ * @returns Action result with the updated session on success, or an error
1124
+ */
1125
+ confirmPayment(options: ConfirmPaymentOptions): Promise<ActionResult>;
1126
+ /**
1127
+ * Initialize a checkout session — combines `elements()` with session data.
1128
+ * Returns session data + action methods in a single call.
1129
+ *
1130
+ * @param options - Must include `clientSecret`
1131
+ * @returns Session data merged with checkout action methods
1132
+ */
1133
+ initCheckout(options: InitCheckoutOptions): Promise<InitCheckoutResult>;
1134
+ }
1135
+ /**
1136
+ * Options for creating an Elements instance from an existing checkout session.
1137
+ *
1138
+ * @example
1139
+ * ```ts
1140
+ * const elements = xpay.elements({
1141
+ * clientSecret: "cs_test_abc_secret_xyz",
1142
+ * appearance: { colorMode: "dark" },
1143
+ * locale: "ar",
1144
+ * });
1145
+ * ```
1146
+ */
1147
+ interface ElementsOptionsClientSecret {
1148
+ /** The client secret from a checkout session. Can be a string or a Promise. */
1149
+ clientSecret: string | Promise<string>;
1150
+ /** Either use mode or clientSecret when creating an Elements group. */
1151
+ mode?: never;
1152
+ /** Amount is only applicable in deferred mode (`mode: "payment"`). */
1153
+ amount?: never;
1154
+ /** Currency is only applicable in deferred mode (`mode: "payment"`). */
1155
+ currency?: never;
1156
+ /** Only applicable in deferred mode. Session-first elements render the session's own payment method types, set when the session is created. */
1157
+ paymentMethodTypes?: never;
1158
+ /** Appearance overrides for the checkout UI */
1159
+ appearance?: Appearance;
1160
+ /** Locale for the payment form — `"en"` (default) or `"ar"` */
1161
+ locale?: "en" | "ar";
1162
+ }
1163
+ /**
1164
+ * Options for creating a DEFERRED Elements instance — no checkout session
1165
+ * exists yet. The Payment Element renders immediately from the amount and
1166
+ * currency alone; your server creates the session with the final total when
1167
+ * the customer clicks Pay, and its clientSecret is passed to
1168
+ * `confirmPayment({ elements, clientSecret })`.
1169
+ *
1170
+ * The amount shown is the amount charged: if the session your server creates
1171
+ * has a different total, the confirmation fails with
1172
+ * `amount_reconfirmation_required` and nothing is charged.
1173
+ *
1174
+ * @example
1175
+ * ```ts
1176
+ * const elements = xpay.elements({
1177
+ * mode: "payment",
1178
+ * amount: 250000, // piasters
1179
+ * currency: "EGP",
1180
+ * });
1181
+ * ```
1182
+ */
1183
+ interface ElementsOptionsMode {
1184
+ /** Deferred mode. Only `"payment"` is supported. */
1185
+ mode: "payment";
1186
+ /** The amount to display and charge, in the currency's smallest unit (piasters). Integer, greater than zero. */
1187
+ amount: number;
1188
+ /** Three-letter currency code (e.g. `"EGP"`). */
1189
+ currency: string;
1190
+ /**
1191
+ * Restrict which payment method types the element renders (e.g. `["card"]`).
1192
+ * Narrow-only: the list is intersected with the payment methods enabled for
1193
+ * your account, so a type that is not enabled is never rendered. If nothing
1194
+ * survives the intersection the element fails to load with a `loaderror`.
1195
+ * Fixed for the element's lifetime. Omit to render every enabled method.
1196
+ * The same values are passed as `paymentMethodTypes` when your server
1197
+ * creates the session at pay time, so display and acceptance match.
1198
+ */
1199
+ paymentMethodTypes?: string[];
1200
+ /** Either use mode or clientSecret when creating an Elements group. */
1201
+ clientSecret?: never;
1202
+ /** Appearance overrides for the checkout UI */
1203
+ appearance?: Appearance;
1204
+ /** Locale for the payment form — `"en"` (default) or `"ar"` */
1205
+ locale?: "en" | "ar";
1206
+ }
1207
+ /**
1208
+ * Options for creating an Elements instance — with a session's
1209
+ * `clientSecret`, or session-less with `{ mode, amount, currency }`
1210
+ * (deferred). The two forms are mutually exclusive.
1211
+ */
1212
+ type ElementsOptions = ElementsOptionsClientSecret | ElementsOptionsMode;
1213
+ /** Options for `elements.update()` — deferred mode only. */
1214
+ interface ElementsUpdateOptions {
1215
+ /** New display amount in the currency's smallest unit. Integer, greater than zero. */
1216
+ amount?: number;
1217
+ /** New three-letter currency code. */
1218
+ currency?: string;
1219
+ }
1220
+ /**
1221
+ * Manages the lifecycle of the PaymentElement.
1222
+ *
1223
+ * A single Elements instance manages one embed iframe shared by all elements.
1224
+ * Provides session management methods (promo codes, quantities, etc.) and
1225
+ * element creation.
1226
+ */
1227
+ interface Elements {
1228
+ /** Create a PaymentElement (full payment method selector + card form) */
1229
+ create(type: "payment", options?: PaymentElementOptions): PaymentElement;
1230
+ /** Get an existing element by type, or null if not created */
1231
+ getElement(type: "payment"): PaymentElement | null;
1232
+ /** Fetch available payment methods for this session */
1233
+ fetchPaymentMethods(): Promise<PaymentMethodInfo[]>;
1234
+ /**
1235
+ * Listen for the `ready` event — fires when the session is loaded and elements can render.
1236
+ * If the session is already loaded, the handler fires immediately.
1237
+ */
1238
+ on(event: "ready", handler: (data: ElementsReadyEvent) => void): void;
1239
+ /** Listen for session data changes (payment method selection, promo codes, fee updates, etc.) */
1240
+ on(event: "change", handler: (session: CheckoutSession) => void): void;
1241
+ /** Listen for session load failures (network errors, invalid client secret, API errors) */
1242
+ on(event: "loaderror", handler: (data: ElementsLoadErrorEvent) => void): void;
1243
+ /** Listen for unsolicited errors not triggered by a merchant action (e.g. session expired during fee recalculation, BIN detection failure) */
1244
+ on(event: "error", handler: (error: XPayError) => void): void;
1245
+ /** Listen for a custom event */
1246
+ on(event: string, handler: (...args: unknown[]) => void): void;
1247
+ /** Remove an event handler */
1248
+ off(event: string, handler: (...args: unknown[]) => void): void;
1249
+ /** Apply a promotion code to the session */
1250
+ applyPromotionCode(code: string): Promise<ActionResult>;
1251
+ /** Remove the applied promotion code */
1252
+ removePromotionCode(): Promise<ActionResult>;
1253
+ /** Update a line item's quantity */
1254
+ updateLineItemQuantity(args: {
1255
+ lineItem: string;
1256
+ quantity: number;
1257
+ }): Promise<ActionResult>;
1258
+ /** Validate all element fields before confirming — returns the selected payment method on success */
1259
+ submit(): Promise<{
1260
+ error?: XPayError;
1261
+ selectedPaymentMethod?: string;
1262
+ }>;
1263
+ /** Re-fetch the session from the server to get the latest data */
1264
+ fetchUpdates(): Promise<ActionResult>;
1265
+ /** Update the appearance at runtime without recreating elements */
1266
+ changeAppearance(appearance: Appearance): void;
1267
+ /**
1268
+ * Update the displayed amount/currency of a DEFERRED Elements instance
1269
+ * (created with `{ mode: "payment" }`). Throws when the instance was
1270
+ * created with a `clientSecret` — session amounts are server-owned.
1271
+ */
1272
+ update(options: ElementsUpdateOptions): Promise<void>;
1273
+ /** Destroy the Elements instance and clean up all resources */
1274
+ destroy(): void;
1275
+ }
1276
+ /** Fired when the session is loaded and elements are ready to render */
1277
+ interface ElementsReadyEvent {
1278
+ /** The loaded checkout session data */
1279
+ session: CheckoutSession;
1280
+ }
1281
+ /** Fired when the session fails to load */
1282
+ interface ElementsLoadErrorEvent {
1283
+ /** Error category */
1284
+ type: "invalid_request_error" | "api_error" | "network_error";
1285
+ /** Human-readable error message */
1286
+ message: string;
1287
+ /** Machine-readable error code */
1288
+ code?: string;
1289
+ /** The parameter that caused the error */
1290
+ param?: string;
1291
+ /** Link to documentation about this error */
1292
+ docUrl?: string;
1293
+ }
1294
+ /** Options for creating a PaymentElement */
1295
+ interface PaymentElementOptions {
1296
+ /**
1297
+ * How the element presents the payment method chooser.
1298
+ *
1299
+ * - `"accordion"` (default): a vertical list, one row per method, the
1300
+ * selected method's content expanding beneath its row. With exactly one
1301
+ * method the chooser disappears: a single non-card method shows a static
1302
+ * identity header (logo and name, no radio) above its content, while a
1303
+ * single card method renders the bare card form, since its fields
1304
+ * already identify it.
1305
+ * - `"tabs"`: a grid of tiles that fills the row and wraps when the
1306
+ * methods no longer fit, with the selected method's content below it.
1307
+ * With exactly one method the tile grid disappears and
1308
+ * only the content renders, for pages whose own UI already shows the
1309
+ * method's logo and name (e.g. a per-gateway plugin row).
1310
+ *
1311
+ * Updatable after creation via `element.update({ layout })`.
1312
+ */
1313
+ layout?: "accordion" | "tabs";
1314
+ /** Pre-select a specific payment method by type */
1315
+ defaultPaymentMethod?: string;
1316
+ /** Custom ordering of payment methods by type */
1317
+ paymentMethodOrder?: string[];
1318
+ }
1319
+ /**
1320
+ * Change event from a PaymentElement.
1321
+ * Fires on payment method selection, card field changes, and session updates.
1322
+ *
1323
+ * @example
1324
+ * ```tsx
1325
+ * <PaymentElement
1326
+ * onChange={(event) => {
1327
+ * setPaymentReady(event.complete);
1328
+ * console.log("Selected method:", event.value.type);
1329
+ * }}
1330
+ * />
1331
+ * ```
1332
+ */
1333
+ interface PaymentElementChangeEvent {
1334
+ elementType: "payment";
1335
+ /** Whether all card fields are empty (no user input yet) */
1336
+ empty: boolean;
1337
+ /** Whether the form is complete and ready for submission */
1338
+ complete: boolean;
1339
+ /** Whether the payment method selector is collapsed (no method selected) */
1340
+ collapsed: boolean;
1341
+ /** The currently selected payment method */
1342
+ value: {
1343
+ type: string;
1344
+ };
1345
+ /** Full session data including updated amounts, fees, and discounts */
1346
+ session: CheckoutSession;
1347
+ }
1348
+ /** Base interface shared by all element types */
1349
+ interface BaseElement {
1350
+ /** Mount the element into a DOM container (CSS selector or HTMLElement) */
1351
+ mount(container: string | HTMLElement): void;
1352
+ /** Unmount the element from the DOM (can be re-mounted later) */
1353
+ unmount(): void;
1354
+ /** Destroy the element and release all resources */
1355
+ destroy(): void;
1356
+ /** Programmatically focus the element's iframe */
1357
+ focus(): void;
1358
+ /** Programmatically blur the element's iframe */
1359
+ blur(): void;
1360
+ /** Fired when the element is mounted and the iframe content is ready */
1361
+ on(event: "ready", handler: () => void): void;
1362
+ /** Fired when the element's iframe starts loading */
1363
+ on(event: "loaderstart", handler: () => void): void;
1364
+ /** Fired when the element fails to load */
1365
+ on(event: "loaderror", handler: (event: ElementsLoadErrorEvent) => void): void;
1366
+ on(event: string, handler: (...args: unknown[]) => void): void;
1367
+ off(event: string, handler: (...args: unknown[]) => void): void;
1368
+ }
1369
+ /**
1370
+ * The subset of `PaymentElementOptions` that can be updated after creation
1371
+ * (Stripe's `StripePaymentElementUpdateOptions` pattern). Only `layout` is
1372
+ * updatable; `defaultPaymentMethod` and `paymentMethodOrder` are set at
1373
+ * creation.
1374
+ */
1375
+ type PaymentElementUpdateOptions = Pick<PaymentElementOptions, "layout">;
1376
+ /** PaymentElement — full payment method selector with card form */
1377
+ interface PaymentElement extends BaseElement {
1378
+ /** Collapse the payment method selector (deselect all methods) */
1379
+ collapse(): void;
1380
+ /** Update element options at runtime — see {@link PaymentElementUpdateOptions} */
1381
+ update(options: PaymentElementUpdateOptions): void;
1382
+ }
1383
+ /**
1384
+ * Options for `confirmPayment()` or `checkout.confirm()`.
1385
+ *
1386
+ * The `redirect` option controls what happens after a successful payment:
1387
+ * - `"if_required"` (default) — returns the result to your code
1388
+ * - `"always"` — always redirects to the session's own destination after payment
1389
+ *
1390
+ * The destination is never set here. It is the `afterCompletion.redirect.url` you gave
1391
+ * when creating the checkout session, because the same address is handed to the
1392
+ * customer's bank during verification — before the browser leaves your page. A value
1393
+ * supplied from the page could only ever disagree with what the bank was already told.
1394
+ *
1395
+ * @example
1396
+ * ```ts
1397
+ * // Default: get the result back in code
1398
+ * const result = await checkout.confirm({
1399
+ * customerDetails: { email: "user@example.com" },
1400
+ * });
1401
+ *
1402
+ * // Always redirect to the session's own destination after payment
1403
+ * await checkout.confirm({ redirect: "always" });
1404
+ * ```
1405
+ */
1406
+ interface ConfirmPaymentOptions {
1407
+ /** The Elements instance managing the payment form */
1408
+ elements: Elements;
1409
+ /**
1410
+ * DEFERRED mode only, and required there: the clientSecret of the checkout
1411
+ * session your server just created with the final total. A plain string —
1412
+ * await your own fetch before calling. The session's total must equal the
1413
+ * amount the element displays, or the confirmation fails with
1414
+ * `amount_reconfirmation_required` and nothing is charged. Ignored when the
1415
+ * elements were created with a clientSecret.
1416
+ */
1417
+ clientSecret?: string;
1418
+ /** Customer details collected by the merchant's form */
1419
+ customerDetails?: CustomerDetails;
1420
+ /** Custom field values for the session */
1421
+ customFields?: Record<string, string | number | boolean>;
1422
+ /** Device fingerprint for fraud detection */
1423
+ deviceFingerprint?: {
1424
+ visitorId: string;
1425
+ confidence?: number;
1426
+ };
1427
+ /** Override the selected payment method type */
1428
+ paymentMethod?: string;
1429
+ /**
1430
+ * Redirect behavior after payment.
1431
+ * - `"if_required"` (default) — returns the result to your code; only redirects if the payment method requires it
1432
+ * - `"always"` — always redirects to the session's `afterCompletion.redirect.url` after payment. The page navigates away and the function never returns on success.
1433
+ */
1434
+ redirect?: "if_required" | "always";
1435
+ }
1436
+ /**
1437
+ * Options for creating a drop-in checkout instance.
1438
+ *
1439
+ * @example
1440
+ * ```ts
1441
+ * const checkout = xpay.checkout({
1442
+ * clientSecret: "cs_test_abc_secret_xyz",
1443
+ * mode: "modal",
1444
+ * onComplete: (result) => console.log("Paid!", result.paymentIntentId),
1445
+ * });
1446
+ * checkout.open();
1447
+ * ```
1448
+ */
1449
+ interface CheckoutOptions {
1450
+ /** Client secret from a checkout session */
1451
+ clientSecret: string;
1452
+ /** Display mode — `"modal"` (overlay) or `"inline"` (embedded in page) */
1453
+ mode?: "modal" | "inline";
1454
+ /** Container for inline mode (CSS selector or HTMLElement) */
1455
+ container?: string | HTMLElement;
1456
+ /** Called when the payment completes successfully */
1457
+ onComplete?: (result: CheckoutCompleteResult) => void;
1458
+ /** Called when the checkout UI is closed */
1459
+ onClose?: () => void;
1460
+ /** Called when the session is loaded and the checkout is ready */
1461
+ onReady?: (session: CheckoutSession) => void;
1462
+ /** Called when the payment is confirmed (before final result) */
1463
+ onConfirmed?: () => void;
1464
+ /** Called when an error occurs */
1465
+ onError?: (error: CheckoutError) => void;
1466
+ /** Appearance overrides */
1467
+ appearance?: Appearance;
1468
+ /** Locale for the checkout UI */
1469
+ locale?: "en" | "ar";
1470
+ }
1471
+ /** Drop-in checkout instance with lifecycle control */
1472
+ interface CheckoutInstance {
1473
+ /** Open the checkout modal (only for `mode: "modal"`) */
1474
+ open(): void;
1475
+ /** Close the checkout UI */
1476
+ close(): void;
1477
+ /** Destroy the checkout instance and clean up resources */
1478
+ destroy(): void;
1479
+ on(event: "complete", handler: (result: CheckoutCompleteResult) => void): void;
1480
+ on(event: "close", handler: () => void): void;
1481
+ on(event: "ready", handler: (session: CheckoutSession) => void): void;
1482
+ on(event: "confirmed", handler: () => void): void;
1483
+ on(event: "error", handler: (error: CheckoutError) => void): void;
1484
+ off(event: string, handler: (...args: unknown[]) => void): void;
1485
+ }
1486
+ /** Result of a successful payment via drop-in checkout */
1487
+ interface CheckoutCompleteResult {
1488
+ status: "succeeded";
1489
+ /**
1490
+ * Whether the money has arrived. `paid` for cards and other instant methods.
1491
+ * `unpaid` when the customer holds a reference they pay afterwards (Fawry): the
1492
+ * checkout is over, but fulfil only on `checkout.session.async_payment_succeeded`.
1493
+ */
1494
+ paymentStatus: "paid" | "unpaid" | "no_payment_required";
1495
+ /** The payment intent ID for server-side verification */
1496
+ paymentIntentId: string;
1497
+ /** The charge ID (if available) */
1498
+ chargeId?: string;
1499
+ /** Redirect URL from the session's afterCompletion settings */
1500
+ redirectUrl?: string;
1501
+ }
1502
+ /** Error from the drop-in checkout */
1503
+ interface CheckoutError {
1504
+ /** Human-readable error message */
1505
+ message: string;
1506
+ /** Machine-readable error code */
1507
+ code?: string;
1508
+ }
1509
+ /**
1510
+ * Options for `initCheckout()` — the modern single-call API.
1511
+ *
1512
+ * @example
1513
+ * ```ts
1514
+ * const checkout = await xpay.initCheckout({
1515
+ * clientSecret: "cs_test_abc_secret_xyz",
1516
+ * });
1517
+ * console.log(checkout.amountTotal);
1518
+ * await checkout.confirm({ customerDetails: { email: "..." } });
1519
+ * ```
1520
+ */
1521
+ interface InitCheckoutOptions {
1522
+ /** Client secret from a checkout session (string or Promise) */
1523
+ clientSecret: string | Promise<string>;
1524
+ /** Appearance overrides */
1525
+ appearance?: Appearance;
1526
+ /** Locale for the payment form */
1527
+ locale?: "en" | "ar";
1528
+ }
1529
+ /** Result of `initCheckout()` — session data merged with action methods */
1530
+ type InitCheckoutResult = CheckoutSession & CheckoutActions;
1531
+ /**
1532
+ * Action methods available on the checkout object.
1533
+ * These are merged with `CheckoutSession` to form the `Checkout` type.
1534
+ */
1535
+ interface CheckoutActions {
1536
+ /**
1537
+ * Confirm the payment.
1538
+ *
1539
+ * @param options - Customer details and redirect behavior
1540
+ * @returns Action result with updated session on success, or an `XPayError`.
1541
+ * With `redirect: "always"`, the page navigates away on success (never returns).
1542
+ *
1543
+ * @example
1544
+ * ```ts
1545
+ * const result = await checkout.confirm({
1546
+ * customerDetails: { email: "user@example.com" },
1547
+ * });
1548
+ * if (result.type === "error") {
1549
+ * console.error(result.error.message);
1550
+ * }
1551
+ * ```
1552
+ */
1553
+ confirm(options?: Omit<ConfirmPaymentOptions, "elements">): Promise<ActionResult>;
1554
+ /** Apply a promotion code to the session */
1555
+ applyPromotionCode(code: string): Promise<ActionResult>;
1556
+ /** Remove the applied promotion code */
1557
+ removePromotionCode(): Promise<ActionResult>;
1558
+ /** Update a line item's quantity */
1559
+ updateLineItemQuantity(args: {
1560
+ lineItem: string;
1561
+ quantity: number;
1562
+ }): Promise<ActionResult>;
1563
+ /** Validate all fields before confirming — returns the selected payment method on success */
1564
+ submit(): Promise<{
1565
+ error?: XPayError;
1566
+ selectedPaymentMethod?: string;
1567
+ }>;
1568
+ /** Re-fetch the session from the server */
1569
+ fetchUpdates(): Promise<ActionResult>;
1570
+ /** Update the appearance at runtime */
1571
+ changeAppearance(appearance: Appearance): void;
1572
+ /** Listen for session data changes */
1573
+ on(event: "change", handler: (session: CheckoutSession) => void): void;
1574
+ /** Listen for unsolicited errors (e.g. session expired during internal updates) */
1575
+ on(event: "error", handler: (error: XPayError) => void): void;
1576
+ /** Listen for a custom event */
1577
+ on(event: string, handler: (...args: unknown[]) => void): void;
1578
+ /** Access the underlying Elements instance for element creation */
1579
+ getElements(): Elements;
1580
+ }
1581
+ /** Customer details collected by the merchant's form */
1582
+ interface CustomerDetails {
1583
+ /** Customer email address */
1584
+ email?: string;
1585
+ /** Customer full name */
1586
+ name?: string;
1587
+ /** Customer phone number */
1588
+ phone?: string;
1589
+ /** Billing details for the payment */
1590
+ billingDetails?: {
1591
+ name?: string;
1592
+ email?: string;
1593
+ phone?: string;
1594
+ address?: Address;
1595
+ };
1596
+ /** Shipping details */
1597
+ shipping?: {
1598
+ name?: string;
1599
+ phone?: string;
1600
+ address?: Address;
1601
+ };
1602
+ }
1603
+ /** Physical address */
1604
+ interface Address {
1605
+ line1?: string;
1606
+ line2?: string;
1607
+ city?: string;
1608
+ state?: string;
1609
+ postalCode?: string;
1610
+ country?: string;
1611
+ }
1612
+ type XPayFactory = (publishableKey: string) => XPayInstance;
1613
+ declare global {
1614
+ interface Window {
1615
+ XPay?: XPayFactory;
1616
+ }
1617
+ }
1618
+ /**
1619
+ * Load the XPay SDK from CDN.
1620
+ *
1621
+ * Returns a promise that resolves to an XPayInstance with full TypeScript support.
1622
+ * The SDK script is loaded once and cached — subsequent calls return the same instance.
1623
+ *
1624
+ * @param publishableKey - Your publishable API key (pk_test_... or pk_live_...)
1625
+ *
1626
+ * @example
1627
+ * ```typescript
1628
+ * import { loadXPay } from '@xpayeg/sdk';
1629
+ *
1630
+ * const xpay = await loadXPay('pk_test_xxx');
1631
+ * const elements = xpay.elements({ clientSecret: 'cs_test_abc_secret_xyz' });
1632
+ * ```
1633
+ */
1634
+ export declare function loadXPay(publishableKey: string): Promise<XPayInstance | null>;
1635
+ export type { ActionResult, Address, Appearance, BaseElement, CheckoutActions, CheckoutCompleteResult, CheckoutDiscount, CheckoutError, CheckoutFees, CheckoutInstance, CheckoutLineItem, CheckoutOptions, CheckoutSession, CheckoutTotalDetails, ConfirmPaymentOptions, CustomerDetails, Elements, ElementsLoadErrorEvent, ElementsOptions, ElementsOptionsClientSecret, ElementsOptionsMode, ElementsReadyEvent, ElementsUpdateOptions, InitCheckoutOptions, InitCheckoutResult, PaymentElement, PaymentElementChangeEvent, PaymentElementOptions, PaymentMethodInfo, SessionStatus, XPayError, XPayInstance };