Skip to content

Commit

Permalink
Update types and methods for EPS, now that we have beta element (stri…
Browse files Browse the repository at this point in the history
…pe#111)

* eps types, methods

* remove beta references + restore deleted test
  • Loading branch information
yaw-stripe authored Oct 26, 2020
1 parent bc8f410 commit 35acd01
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
CustomFontSource,
StripeIbanElement,
StripeIdealBankElement,
StripeEpsBankElement,
StripeFpxBankElement,
StripeFpxBankElementChangeEvent,
StripeAuBankAccountElement,
Expand Down Expand Up @@ -190,6 +191,16 @@ const retrievedPaymentRequestButtonElement: StripePaymentRequestButtonElement |
// Make sure that `paymentRequest` is at least optional;
retrievedPaymentRequestButtonElement!.update({});

const epsBankElement = elements.create('epsBank', {
style: MY_STYLE,
value: '',
classes: {webkitAutoFill: ''},
});

const retrievedEpsBankElement: StripeEpsBankElement | null = elements.getElement(
'epsBank'
);

type StripePaymentRequestButtonElementUpdateOptions = Parameters<
StripePaymentRequestButtonElement['update']
>[0];
Expand Down Expand Up @@ -407,7 +418,18 @@ stripe.confirmCardPayment('');
stripe.confirmCardPayment('');

stripe.confirmEpsPayment('', {
payment_method: {billing_details: {name: 'Jenny Rosen'}},
payment_method: {
eps: {bank: 'bank_austria'},
billing_details: {name: 'Jenny Rosen'},
},
return_url: window.location.href,
});

stripe.confirmEpsPayment('', {
payment_method: {
eps: epsBankElement,
billing_details: {name: 'Jenny Rosen'},
},
return_url: window.location.href,
});

Expand Down
9 changes: 9 additions & 0 deletions types/api/PaymentMethods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ declare module '@stripe/stripe-js' {
*/
customer: string | null;

eps?: PaymentMethod.Eps;

fpx?: PaymentMethod.Fpx;

ideal?: PaymentMethod.Ideal;
Expand Down Expand Up @@ -171,6 +173,13 @@ declare module '@stripe/stripe-js' {

interface CardPresent {}

interface Eps {
/**
* The customer's bank.
*/
bank: string;
}

interface Fpx {
/**
* The customer's bank.
Expand Down
26 changes: 26 additions & 0 deletions types/stripe-js/elements.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
///<reference path='./elements/fpx-bank.d.ts' />
///<reference path='./elements/payment-request-button.d.ts' />
///<reference path='./elements/au-bank-account.d.ts' />
///<reference path='./elements/eps-bank.d.ts' />

import {StripeAuBankAccountElement} from '@stripe/stripe-js';

Expand Down Expand Up @@ -120,6 +121,29 @@ declare module '@stripe/stripe-js' {
*/
getElement(elementType: 'fpxBank'): StripeFpxBankElement | null;

/////////////////////////////
/// epsBank
/////////////////////////////

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Creates an `EpsBankElement`.
*/
create(
elementType: 'epsBank',
options: StripeEpsBankElementOptions
): StripeEpsBankElement;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Looks up a previously created `Element` by its type.
*/
getElement(elementType: 'epsBank'): StripeEpsBankElement | null;

/////////////////////////////
/// iban
/////////////////////////////
Expand Down Expand Up @@ -182,6 +206,7 @@ declare module '@stripe/stripe-js' {
| 'cardNumber'
| 'cardExpiry'
| 'cardCvc'
| 'epsBank'
| 'fpxBank'
| 'iban'
| 'idealBank'
Expand All @@ -193,6 +218,7 @@ declare module '@stripe/stripe-js' {
| StripeCardNumberElement
| StripeCardExpiryElement
| StripeCardCvcElement
| StripeEpsBankElement
| StripeFpxBankElement
| StripeIbanElement
| StripeIdealBankElement
Expand Down
84 changes: 84 additions & 0 deletions types/stripe-js/elements/eps-bank.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
///<reference path='./base.d.ts' />

declare module '@stripe/stripe-js' {
type StripeEpsBankElement = StripeElementBase & {
/**
* The change event is triggered when the `Element`'s value changes.
*/
on(
eventType: 'change',
handler: (event: StripeEpsBankElementChangeEvent) => any
): StripeEpsBankElement;

/**
* Triggered when the element is fully rendered and can accept `element.focus` calls.
*/
on(eventType: 'ready', handler: () => any): StripeEpsBankElement;

/**
* Triggered when the element gains focus.
*/
on(eventType: 'focus', handler: () => any): StripeEpsBankElement;

/**
* Triggered when the element loses focus.
*/
on(eventType: 'blur', handler: () => any): StripeEpsBankElement;

/**
* Triggered when the escape key is pressed within the element.
*/
on(eventType: 'escape', handler: () => any): StripeEpsBankElement;

/**
* Updates the options the `EpsBankElement` was initialized with.
* Updates are merged into the existing configuration.
*
* The styles of an `EpsBankElement` 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<StripeEpsBankElementOptions>): void;
};

interface StripeEpsBankElementOptions {
classes?: StripeElementClasses;

style?: StripeElementStyle;

/**
* Appearance of the icon in the Element.
*/
iconStyle?: 'default' | 'solid';

/**
* A pre-filled value for the Element.
* Can be one of the banks listed in the [EPS guide](https://stripe.com/docs/payments/eps/accept-a-payment#bank-values) (e.g., `bank_austria`).
*/
value?: string;

/**
* 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 StripeEpsBankElementChangeEvent extends StripeElementChangeEvent {
/**
* The type of element that emitted this event.
*/
elementType: 'epsBank';

/**
* A pre-filled value for the Element.
* Can be one of the banks listed in the [EPS guide](https://stripe.com/docs/payments/eps/accept-a-payment#bank-values) (e.g., `bank_austria`).
*/
value?: string;
}
}
9 changes: 9 additions & 0 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ declare module '@stripe/stripe-js' {
billing_details: PaymentMethodCreateParams.BillingDetails & {
name: string;
};

eps:
| StripeEpsBankElement
| {
/**
* The customer's bank
*/
bank?: string;
};
}

interface CreatePaymentMethodFpxData extends PaymentMethodCreateParams {
Expand Down

0 comments on commit 35acd01

Please sign in to comment.