diff --git a/tests/types/src/invalid.ts b/tests/types/src/invalid.ts index 8d4f6e42..c2cfaf57 100644 --- a/tests/types/src/invalid.ts +++ b/tests/types/src/invalid.ts @@ -214,6 +214,23 @@ stripe } }); +stripe.handleNextAction({clientSecret: ''}).then((res) => { + if (res.paymentIntent) { + // @ts-expect-error If result has a paymentIntent, setupIntent will be undefined + const setupIntentId = res.setupIntent.id; + } + if (res.setupIntent) { + // @ts-expect-error If result has a setupIntent, paymentIntent will be undefined + const paymentIntentId = res.paymentIntent.id; + } + if (res.error) { + // @ts-expect-error If result has an error, paymentIntent will be undefined + const paymentIntentId = res.paymentIntent.id; + // @ts-expect-error If result has an error, setupIntent will be undefined + const setupIntentId = res.setupIntent.id; + } +}); + stripe.processOrder({elements, confirmParams: {return_url: ''}}).then((res) => { if (res.error) { } diff --git a/tests/types/src/valid.ts b/tests/types/src/valid.ts index 14cac650..d90aa812 100644 --- a/tests/types/src/valid.ts +++ b/tests/types/src/valid.ts @@ -2170,9 +2170,17 @@ stripe .handleCardAction('') .then(({paymentIntent}: {paymentIntent?: PaymentIntent}) => {}); -stripe - .handleNextAction({clientSecret: ''}) - .then(({paymentIntent}: {paymentIntent?: PaymentIntent}) => {}); +stripe.handleNextAction({clientSecret: ''}).then((res) => { + if (res.paymentIntent) { + const paymentIntentId = res.paymentIntent.id; + } + if (res.setupIntent) { + const setupIntentId = res.setupIntent.id; + } + if (res.error) { + const errorType = res.error.type; + } +}); stripe .verifyMicrodepositsForPayment('', {amounts: [32, 45]}) diff --git a/types/stripe-js/stripe.d.ts b/types/stripe-js/stripe.d.ts index dcd47a9a..44f12f3f 100644 --- a/types/stripe-js/stripe.d.ts +++ b/types/stripe-js/stripe.d.ts @@ -590,8 +590,8 @@ export interface Stripe { handleCardAction(clientSecret: string): Promise; /** - * Use `stripe.handleNextAction` in the Payment Intents API finalizing payments on the server flow to finish confirmation of a [PaymentIntent](https://stripe.com/docs/api/payment_intents) or [SetupIntent](https://stripe.com/docs/api/setup_intents) with the `requires_action` status. - * It will throw an error if the `PaymentIntent` has a different status. + * Use `stripe.handleNextAction` in the [finalizing payments on the server](https://stripe.com/docs/payments/finalize-payments-on-the-server) flow to finish confirmation of a [PaymentIntent](https://stripe.com/docs/api/payment_intents) or [SetupIntent](https://stripe.com/docs/api/setup_intents) with the `requires_action` status. + * It will throw an error if the `PaymentIntent` or `SetupIntent` has a different status. * * Note that `stripe.handleNextAction` may take several seconds to complete. * During that time, you should disable your form from being resubmitted and show a waiting indicator like a spinner. @@ -605,7 +605,7 @@ export interface Stripe { */ handleNextAction(options: { clientSecret: string; - }): Promise; + }): Promise; /** * Use `stripe.verifyMicrodepositsForPayment` in the [Accept a Canadian pre-authorized debit payment](https://stripe.com/docs/payments/acss-debit/accept-a-payment) flow @@ -1203,6 +1203,15 @@ export type SetupIntentResult = | {setupIntent: api.SetupIntent; error?: undefined} | {setupIntent?: undefined; error: StripeError}; +export type PaymentIntentOrSetupIntentResult = + | { + paymentIntent: api.PaymentIntent; + setupIntent?: undefined; + error?: undefined; + } + | {paymentIntent?: undefined; setupIntent: api.SetupIntent; error?: undefined} + | {paymentIntent?: undefined; setupIntent?: undefined; error: StripeError}; + export type ProcessOrderResult = | {paymentIntent: api.PaymentIntent; order: api.Order; error?: undefined} | {paymentIntent?: undefined; order: api.Order; error?: undefined}