Skip to content

Commit

Permalink
Type support for for Cash App (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahp-stripe authored Mar 13, 2023
1 parent 1ef5ca9 commit 3b215c7
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,32 @@ stripe.confirmCardPayment('').then((res) => {
}
});

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

stripe
.confirmCashappPayment('', {
return_url: window.location.href,
})
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmCashappPayment(
'',
{
payment_method: '',
return_url: window.location.href,
},
{
handleActions: false,
}
)
.then((result: {paymentIntent?: PaymentIntent; error?: StripeError}) => null);

stripe
.confirmCustomerBalancePayment(
'',
Expand Down Expand Up @@ -2396,6 +2422,32 @@ stripe.confirmCardSetup('').then((res) => {
}
});

stripe
.confirmCashappSetup('', {
payment_method: '',
return_url: window.location.href,
})
.then((result: {setupIntent?: SetupIntent; error?: StripeError}) => null);

stripe
.confirmCashappSetup('', {
return_url: window.location.href,
})
.then((result: {setupIntent?: SetupIntent; error?: StripeError}) => null);

stripe
.confirmCashappSetup(
'',
{
payment_method: '',
return_url: window.location.href,
},
{
handleActions: false,
}
)
.then((result: {setupIntent?: SetupIntent; error?: StripeError}) => null);

stripe
.confirmIdealSetup('', {
payment_method: {
Expand Down
35 changes: 35 additions & 0 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type CreatePaymentMethodData =
| CreatePaymentMethodBancontactData
| CreatePaymentMethodBoletoData
| CreatePaymentMethodCardData
| CreatePaymentMethodCashappData
| CreatePaymentMethodCustomerBalanceData
| CreatePaymentMethodEpsData
| CreatePaymentMethodGiropayData
Expand Down Expand Up @@ -122,6 +123,10 @@ export interface CreatePaymentMethodCardData extends PaymentMethodCreateParams {
card: StripeCardElement | StripeCardNumberElement | {token: string};
}

interface CreatePaymentMethodCashappData extends PaymentMethodCreateParams {
type: 'cashapp';
}

export interface CreatePaymentMethodCustomerBalanceData
extends PaymentMethodCreateParams {
/**
Expand Down Expand Up @@ -643,6 +648,36 @@ export interface ConfirmCardPaymentOptions {
handleActions?: boolean;
}

/**
* Data to be sent with a `stripe.confirmCashappPayment` request.
* Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters.
*/
interface ConfirmCashappPaymentData 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<CreatePaymentMethodCashappData, '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.confirmCashappPayment`.
*/
interface ConfirmCashappPaymentOptions {
/**
* Set this to `false` if you want to [manually handle the authorization QR code or redirect](https://stripe.com/docs/payments/cash-app-pay/accept-a-payment?platform=web&ui=API#handle-redirect).
* Default is `true`.
*/
handleActions?: boolean;
}

/**
* Data to be sent with a `stripe.confirmCustomerBalancePayment` request.
* Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters.
Expand Down
27 changes: 27 additions & 0 deletions types/stripe-js/setup-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CreatePaymentMethodAuBecsDebitData,
CreatePaymentMethodBancontactData,
CreatePaymentMethodCardData,
CreatePaymentMethodCashappData,
CreatePaymentMethodIdealData,
CreatePaymentMethodSepaDebitData,
CreatePaymentMethodSofortData,
Expand Down Expand Up @@ -41,6 +42,32 @@ export interface ConfirmCardSetupOptions {
handleActions?: boolean;
}

interface ConfirmCashappSetupData extends SetupIntentConfirmParams {
/*
* 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 `SetupIntent`.
*
* @recommended
*/
payment_method?: string | Omit<CreatePaymentMethodCashappData, '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.confirmCashappSetup`.
*/
interface ConfirmCashappSetupOptions {
/*
* Set this to `false` if you want to [manually handle the authorization QR code or redirect](https://stripe.com/docs/payments/cash-app-pay/set-up-payment?platform=web&ui=API#web-create-setup-intent).
* Default is `true`.
*/
handleActions?: boolean;
}

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

/**
* Use `stripe.confirmCashappPayment` in the [Cash App Payments](https://stripe.com/docs/payments/cash-app-pay) 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://stripe.com/docs/payments/cash-app-pay) 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_cashapp_payment
*/
confirmCashappPayment(
clientSecret: string,
data?: paymentIntents.ConfirmCashappPaymentData,
options?: paymentIntents.ConfirmCashappPaymentOptions
): Promise<PaymentIntentResult>;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
Expand Down Expand Up @@ -697,6 +714,23 @@ export interface Stripe {
options?: setupIntents.ConfirmCardSetupOptions
): Promise<SetupIntentResult>;

/**
* Use `stripe.confirmCashappSetup` in the [Setup Intents API flow](https://stripe.com/docs/payments/save-and-reuse) when the customer submits your payment form.
* When called, it will confirm the [SetupIntent](https://stripe.com/docs/api/setup_intents) with `data` you provide.
* Refer to our [integration guide](https://stripe.com/docs/payments/cash-app-pay) for more details..
*
* When you confirm a `SetupIntent`, it needs to have an attached [PaymentMethod](https://stripe.com/docs/api/payment_methods).
* In addition to confirming the `SetupIntent`, this method can automatically create and attach a new `PaymentMethod` for you.
* It can also be called with an existing `PaymentMethod`, or 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_cashapp_setup
*/
confirmCashappSetup(
clientSecret: string,
data?: setupIntents.ConfirmCashappSetupData,
options?: setupIntents.ConfirmCashappSetupOptions
): Promise<SetupIntentResult>;

/**
* Use `stripe.confirmIdealSetup` in the [Set up future payments](https://stripe.com/docs/payments/ideal/set-up-payment) flow to use iDEAL bank details to set up a SEPA Direct Debit payment method for future payments.
* When called, it will confirm a `SetupIntent` with `data` you provide, and it will automatically redirect the customer to authorize the transaction.
Expand Down

0 comments on commit 3b215c7

Please sign in to comment.