Skip to content

Commit

Permalink
Type support for MobilePay (#610)
Browse files Browse the repository at this point in the history
* Type support for MobilePay

* prettier format

---------

Co-authored-by: Kausthub Naarayan <kausthub@stripe.com>
  • Loading branch information
scottj-stripe and kausthub-stripe authored May 29, 2024
1 parent f990973 commit f7f2c0d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,40 @@ 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);
Expand Down
36 changes: 36 additions & 0 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ export interface CreatePaymentMethodKonbiniData
};
}

export interface CreatePaymentMethodMobilepayData
extends PaymentMethodCreateParams {
type: 'mobilepay';
}

export interface CreatePaymentMethodOxxoData extends PaymentMethodCreateParams {
type: 'oxxo';

Expand Down Expand Up @@ -1040,6 +1045,37 @@ 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<CreatePaymentMethodMobilepayData, 'type'>;

/**
* 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.
Expand Down
17 changes: 17 additions & 0 deletions types/stripe-js/stripe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,23 @@ export interface Stripe {
options?: paymentIntents.ConfirmKonbiniPaymentOptions
): Promise<PaymentIntentResult>;

/**
* 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<PaymentIntentResult>;

/**
* 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.
Expand Down

0 comments on commit f7f2c0d

Please sign in to comment.