@xpayeg/sdk 2.1.0 → 2.3.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.
- package/CHANGELOG.md +16 -0
- package/dist/index.d.cts +90 -3
- package/dist/index.d.mts +90 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @xpayeg/sdk
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#471](https://github.com/xpayeg/xpay/pull/471) [`e76a6c3`](https://github.com/xpayeg/xpay/commit/e76a6c3e5f73f4dcf1f108b6be0e1a63dce5d1b9) Thanks [@Elmosh](https://github.com/Elmosh)! - Deferred Elements accept `paymentMethodTypes` (e.g. `["card"]`) to restrict which payment methods the element renders. Narrow-only: the list is intersected with the methods enabled for your account, so a type you have not enabled is never rendered, and an empty intersection fails with `loaderror` instead of rendering an empty frame. Fixed for the element's lifetime; pass the same values when your server creates the session so display and acceptance match. One method per element is the pattern for per-method rows in your own selector.
|
|
9
|
+
|
|
10
|
+
## 2.2.0
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
- [#462](https://github.com/xpayeg/xpay/pull/462) [`f083704`](https://github.com/xpayeg/xpay/commit/f08370434ff93c52450cfaee17f249c11b5cd46c) Thanks [@Elmosh](https://github.com/Elmosh)! - Deferred-mount Payment Element: `xpay.elements({ mode: "payment", amount, currency })` renders the payment form with no checkout session — your server creates the session with the final total when the customer clicks Pay, and its clientSecret is passed to `confirmPayment({ elements, clientSecret })` (a plain string). The session's total must equal the amount the element displays, or the confirmation fails with `amount_reconfirmation_required` and nothing is charged. Adds `elements.update({ amount, currency })` for deferred display updates. `XPayProvider` accepts the new options form; deferred amount/currency prop changes flow through `elements.update()` without recreating the instance. The existing `{ clientSecret }` path is unchanged.
|
|
16
|
+
|
|
17
|
+
Also in this release: the overlay scroll lock (3DS/action overlay and drop-in modal, now one shared implementation) pins the page at its measured geometry and preserves the scrollbar gutter, so centered boxed themes no longer shift when an overlay opens; `elements.fetchUpdates()` now genuinely re-fetches the session from the server (it previously answered from the iframe's local state; failures now resolve the error arm instead of returning stale data), and `CheckoutSession` gains optional `presentmentDetails` — the customer-facing amounts, present only when the merchant prices in a currency other than the processing currency. Read amounts presentment-first.
|
|
18
|
+
|
|
3
19
|
## 2.1.0
|
|
4
20
|
### Minor Changes
|
|
5
21
|
|
package/dist/index.d.cts
CHANGED
|
@@ -3454,6 +3454,13 @@ type CheckoutSession = Pick<CheckoutSessionResponseDto, "id" | "amountSubtotal"
|
|
|
3454
3454
|
canConfirm: boolean;
|
|
3455
3455
|
/** Available payment methods */
|
|
3456
3456
|
paymentMethods: PaymentMethodInfo[];
|
|
3457
|
+
/**
|
|
3458
|
+
* Customer-facing amounts, present only when the merchant prices in a
|
|
3459
|
+
* currency other than the processing currency — read amounts
|
|
3460
|
+
* presentment-first (`presentmentDetails.amountTotal` when present,
|
|
3461
|
+
* top-level `amountTotal` otherwise).
|
|
3462
|
+
*/
|
|
3463
|
+
presentmentDetails?: CheckoutSessionResponseDto["presentmentDetails"];
|
|
3457
3464
|
/** Line items in the session */
|
|
3458
3465
|
lineItems?: CheckoutSessionResponseDto["lineItems"];
|
|
3459
3466
|
/** Totals breakdown (subtotal, tax, shipping, etc.) */
|
|
@@ -3584,7 +3591,7 @@ interface XPayInstance {
|
|
|
3584
3591
|
initCheckout(options: InitCheckoutOptions): Promise<InitCheckoutResult>;
|
|
3585
3592
|
}
|
|
3586
3593
|
/**
|
|
3587
|
-
* Options for creating an Elements instance.
|
|
3594
|
+
* Options for creating an Elements instance from an existing checkout session.
|
|
3588
3595
|
*
|
|
3589
3596
|
* @example
|
|
3590
3597
|
* ```ts
|
|
@@ -3595,14 +3602,79 @@ interface XPayInstance {
|
|
|
3595
3602
|
* });
|
|
3596
3603
|
* ```
|
|
3597
3604
|
*/
|
|
3598
|
-
interface
|
|
3605
|
+
interface ElementsOptionsClientSecret {
|
|
3599
3606
|
/** The client secret from a checkout session. Can be a string or a Promise. */
|
|
3600
3607
|
clientSecret: string | Promise<string>;
|
|
3608
|
+
/** Either use mode or clientSecret when creating an Elements group. */
|
|
3609
|
+
mode?: never;
|
|
3610
|
+
/** Amount is only applicable in deferred mode (`mode: "payment"`). */
|
|
3611
|
+
amount?: never;
|
|
3612
|
+
/** Currency is only applicable in deferred mode (`mode: "payment"`). */
|
|
3613
|
+
currency?: never;
|
|
3614
|
+
/** Only applicable in deferred mode. Session-first elements render the session's own payment method types, set when the session is created. */
|
|
3615
|
+
paymentMethodTypes?: never;
|
|
3601
3616
|
/** Appearance overrides for the checkout UI */
|
|
3602
3617
|
appearance?: Appearance;
|
|
3603
3618
|
/** Locale for the payment form — `"en"` (default) or `"ar"` */
|
|
3604
3619
|
locale?: "en" | "ar";
|
|
3605
3620
|
}
|
|
3621
|
+
/**
|
|
3622
|
+
* Options for creating a DEFERRED Elements instance — no checkout session
|
|
3623
|
+
* exists yet. The Payment Element renders immediately from the amount and
|
|
3624
|
+
* currency alone; your server creates the session with the final total when
|
|
3625
|
+
* the customer clicks Pay, and its clientSecret is passed to
|
|
3626
|
+
* `confirmPayment({ elements, clientSecret })`.
|
|
3627
|
+
*
|
|
3628
|
+
* The amount shown is the amount charged: if the session your server creates
|
|
3629
|
+
* has a different total, the confirmation fails with
|
|
3630
|
+
* `amount_reconfirmation_required` and nothing is charged.
|
|
3631
|
+
*
|
|
3632
|
+
* @example
|
|
3633
|
+
* ```ts
|
|
3634
|
+
* const elements = xpay.elements({
|
|
3635
|
+
* mode: "payment",
|
|
3636
|
+
* amount: 250000, // piasters
|
|
3637
|
+
* currency: "EGP",
|
|
3638
|
+
* });
|
|
3639
|
+
* ```
|
|
3640
|
+
*/
|
|
3641
|
+
interface ElementsOptionsMode {
|
|
3642
|
+
/** Deferred mode. Only `"payment"` is supported. */
|
|
3643
|
+
mode: "payment";
|
|
3644
|
+
/** The amount to display and charge, in the currency's smallest unit (piasters). Integer, greater than zero. */
|
|
3645
|
+
amount: number;
|
|
3646
|
+
/** Three-letter currency code (e.g. `"EGP"`). */
|
|
3647
|
+
currency: string;
|
|
3648
|
+
/**
|
|
3649
|
+
* Restrict which payment method types the element renders (e.g. `["card"]`).
|
|
3650
|
+
* Narrow-only: the list is intersected with the payment methods enabled for
|
|
3651
|
+
* your account, so a type that is not enabled is never rendered. If nothing
|
|
3652
|
+
* survives the intersection the element fails to load with a `loaderror`.
|
|
3653
|
+
* Fixed for the element's lifetime. Omit to render every enabled method.
|
|
3654
|
+
* The same values are passed as `paymentMethodTypes` when your server
|
|
3655
|
+
* creates the session at pay time, so display and acceptance match.
|
|
3656
|
+
*/
|
|
3657
|
+
paymentMethodTypes?: string[];
|
|
3658
|
+
/** Either use mode or clientSecret when creating an Elements group. */
|
|
3659
|
+
clientSecret?: never;
|
|
3660
|
+
/** Appearance overrides for the checkout UI */
|
|
3661
|
+
appearance?: Appearance;
|
|
3662
|
+
/** Locale for the payment form — `"en"` (default) or `"ar"` */
|
|
3663
|
+
locale?: "en" | "ar";
|
|
3664
|
+
}
|
|
3665
|
+
/**
|
|
3666
|
+
* Options for creating an Elements instance — with a session's
|
|
3667
|
+
* `clientSecret`, or session-less with `{ mode, amount, currency }`
|
|
3668
|
+
* (deferred). The two forms are mutually exclusive.
|
|
3669
|
+
*/
|
|
3670
|
+
type ElementsOptions = ElementsOptionsClientSecret | ElementsOptionsMode;
|
|
3671
|
+
/** Options for `elements.update()` — deferred mode only. */
|
|
3672
|
+
interface ElementsUpdateOptions {
|
|
3673
|
+
/** New display amount in the currency's smallest unit. Integer, greater than zero. */
|
|
3674
|
+
amount?: number;
|
|
3675
|
+
/** New three-letter currency code. */
|
|
3676
|
+
currency?: string;
|
|
3677
|
+
}
|
|
3606
3678
|
/**
|
|
3607
3679
|
* Manages the lifecycle of the PaymentElement.
|
|
3608
3680
|
*
|
|
@@ -3650,6 +3722,12 @@ interface Elements {
|
|
|
3650
3722
|
fetchUpdates(): Promise<ActionResult>;
|
|
3651
3723
|
/** Update the appearance at runtime without recreating elements */
|
|
3652
3724
|
changeAppearance(appearance: Appearance): void;
|
|
3725
|
+
/**
|
|
3726
|
+
* Update the displayed amount/currency of a DEFERRED Elements instance
|
|
3727
|
+
* (created with `{ mode: "payment" }`). Throws when the instance was
|
|
3728
|
+
* created with a `clientSecret` — session amounts are server-owned.
|
|
3729
|
+
*/
|
|
3730
|
+
update(options: ElementsUpdateOptions): Promise<void>;
|
|
3653
3731
|
/** Destroy the Elements instance and clean up all resources */
|
|
3654
3732
|
destroy(): void;
|
|
3655
3733
|
}
|
|
@@ -3763,6 +3841,15 @@ interface PaymentElement extends BaseElement {
|
|
|
3763
3841
|
interface ConfirmPaymentOptions {
|
|
3764
3842
|
/** The Elements instance managing the payment form */
|
|
3765
3843
|
elements: Elements;
|
|
3844
|
+
/**
|
|
3845
|
+
* DEFERRED mode only, and required there: the clientSecret of the checkout
|
|
3846
|
+
* session your server just created with the final total. A plain string —
|
|
3847
|
+
* await your own fetch before calling. The session's total must equal the
|
|
3848
|
+
* amount the element displays, or the confirmation fails with
|
|
3849
|
+
* `amount_reconfirmation_required` and nothing is charged. Ignored when the
|
|
3850
|
+
* elements were created with a clientSecret.
|
|
3851
|
+
*/
|
|
3852
|
+
clientSecret?: string;
|
|
3766
3853
|
/** Customer details collected by the merchant's form */
|
|
3767
3854
|
customerDetails?: CustomerDetails;
|
|
3768
3855
|
/** Custom field values for the session */
|
|
@@ -3995,4 +4082,4 @@ declare global {
|
|
|
3995
4082
|
declare function loadXPay(publishableKey: string): Promise<XPayInstance | null>;
|
|
3996
4083
|
|
|
3997
4084
|
export { loadXPay };
|
|
3998
|
-
export type { ActionResult, Address, Appearance, BaseElement, CheckoutActions, CheckoutCompleteResult, DiscountResponseDto as CheckoutDiscount, CheckoutError, FeesResponseDto as CheckoutFees, CheckoutInstance, LineItemDto as CheckoutLineItem, CheckoutOptions, CheckoutSession, TotalDetailsResponseDto as CheckoutTotalDetails, ConfirmPaymentOptions, CustomerDetails, Elements, ElementsLoadErrorEvent, ElementsOptions, ElementsReadyEvent, InitCheckoutOptions, InitCheckoutResult, PaymentElement, PaymentElementChangeEvent, PaymentElementOptions, PaymentMethodInfo, SessionStatus, XPayError, XPayInstance };
|
|
4085
|
+
export type { ActionResult, Address, Appearance, BaseElement, CheckoutActions, CheckoutCompleteResult, DiscountResponseDto as CheckoutDiscount, CheckoutError, FeesResponseDto as CheckoutFees, CheckoutInstance, LineItemDto as CheckoutLineItem, CheckoutOptions, CheckoutSession, TotalDetailsResponseDto as CheckoutTotalDetails, ConfirmPaymentOptions, CustomerDetails, Elements, ElementsLoadErrorEvent, ElementsOptions, ElementsOptionsClientSecret, ElementsOptionsMode, ElementsReadyEvent, ElementsUpdateOptions, InitCheckoutOptions, InitCheckoutResult, PaymentElement, PaymentElementChangeEvent, PaymentElementOptions, PaymentMethodInfo, SessionStatus, XPayError, XPayInstance };
|
package/dist/index.d.mts
CHANGED
|
@@ -3454,6 +3454,13 @@ type CheckoutSession = Pick<CheckoutSessionResponseDto, "id" | "amountSubtotal"
|
|
|
3454
3454
|
canConfirm: boolean;
|
|
3455
3455
|
/** Available payment methods */
|
|
3456
3456
|
paymentMethods: PaymentMethodInfo[];
|
|
3457
|
+
/**
|
|
3458
|
+
* Customer-facing amounts, present only when the merchant prices in a
|
|
3459
|
+
* currency other than the processing currency — read amounts
|
|
3460
|
+
* presentment-first (`presentmentDetails.amountTotal` when present,
|
|
3461
|
+
* top-level `amountTotal` otherwise).
|
|
3462
|
+
*/
|
|
3463
|
+
presentmentDetails?: CheckoutSessionResponseDto["presentmentDetails"];
|
|
3457
3464
|
/** Line items in the session */
|
|
3458
3465
|
lineItems?: CheckoutSessionResponseDto["lineItems"];
|
|
3459
3466
|
/** Totals breakdown (subtotal, tax, shipping, etc.) */
|
|
@@ -3584,7 +3591,7 @@ interface XPayInstance {
|
|
|
3584
3591
|
initCheckout(options: InitCheckoutOptions): Promise<InitCheckoutResult>;
|
|
3585
3592
|
}
|
|
3586
3593
|
/**
|
|
3587
|
-
* Options for creating an Elements instance.
|
|
3594
|
+
* Options for creating an Elements instance from an existing checkout session.
|
|
3588
3595
|
*
|
|
3589
3596
|
* @example
|
|
3590
3597
|
* ```ts
|
|
@@ -3595,14 +3602,79 @@ interface XPayInstance {
|
|
|
3595
3602
|
* });
|
|
3596
3603
|
* ```
|
|
3597
3604
|
*/
|
|
3598
|
-
interface
|
|
3605
|
+
interface ElementsOptionsClientSecret {
|
|
3599
3606
|
/** The client secret from a checkout session. Can be a string or a Promise. */
|
|
3600
3607
|
clientSecret: string | Promise<string>;
|
|
3608
|
+
/** Either use mode or clientSecret when creating an Elements group. */
|
|
3609
|
+
mode?: never;
|
|
3610
|
+
/** Amount is only applicable in deferred mode (`mode: "payment"`). */
|
|
3611
|
+
amount?: never;
|
|
3612
|
+
/** Currency is only applicable in deferred mode (`mode: "payment"`). */
|
|
3613
|
+
currency?: never;
|
|
3614
|
+
/** Only applicable in deferred mode. Session-first elements render the session's own payment method types, set when the session is created. */
|
|
3615
|
+
paymentMethodTypes?: never;
|
|
3601
3616
|
/** Appearance overrides for the checkout UI */
|
|
3602
3617
|
appearance?: Appearance;
|
|
3603
3618
|
/** Locale for the payment form — `"en"` (default) or `"ar"` */
|
|
3604
3619
|
locale?: "en" | "ar";
|
|
3605
3620
|
}
|
|
3621
|
+
/**
|
|
3622
|
+
* Options for creating a DEFERRED Elements instance — no checkout session
|
|
3623
|
+
* exists yet. The Payment Element renders immediately from the amount and
|
|
3624
|
+
* currency alone; your server creates the session with the final total when
|
|
3625
|
+
* the customer clicks Pay, and its clientSecret is passed to
|
|
3626
|
+
* `confirmPayment({ elements, clientSecret })`.
|
|
3627
|
+
*
|
|
3628
|
+
* The amount shown is the amount charged: if the session your server creates
|
|
3629
|
+
* has a different total, the confirmation fails with
|
|
3630
|
+
* `amount_reconfirmation_required` and nothing is charged.
|
|
3631
|
+
*
|
|
3632
|
+
* @example
|
|
3633
|
+
* ```ts
|
|
3634
|
+
* const elements = xpay.elements({
|
|
3635
|
+
* mode: "payment",
|
|
3636
|
+
* amount: 250000, // piasters
|
|
3637
|
+
* currency: "EGP",
|
|
3638
|
+
* });
|
|
3639
|
+
* ```
|
|
3640
|
+
*/
|
|
3641
|
+
interface ElementsOptionsMode {
|
|
3642
|
+
/** Deferred mode. Only `"payment"` is supported. */
|
|
3643
|
+
mode: "payment";
|
|
3644
|
+
/** The amount to display and charge, in the currency's smallest unit (piasters). Integer, greater than zero. */
|
|
3645
|
+
amount: number;
|
|
3646
|
+
/** Three-letter currency code (e.g. `"EGP"`). */
|
|
3647
|
+
currency: string;
|
|
3648
|
+
/**
|
|
3649
|
+
* Restrict which payment method types the element renders (e.g. `["card"]`).
|
|
3650
|
+
* Narrow-only: the list is intersected with the payment methods enabled for
|
|
3651
|
+
* your account, so a type that is not enabled is never rendered. If nothing
|
|
3652
|
+
* survives the intersection the element fails to load with a `loaderror`.
|
|
3653
|
+
* Fixed for the element's lifetime. Omit to render every enabled method.
|
|
3654
|
+
* The same values are passed as `paymentMethodTypes` when your server
|
|
3655
|
+
* creates the session at pay time, so display and acceptance match.
|
|
3656
|
+
*/
|
|
3657
|
+
paymentMethodTypes?: string[];
|
|
3658
|
+
/** Either use mode or clientSecret when creating an Elements group. */
|
|
3659
|
+
clientSecret?: never;
|
|
3660
|
+
/** Appearance overrides for the checkout UI */
|
|
3661
|
+
appearance?: Appearance;
|
|
3662
|
+
/** Locale for the payment form — `"en"` (default) or `"ar"` */
|
|
3663
|
+
locale?: "en" | "ar";
|
|
3664
|
+
}
|
|
3665
|
+
/**
|
|
3666
|
+
* Options for creating an Elements instance — with a session's
|
|
3667
|
+
* `clientSecret`, or session-less with `{ mode, amount, currency }`
|
|
3668
|
+
* (deferred). The two forms are mutually exclusive.
|
|
3669
|
+
*/
|
|
3670
|
+
type ElementsOptions = ElementsOptionsClientSecret | ElementsOptionsMode;
|
|
3671
|
+
/** Options for `elements.update()` — deferred mode only. */
|
|
3672
|
+
interface ElementsUpdateOptions {
|
|
3673
|
+
/** New display amount in the currency's smallest unit. Integer, greater than zero. */
|
|
3674
|
+
amount?: number;
|
|
3675
|
+
/** New three-letter currency code. */
|
|
3676
|
+
currency?: string;
|
|
3677
|
+
}
|
|
3606
3678
|
/**
|
|
3607
3679
|
* Manages the lifecycle of the PaymentElement.
|
|
3608
3680
|
*
|
|
@@ -3650,6 +3722,12 @@ interface Elements {
|
|
|
3650
3722
|
fetchUpdates(): Promise<ActionResult>;
|
|
3651
3723
|
/** Update the appearance at runtime without recreating elements */
|
|
3652
3724
|
changeAppearance(appearance: Appearance): void;
|
|
3725
|
+
/**
|
|
3726
|
+
* Update the displayed amount/currency of a DEFERRED Elements instance
|
|
3727
|
+
* (created with `{ mode: "payment" }`). Throws when the instance was
|
|
3728
|
+
* created with a `clientSecret` — session amounts are server-owned.
|
|
3729
|
+
*/
|
|
3730
|
+
update(options: ElementsUpdateOptions): Promise<void>;
|
|
3653
3731
|
/** Destroy the Elements instance and clean up all resources */
|
|
3654
3732
|
destroy(): void;
|
|
3655
3733
|
}
|
|
@@ -3763,6 +3841,15 @@ interface PaymentElement extends BaseElement {
|
|
|
3763
3841
|
interface ConfirmPaymentOptions {
|
|
3764
3842
|
/** The Elements instance managing the payment form */
|
|
3765
3843
|
elements: Elements;
|
|
3844
|
+
/**
|
|
3845
|
+
* DEFERRED mode only, and required there: the clientSecret of the checkout
|
|
3846
|
+
* session your server just created with the final total. A plain string —
|
|
3847
|
+
* await your own fetch before calling. The session's total must equal the
|
|
3848
|
+
* amount the element displays, or the confirmation fails with
|
|
3849
|
+
* `amount_reconfirmation_required` and nothing is charged. Ignored when the
|
|
3850
|
+
* elements were created with a clientSecret.
|
|
3851
|
+
*/
|
|
3852
|
+
clientSecret?: string;
|
|
3766
3853
|
/** Customer details collected by the merchant's form */
|
|
3767
3854
|
customerDetails?: CustomerDetails;
|
|
3768
3855
|
/** Custom field values for the session */
|
|
@@ -3995,4 +4082,4 @@ declare global {
|
|
|
3995
4082
|
declare function loadXPay(publishableKey: string): Promise<XPayInstance | null>;
|
|
3996
4083
|
|
|
3997
4084
|
export { loadXPay };
|
|
3998
|
-
export type { ActionResult, Address, Appearance, BaseElement, CheckoutActions, CheckoutCompleteResult, DiscountResponseDto as CheckoutDiscount, CheckoutError, FeesResponseDto as CheckoutFees, CheckoutInstance, LineItemDto as CheckoutLineItem, CheckoutOptions, CheckoutSession, TotalDetailsResponseDto as CheckoutTotalDetails, ConfirmPaymentOptions, CustomerDetails, Elements, ElementsLoadErrorEvent, ElementsOptions, ElementsReadyEvent, InitCheckoutOptions, InitCheckoutResult, PaymentElement, PaymentElementChangeEvent, PaymentElementOptions, PaymentMethodInfo, SessionStatus, XPayError, XPayInstance };
|
|
4085
|
+
export type { ActionResult, Address, Appearance, BaseElement, CheckoutActions, CheckoutCompleteResult, DiscountResponseDto as CheckoutDiscount, CheckoutError, FeesResponseDto as CheckoutFees, CheckoutInstance, LineItemDto as CheckoutLineItem, CheckoutOptions, CheckoutSession, TotalDetailsResponseDto as CheckoutTotalDetails, ConfirmPaymentOptions, CustomerDetails, Elements, ElementsLoadErrorEvent, ElementsOptions, ElementsOptionsClientSecret, ElementsOptionsMode, ElementsReadyEvent, ElementsUpdateOptions, InitCheckoutOptions, InitCheckoutResult, PaymentElement, PaymentElementChangeEvent, PaymentElementOptions, PaymentMethodInfo, SessionStatus, XPayError, XPayInstance };
|