Skip to content

Commit

Permalink
Add Type Support for Multibanco and Twint (#666)
Browse files Browse the repository at this point in the history
* Add Bindings for Multibanco and Twint

* run Prettier

* Fix types for Multibanco

* Fix linting
  • Loading branch information
adityar-stripe authored Oct 11, 2024
1 parent bed71dc commit 8a68460
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,24 @@ stripe
)
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmMultibancoPayment('', {
payment_method: {billing_details: {email: '[email protected]'}},
})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmMultibancoPayment('', {payment_method: ''})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmMultibancoPayment('', {payment_method: ''}, {handleActions: false})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmMultibancoPayment('')
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmOxxoPayment('', {payment_method: ''})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);
Expand Down Expand Up @@ -2256,6 +2274,25 @@ stripe
.confirmSofortPayment('', {}, {handleActions: false})
.then(({paymentIntent}: {paymentIntent?: PaymentIntent}) => {});

stripe
.confirmTwintPayment('', {
payment_method: {billing_details: {name: 'Jenny Rosen'}},
return_url: window.location.href,
})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmTwintPayment('', {payment_method: ''})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmTwintPayment('', {payment_method: ''}, {handleActions: false})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmTwintPayment('')
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmWechatPayPayment('', {}, {handleActions: false})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);
Expand Down
79 changes: 79 additions & 0 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ export interface CreatePaymentMethodMobilepayData
type: 'mobilepay';
}

export interface CreatePaymentMethodMultibancoData
extends PaymentMethodCreateParams {
type: 'multibanco';

/**
* The customer's billing details.
* `email` is required.
*
* @docs https://stripe.com/docs/api/payment_methods/create#create_payment_method-billing_details
*/
billing_details: PaymentMethodCreateParams.BillingDetails & {
email: string;
};
}

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

Expand Down Expand Up @@ -370,6 +385,11 @@ export interface CreatePaymentMethodSofortData
billing_details?: PaymentMethodCreateParams.BillingDetails;
}

export interface CreatePaymentMethodTwintData
extends PaymentMethodCreateParams {
type: 'twint';
}

export interface CreatePaymentMethodAuBecsDebitData
extends PaymentMethodCreateParams {
/**
Expand Down Expand Up @@ -1076,6 +1096,36 @@ export interface ConfirmMobilepayPaymentOptions {
handleActions?: boolean;
}

/**
* Data to be sent with a `stripe.confirmMultibancoPayment` request.
* Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters.
*/
export interface ConfirmMultibancoPaymentData
extends PaymentIntentConfirmParams {
/**
* Either the `id` of an existing [PaymentMethod](https://stripe.com/docs/api/payment_methods), or an object containing data to create a `PaymentMethod` with.
* This field is optional if a `PaymentMethod` has already been attached to this `PaymentIntent`.
*
* @recommended
*/
payment_method?: string | Omit<CreatePaymentMethodMultibancoData, 'type'>;

/**
* The url your customer will be directed to after they complete authentication.
*
* @recommended
*/
return_url?: string;
}

export interface ConfirmMultibancoPaymentOptions {
/**
* Set this to `false` if you want to [manually handle the authorization redirect](https://stripe.com/docs/payments/sofort/accept-a-payment?platform=web#handle-redirect).
* 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 Expand Up @@ -1278,6 +1328,35 @@ export interface ConfirmSofortPaymentOptions {
handleActions?: boolean;
}

/**
* Data to be sent with a `stripe.confirmTwintPayment` request.
* Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters.
*/
export interface ConfirmTwintPaymentData extends PaymentIntentConfirmParams {
/**
* Either the `id` of an existing [PaymentMethod](https://stripe.com/docs/api/payment_methods), or an object containing data to create a `PaymentMethod` with.
* This field is optional if a `PaymentMethod` has already been attached to this `PaymentIntent`.
*
* @recommended
*/
payment_method?: string | Omit<CreatePaymentMethodTwintData, 'type'>;

/**
* The url your customer will be directed to after they complete authentication.
*
* @recommended
*/
return_url?: string;
}

export interface ConfirmTwintPaymentOptions {
/**
* Set this to `false` if you want to [manually handle the authorization redirect](https://stripe.com/docs/payments/sofort/accept-a-payment?platform=web#handle-redirect).
* Default is `true`.
*/
handleActions?: boolean;
}

/**
* Data to be sent with a `stripe.confirmWechatPayPayment` request.
* Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters.
Expand Down
35 changes: 35 additions & 0 deletions types/stripe-js/stripe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,24 @@ export interface Stripe {
options?: paymentIntents.ConfirmMobilepayPaymentOptions
): Promise<PaymentIntentResult>;

/**
* Use `stripe.confirmMultibancoPayment` in the [Multibanco Payment](https://stripe.com/docs/payments/multibanco) 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.
* Note that there are some additional requirements to this flow that are not covered in this reference.
* Refer to our [integration guide](https://stripe.com/docs/payments/multibanco) 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_multibanco_payment
*/
confirmMultibancoPayment(
clientSecret: string,
data?: paymentIntents.ConfirmMultibancoPaymentData,
options?: paymentIntents.ConfirmMultibancoPaymentOptions
): 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 Expand Up @@ -579,6 +597,23 @@ export interface Stripe {
options?: paymentIntents.ConfirmSofortPaymentOptions
): Promise<PaymentIntentResult>;

/**
* Use `stripe.confirmTwintPayment` in the [TWINT Payments with Payment Methods](https://stripe.com/docs/payments/twint) flow when the customer submits your payment form.
* When called, it will confirm the `PaymentIntent` with `data` you provide, and it will automatically redirect the customer to authorize the transaction.
* Once authorization is complete, the customer will be redirected back to your specified `return_url`.
*
* 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_twint_payment
*/
confirmTwintPayment(
clientSecret: string,
data?: paymentIntents.ConfirmTwintPaymentData,
options?: paymentIntents.ConfirmTwintPaymentOptions
): Promise<PaymentIntentResult>;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
Expand Down

0 comments on commit 8a68460

Please sign in to comment.