diff --git a/types/stripe-v3/index.d.ts b/types/stripe-v3/index.d.ts index 1c6775aab7..b703f86784 100644 --- a/types/stripe-v3/index.d.ts +++ b/types/stripe-v3/index.d.ts @@ -28,7 +28,11 @@ declare namespace stripe { createSource(element: elements.Element, options?: { owner?: OwnerInfo }): Promise; createSource(options: SourceOptions): Promise; retrieveSource(options: RetrieveSourceOptions): Promise; - redirectToCheckout(options: StripeCheckoutOptions): Promise; + // We use function overloading instead of a union here to ensure that redirectToCheckout can only be + // called with either the server options or the client options - not a mix of both. + redirectToCheckout(options: StripeClientCheckoutOptions): Promise; + // tslint:disable-next-line unified-signatures + redirectToCheckout(options: StripeServerCheckoutOptions): Promise; paymentRequest(options: paymentRequest.StripePaymentRequestOptions): paymentRequest.StripePaymentRequest; createPaymentMethod( type: paymentMethod.paymentMethodType, @@ -75,17 +79,21 @@ declare namespace stripe { }; type billingAddressCollectionType = 'required' | 'auto' | ''; - interface StripeCheckoutOptions { + + interface StripeClientCheckoutOptions { items: StripeCheckoutItem[]; successUrl: string; cancelUrl: string; clientReferenceId?: string; customerEmail?: string; billingAddressCollection?: billingAddressCollectionType; - sessionId?: string; locale?: string; } + interface StripeServerCheckoutOptions { + sessionId: string; + } + interface StripeCheckoutItem { sku?: string; plan?: string; diff --git a/types/stripe-v3/stripe-v3-tests.ts b/types/stripe-v3/stripe-v3-tests.ts index 9a47515e9c..4244bc7d9d 100644 --- a/types/stripe-v3/stripe-v3-tests.ts +++ b/types/stripe-v3/stripe-v3-tests.ts @@ -196,7 +196,7 @@ describe("Stripe elements", () => { }); }); - it("should use checkout API", () => { + it("should use checkout API for client implementations", () => { stripe.redirectToCheckout({ items: [ { sku: 'sku_123', quantity: 1 } @@ -208,6 +208,14 @@ describe("Stripe elements", () => { }); }); + it("should use the checkout API for server implementations", () => { + stripe.redirectToCheckout({ + sessionId: 'sess_test_123', + }).then(errorResult => { + console.log(errorResult.error.param); + }); + }); + it("should use payment intents", () => { stripe.retrievePaymentIntent('pi_18eYalAHEMiOZZp1l9ZTjSU0_secret_NibvRz4PMmJqjfb0sqmT7aq2') .then(result => {