From f1d7b48af3c469393cf44dcff0b4789594f628f1 Mon Sep 17 00:00:00 2001 From: Brendan Moore <57721954+brendanm-stripe@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:45:18 -0400 Subject: [PATCH 1/3] Add optional payment_method confirmPayment param --- types/stripe-js/payment-intents.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/stripe-js/payment-intents.d.ts b/types/stripe-js/payment-intents.d.ts index 58d03681..b7a6e9de 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. */ From 0ae100a09b085c8953c0bcf627cdbb37054b1f64 Mon Sep 17 00:00:00 2001 From: Brendan Moore Date: Thu, 14 Sep 2023 00:01:24 -0400 Subject: [PATCH 2/3] Add type tests --- tests/types/src/invalid.ts | 6 ++++++ tests/types/src/valid.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/types/src/invalid.ts b/tests/types/src/invalid.ts index c2cfaf57..95c9be7b 100644 --- a/tests/types/src/invalid.ts +++ b/tests/types/src/invalid.ts @@ -165,6 +165,9 @@ elements.create('expressCheckout', { // @ts-expect-error at least one of elements or clientSecret is required stripe.confirmPayment({confirmParams: {return_url: ''}}); +// @ts-expect-error Existing payment method by ID string only, not object +stripe.confirmPayment({clientSecret: '', confirmParams: {return_url: '', payment_method: {}}}); + stripe .confirmPayment({elements, confirmParams: {return_url: ''}}) .then((res) => { @@ -194,6 +197,9 @@ stripe // @ts-expect-error either elements or clientSecret is required stripe.confirmSetup({confirmParams: {return_url: ''}}); +// @ts-expect-error Existing payment method by ID string only, not object +stripe.confirmSetup({clientSecret: '', 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..bb26983f 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,23 @@ 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, From 095b5a2e3a872c1ee8dc8fe0af429e82ead539b1 Mon Sep 17 00:00:00 2001 From: Brendan Moore Date: Thu, 14 Sep 2023 00:04:47 -0400 Subject: [PATCH 3/3] prettier/lint fix --- tests/types/src/invalid.ts | 14 ++++++++++---- tests/types/src/valid.ts | 1 - types/stripe-js/payment-intents.d.ts | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/types/src/invalid.ts b/tests/types/src/invalid.ts index 95c9be7b..8729a293 100644 --- a/tests/types/src/invalid.ts +++ b/tests/types/src/invalid.ts @@ -165,8 +165,11 @@ elements.create('expressCheckout', { // @ts-expect-error at least one of elements or clientSecret is required stripe.confirmPayment({confirmParams: {return_url: ''}}); -// @ts-expect-error Existing payment method by ID string only, not object -stripe.confirmPayment({clientSecret: '', confirmParams: {return_url: '', payment_method: {}}}); +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: ''}}) @@ -197,8 +200,11 @@ stripe // @ts-expect-error either elements or clientSecret is required stripe.confirmSetup({confirmParams: {return_url: ''}}); -// @ts-expect-error Existing payment method by ID string only, not object -stripe.confirmSetup({clientSecret: '', confirmParams: {return_url: '', payment_method: {}}}); +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 bb26983f..a1f13a16 100644 --- a/tests/types/src/valid.ts +++ b/tests/types/src/valid.ts @@ -2947,7 +2947,6 @@ stripe } }); - stripe .processOrder({ elements, diff --git a/types/stripe-js/payment-intents.d.ts b/types/stripe-js/payment-intents.d.ts index b7a6e9de..1f26aaef 100644 --- a/types/stripe-js/payment-intents.d.ts +++ b/types/stripe-js/payment-intents.d.ts @@ -1429,7 +1429,7 @@ export interface ConfirmPaymentData extends PaymentIntentConfirmParams { * * @docs https://stripe.com/docs/js/payment_intents/confirm_payment#confirm_payment_intent-options-confirmParams-payment_method */ - payment_method?: string + payment_method?: string; /** * Specifies which fields in the response should be expanded.