From 3e83e5cf1586cae381425a28fe328f9cbcc7646b Mon Sep 17 00:00:00 2001 From: Kausthub Naarayan Date: Mon, 27 May 2024 01:11:08 +0100 Subject: [PATCH 1/2] Type support for MobilePay --- tests/types/src/valid.ts | 35 ++++++++++++++++++++++++++++ types/stripe-js/payment-intents.d.ts | 35 ++++++++++++++++++++++++++++ types/stripe-js/stripe.d.ts | 17 ++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/tests/types/src/valid.ts b/tests/types/src/valid.ts index d474423f..e27352aa 100644 --- a/tests/types/src/valid.ts +++ b/tests/types/src/valid.ts @@ -1867,6 +1867,41 @@ stripe .confirmKonbiniPayment('') .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); +stripe + .confirmMobilepayPayment('', {payment_method: ''}) + .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); + +stripe + .confirmMobilepayPayment('', {payment_method: ''}, {handleActions: false}) + .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); + + stripe + .confirmMobilepayPayment('', { + payment_method: '', + return_url: window.location.href, + }) + .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); + +stripe + .confirmMobilepayPayment('', { + return_url: window.location.href, + }) + .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); + +stripe + .confirmMobilepayPayment( + '', + { + payment_method: '', + return_url: window.location.href, + }, + { + handleActions: false, + } + ) + .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); + + stripe .confirmOxxoPayment('', {payment_method: ''}) .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); diff --git a/types/stripe-js/payment-intents.d.ts b/types/stripe-js/payment-intents.d.ts index b103c3a6..f3fb1aa8 100644 --- a/types/stripe-js/payment-intents.d.ts +++ b/types/stripe-js/payment-intents.d.ts @@ -264,6 +264,11 @@ export interface CreatePaymentMethodKonbiniData }; } +export interface CreatePaymentMethodMobilepayData + extends PaymentMethodCreateParams { + type: 'mobilepay'; +} + export interface CreatePaymentMethodOxxoData extends PaymentMethodCreateParams { type: 'oxxo'; @@ -1040,6 +1045,36 @@ export interface ConfirmKonbiniPaymentOptions { handleActions?: boolean; } +/** + * Data to be sent with a `stripe.confirmMobilepayPayment` request. + * Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters. + */ +export interface ConfirmMobilepayPaymentData extends PaymentIntentConfirmParams { + /** + * The `id` of an existing [PaymentMethod](https://stripe.com/docs/api/payment_methods). + * This field is optional if a `PaymentMethod` has already been attached to this `PaymentIntent` or a new `PaymentMethod` will be created. + * + * @recommended + */ + payment_method?: string | Omit; + + /** + * The url your customer will be directed to after they complete authentication. + */ + return_url?: string; +} + +/** + * An options object to control the behavior of `stripe.confirmMobilepayPayment`. + */ +export interface ConfirmMobilepayPaymentOptions { + /** + * Set this to `false` if you want to [manually handle the redirect](https://docs.stripe.com/payments/mobilepay/accept-a-payment?web-or-mobile=web&payments-ui-type=direct-api#web-confirm-payment-intent). + * Default is `true`. + */ + handleActions?: boolean; +} + /** * Data to be sent with a `stripe.confirmOxxoPayment` request. * Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters. diff --git a/types/stripe-js/stripe.d.ts b/types/stripe-js/stripe.d.ts index f7753350..0c0a27de 100644 --- a/types/stripe-js/stripe.d.ts +++ b/types/stripe-js/stripe.d.ts @@ -420,6 +420,23 @@ export interface Stripe { options?: paymentIntents.ConfirmKonbiniPaymentOptions ): Promise; + /** + * Use `stripe.confirmMobilepayPayment` in the [Mobilepay Payments](https://docs.stripe.com/payments/mobilepay) with Payment Methods flow when the customer submits your payment form. + * When called, it will confirm the [PaymentIntent](https://stripe.com/docs/api/payment_intents) with `data` you provide. + * Refer to our [integration guide](https://docs.stripe.com/payments/mobilepay) for more details. + * + * When you confirm a `PaymentIntent`, it needs to have an attached [PaymentMethod](https://stripe.com/docs/api/payment_methods). + * In addition to confirming the `PaymentIntent`, this method can automatically create and attach a new PaymentMethod for you. + * If you have already attached a `PaymentMethod` you can call this method without needing to provide any additional data. + * + * @docs https://stripe.com/docs/js/payment_intents/confirm_mobilepay_payment + */ + confirmMobilepayPayment( + clientSecret: string, + data?: paymentIntents.ConfirmMobilepayPaymentData, + options?: paymentIntents.ConfirmMobilepayPaymentOptions + ): Promise; + /** * Use `stripe.confirmOxxoPayment` in the [OXXO Payment](https://stripe.com/docs/payments/oxxo) with Payment Methods flow when the customer submits your payment form. * When called, it will confirm the [PaymentIntent](https://stripe.com/docs/api/payment_intents) with `data` you provide. From b682e5189ef861e1fa6a54bb20867a12cb3bf52b Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Mon, 27 May 2024 10:55:03 +0100 Subject: [PATCH 2/2] prettier format --- tests/types/src/valid.ts | 3 +-- types/stripe-js/payment-intents.d.ts | 3 ++- types/stripe-js/stripe.d.ts | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/types/src/valid.ts b/tests/types/src/valid.ts index e27352aa..4966df99 100644 --- a/tests/types/src/valid.ts +++ b/tests/types/src/valid.ts @@ -1875,7 +1875,7 @@ stripe .confirmMobilepayPayment('', {payment_method: ''}, {handleActions: false}) .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); - stripe +stripe .confirmMobilepayPayment('', { payment_method: '', return_url: window.location.href, @@ -1901,7 +1901,6 @@ stripe ) .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); - stripe .confirmOxxoPayment('', {payment_method: ''}) .then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null); diff --git a/types/stripe-js/payment-intents.d.ts b/types/stripe-js/payment-intents.d.ts index f3fb1aa8..507937f6 100644 --- a/types/stripe-js/payment-intents.d.ts +++ b/types/stripe-js/payment-intents.d.ts @@ -1049,7 +1049,8 @@ export interface ConfirmKonbiniPaymentOptions { * Data to be sent with a `stripe.confirmMobilepayPayment` request. * Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters. */ -export interface ConfirmMobilepayPaymentData extends PaymentIntentConfirmParams { +export interface ConfirmMobilepayPaymentData + extends PaymentIntentConfirmParams { /** * The `id` of an existing [PaymentMethod](https://stripe.com/docs/api/payment_methods). * This field is optional if a `PaymentMethod` has already been attached to this `PaymentIntent` or a new `PaymentMethod` will be created. diff --git a/types/stripe-js/stripe.d.ts b/types/stripe-js/stripe.d.ts index 0c0a27de..a1c296f8 100644 --- a/types/stripe-js/stripe.d.ts +++ b/types/stripe-js/stripe.d.ts @@ -431,11 +431,11 @@ export interface Stripe { * * @docs https://stripe.com/docs/js/payment_intents/confirm_mobilepay_payment */ - confirmMobilepayPayment( - clientSecret: string, - data?: paymentIntents.ConfirmMobilepayPaymentData, - options?: paymentIntents.ConfirmMobilepayPaymentOptions - ): Promise; + confirmMobilepayPayment( + clientSecret: string, + data?: paymentIntents.ConfirmMobilepayPaymentData, + options?: paymentIntents.ConfirmMobilepayPaymentOptions + ): Promise; /** * Use `stripe.confirmOxxoPayment` in the [OXXO Payment](https://stripe.com/docs/payments/oxxo) with Payment Methods flow when the customer submits your payment form.