From 2931201def55b8c5e1458c19f0f2580000486887 Mon Sep 17 00:00:00 2001 From: Polo Li <65737086+pololi-stripe@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:42:16 -0700 Subject: [PATCH] Add onShippingDetailsChange type for embedded checkout (#633) --- types/stripe-js/embedded-checkout.d.ts | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/types/stripe-js/embedded-checkout.d.ts b/types/stripe-js/embedded-checkout.d.ts index c1217d3e..6a1af394 100644 --- a/types/stripe-js/embedded-checkout.d.ts +++ b/types/stripe-js/embedded-checkout.d.ts @@ -1,3 +1,26 @@ +export type StripeEmbeddedCheckoutAddress = { + country: string; + line1?: string | null; + line2?: string | null; + city?: string | null; + postal_code?: string | null; + state?: string | null; +}; + +export type StripeEmbeddedCheckoutShippingDetails = { + name: string; + address: StripeEmbeddedCheckoutAddress; +}; + +export type StripeEmbeddedCheckoutShippingDetailsChangeEvent = { + checkoutSessionId: string; + shippingDetails: StripeEmbeddedCheckoutShippingDetails; +}; + +export type ResultAction = + | {type: 'accept'} + | {type: 'reject'; errorMessage?: string}; + export interface StripeEmbeddedCheckoutOptions { /** * The client secret of the [Checkout Session](https://stripe.com/docs/api/checkout/sessions). @@ -13,6 +36,15 @@ export interface StripeEmbeddedCheckoutOptions { * You can use it to unmount Embedded Checkout and render a custom success UI. */ onComplete?: () => void; + /** + * onShippingDetailsChange is called when the customer completes the shipping details form. + * + * The callback is required when [permissions.update.shipping_details](https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-permissions-update-shipping_details) is set to `server_only`. + * For a step-by-step guide on using this callback to customize shipping options during checkout, see [Customize Shipping Options](https://docs.stripe.com/payments/checkout/custom-shipping-options). + */ + onShippingDetailsChange?: ( + event: StripeEmbeddedCheckoutShippingDetailsChangeEvent + ) => Promise; } export interface StripeEmbeddedCheckout {