Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onShippingDetailsChange type for embedded checkout #633

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions types/stripe-js/embedded-checkout.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
export type StripeEmbeddedCheckoutAddress = {
country: string;
line1?: string | null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: I think we can guarantee line1 is present so we could update this typing to be more strict

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied type from our internal code. We can update it once we change the internal type.

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).
Expand All @@ -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<ResultAction>;
}

export interface StripeEmbeddedCheckout {
Expand Down
Loading