diff --git a/tests/types/src/invalid.ts b/tests/types/src/invalid.ts index c2cfaf57..8729a293 100644 --- a/tests/types/src/invalid.ts +++ b/tests/types/src/invalid.ts @@ -165,6 +165,12 @@ elements.create('expressCheckout', { // @ts-expect-error at least one of elements or clientSecret is required stripe.confirmPayment({confirmParams: {return_url: ''}}); +stripe.confirmPayment({ + clientSecret: '', + // @ts-expect-error Existing payment method by ID string only, not object + confirmParams: {return_url: '', payment_method: {}}, +}); + stripe .confirmPayment({elements, confirmParams: {return_url: ''}}) .then((res) => { @@ -194,6 +200,12 @@ stripe // @ts-expect-error either elements or clientSecret is required stripe.confirmSetup({confirmParams: {return_url: ''}}); +stripe.confirmSetup({ + clientSecret: '', + // @ts-expect-error Existing payment method by ID string only, not object + confirmParams: {return_url: '', payment_method: {}}, +}); + stripe.confirmSetup({elements, confirmParams: {return_url: ''}}).then((res) => { if (res.error) { } diff --git a/tests/types/src/valid.ts b/tests/types/src/valid.ts index f83de5f5..a1f13a16 100644 --- a/tests/types/src/valid.ts +++ b/tests/types/src/valid.ts @@ -2813,6 +2813,22 @@ stripe } }); +// confirmPayment redirect: 'if_required' with clientSecret and existing PM +stripe + .confirmPayment({ + clientSecret: '', + redirect: 'if_required', + confirmParams: { + payment_method: '', + }, + }) + .then((res) => { + if (res.error) { + } + if (res.paymentIntent) { + } + }); + // confirmSetup: redirect: 'always' without clientSecret stripe .confirmSetup({ @@ -2915,6 +2931,22 @@ stripe } }); +// confirmSetup redirect: 'if_required' with clientSecret and existing PM +stripe + .confirmSetup({ + clientSecret: '', + redirect: 'if_required', + confirmParams: { + payment_method: '', + }, + }) + .then((res) => { + if (res.error) { + } + if (res.setupIntent) { + } + }); + stripe .processOrder({ elements, diff --git a/types/stripe-js/payment-intents.d.ts b/types/stripe-js/payment-intents.d.ts index 58d03681..1f26aaef 100644 --- a/types/stripe-js/payment-intents.d.ts +++ b/types/stripe-js/payment-intents.d.ts @@ -1424,6 +1424,13 @@ export interface ConfirmPaymentData extends PaymentIntentConfirmParams { billing_details?: PaymentMethodCreateParams.BillingDetails; }; + /** + * Optional `id` of an existing [PaymentMethod](https://stripe.com/docs/api/payment_methods). + * + * @docs https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-payment_method + */ + payment_method?: string; + /** * Specifies which fields in the response should be expanded. */