Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type support for MobilePay #610

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading