From 6057dd0c814790cea7c6ece7c735c08b61252450 Mon Sep 17 00:00:00 2001 From: William Shallum Date: Wed, 12 Feb 2020 14:56:27 +0800 Subject: [PATCH 1/2] Add auBankAccount element support --- types/stripe-js/elements.d.ts | 7 +- types/stripe-js/elements/au-bank-account.d.ts | 80 +++++++++++++++++++ types/stripe-js/payment-intents.d.ts | 50 ++++++++++++ types/stripe-js/setup-intents.d.ts | 14 ++++ 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 types/stripe-js/elements/au-bank-account.d.ts diff --git a/types/stripe-js/elements.d.ts b/types/stripe-js/elements.d.ts index bb16826a..fbc55db1 100644 --- a/types/stripe-js/elements.d.ts +++ b/types/stripe-js/elements.d.ts @@ -5,6 +5,7 @@ /// /// /// +/// declare module '@stripe/stripe-js' { interface StripeElements { @@ -139,7 +140,8 @@ declare module '@stripe/stripe-js' { | 'cardCvc' | 'iban' | 'idealBank' - | 'paymentRequestButton'; + | 'paymentRequestButton' + | 'auBankAccount'; type StripeElement = | StripeCardElement @@ -148,7 +150,8 @@ declare module '@stripe/stripe-js' { | StripeCardCvcElement | StripeIbanElement | StripeIdealBankElement - | StripePaymentRequestButtonElement; + | StripePaymentRequestButtonElement + | StripeAuBankAccountElement; /** * Options to create an `Elements` instance with. diff --git a/types/stripe-js/elements/au-bank-account.d.ts b/types/stripe-js/elements/au-bank-account.d.ts new file mode 100644 index 00000000..5bc6f1ae --- /dev/null +++ b/types/stripe-js/elements/au-bank-account.d.ts @@ -0,0 +1,80 @@ +/// + +declare module '@stripe/stripe-js' { + type StripeAuBankAccountElement = StripeElementBase & { + /** + * The change event is triggered when the `Element`'s value changes. + */ + on( + eventType: 'change', + handler: (event: StripeAuBankAccountElementChangeEvent) => any + ): void; + + /** + * Triggered when the element is fully rendered and can accept `element.focus` calls. + */ + on(eventType: 'ready', handler: () => any): StripeAuBankAccountElement; + + /** + * Triggered when the element gains focus. + */ + on(eventType: 'focus', handler: () => any): StripeAuBankAccountElement; + + /** + * Triggered when the element loses focus. + */ + on(eventType: 'blur', handler: () => any): StripeAuBankAccountElement; + + /** + * Updates the options the `AuBankAccountElement` was initialized with. + * Updates are merged into the existing configuration. + * + * If you collect certain information in a different part of your interface (e.g., ZIP or postal code), use `element.update` with the appropriate information. + * + * The styles of an `AuBankAccountElement` can be dynamically changed using `element.update`. + * This method can be used to simulate CSS media queries that automatically adjust the size of elements when viewed on different devices. + */ + update(options: Partial): void; + }; + + interface StripeAuBankAccountElementOptions { + classes?: StripeElementClasses; + + style?: StripeElementStyle; + + /** + * Appearance of the icon in the Element. + */ + iconStyle?: 'default' | 'solid'; + + /** + * Hides the icon in the Element. + * Default is `false`. + */ + hideIcon?: boolean; + + /** + * Applies a disabled state to the Element such that user input is not accepted. + * Default is false. + */ + disabled?: boolean; + } + + interface StripeAuBankAccountElementChangeEvent + extends StripeElementChangeEvent { + /** + * The type of element that emitted this event. + */ + elementType: 'auBankAccount'; + + /** + * The bank name corresponding to the entered BSB. + */ + bankName?: string; + + /** + * The branch name corresponding to the entered BSB. + */ + branchName?: string; + } +} diff --git a/types/stripe-js/payment-intents.d.ts b/types/stripe-js/payment-intents.d.ts index ae07a2f1..ee5f8d47 100644 --- a/types/stripe-js/payment-intents.d.ts +++ b/types/stripe-js/payment-intents.d.ts @@ -50,6 +50,36 @@ declare module '@stripe/stripe-js' { }; } + interface CreatePaymentMethodAuBecsDebitData + extends PaymentMethodCreateParams { + type: 'au_becs_debit'; + + au_becs_debit: + | StripeAuBankAccountElement + | { + /** + * A BSB number. + */ + bsb_number: string; + + /** + * An account number. + */ + account_number: string; + }; + + /* + * The customer's billing details. + * `name` and `email` are required. + * + * @docs https://stripe.com/docs/api/payment_methods/create#create_payment_method-billing_details + */ + billing_details: PaymentMethodCreateParams.BillingDetails & { + name: string; + email: string; + }; + } + /** * Data to be sent with a `stripe.confirmCardPayment` request. * Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters. @@ -126,4 +156,24 @@ declare module '@stripe/stripe-js' { */ handleActions?: boolean; } + + /** + * Data to be sent with a `stripe.confirmAuBecsDebitPayment` request. + * Refer to the [Payment Intents API](https://stripe.com/docs/api/payment_intents/confirm) for a full list of parameters. + */ + interface ConfirmAuBecsDebitPaymentData 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; + + /** + * To save the BECS Direct Debit account for reuse, set this parameter to `off_session`. + * BECS Direct Debit only accepts an `off_session` value for this parameter. + */ + setup_future_usage?: 'off_session'; + } } diff --git a/types/stripe-js/setup-intents.d.ts b/types/stripe-js/setup-intents.d.ts index 661b80ef..2f371820 100644 --- a/types/stripe-js/setup-intents.d.ts +++ b/types/stripe-js/setup-intents.d.ts @@ -37,4 +37,18 @@ declare module '@stripe/stripe-js' { */ payment_method?: string | Omit; } + + /** + * Data to be sent with a `stripe.confirmAuBecsDebitSetup` request. + * Refer to the [Setup Intents API](https://stripe.com/docs/api/setup_intents/confirm) for a full list of parameters. + */ + interface ConfirmAuBecsDebitSetupData 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; + } } From efbddc55d2b1f4b7ce1773a3a4b65a5f8ab5e45a Mon Sep 17 00:00:00 2001 From: David Weedon Date: Thu, 13 Feb 2020 16:11:20 -0600 Subject: [PATCH 2/2] fixes --- types/stripe-js/elements.d.ts | 4 ++-- types/stripe-js/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/stripe-js/elements.d.ts b/types/stripe-js/elements.d.ts index 584fe7cb..4c62376e 100644 --- a/types/stripe-js/elements.d.ts +++ b/types/stripe-js/elements.d.ts @@ -177,6 +177,7 @@ declare module '@stripe/stripe-js' { } type StripeElementType = + | 'auBankAccount' | 'card' | 'cardNumber' | 'cardExpiry' @@ -184,8 +185,7 @@ declare module '@stripe/stripe-js' { | 'fpxBank' | 'iban' | 'idealBank' - | 'paymentRequestButton' - | 'auBankAccount'; + | 'paymentRequestButton'; type StripeElement = | StripeAuBankAccountElement diff --git a/types/stripe-js/index.d.ts b/types/stripe-js/index.d.ts index 17c28205..23c356ae 100644 --- a/types/stripe-js/index.d.ts +++ b/types/stripe-js/index.d.ts @@ -206,7 +206,7 @@ declare module '@stripe/stripe-js' { ): Promise<{setupIntent?: SetupIntent; error?: StripeError}>; /** - * Use `stripe.confirmBecsDebitSetup` in the [SEPA Direct Debit with Setup Intents](https://stripe.com/docs/payments/sepa-debit-setup-intents) flow when the customer submits your payment form. + * Use `stripe.confirmSepaDebitSetup` in the [SEPA Direct Debit with Setup Intents](https://stripe.com/docs/payments/sepa-debit-setup-intents) flow when the customer submits your payment form. * When called, it will confirm the `SetupIntent` 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/sepa-debit-setup-intents) for more details.