Skip to content

Commit

Permalink
Add bindings for CurrencySelectorElement (#669)
Browse files Browse the repository at this point in the history
Co-authored-by: Polo Li <65737086+pololi-stripe@users.noreply.github.com>
  • Loading branch information
jackieosborn-stripe and pololi-stripe authored Oct 18, 2024
1 parent 7d39b66 commit dba6332
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 15 deletions.
9 changes: 9 additions & 0 deletions tests/types/src/invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StripePaymentElement,
StripeExpressCheckoutElement,
StripeElementsOptions,
StripeCurrencySelectorElement,
} from '../../../types';
import {ApplePayUpdateOption} from '../../../types/stripe-js/elements/apple-pay';

Expand All @@ -15,6 +16,7 @@ declare const cardNumberElement: StripeCardNumberElement;
declare const ibanElement: StripeIbanElement;
declare const paymentElement: StripePaymentElement;
declare const expressCheckoutElement: StripeExpressCheckoutElement;
declare const currencySelectorElement: StripeCurrencySelectorElement;

const options: StripeElementsOptions = {
clientSecret: '',
Expand Down Expand Up @@ -224,6 +226,13 @@ expressCheckoutElement.on('click', ({resolve}) => {
});
});

// @ts-expect-error: CurrencySelector cannot be created from Elements
elements.create('currencySelector');
// @ts-expect-error: CurrencySelector cannot be retrieved from Elements
elements.getElement('currencySelector');
// @ts-expect-error: CurrencySelector cannot be updated
currencySelectorElement.update({});

// @ts-expect-error: AddressElement requires a mode
elements.create('address');

Expand Down
18 changes: 18 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
StripeElementsOptions,
CardBrand,
CardFunding,
StripeCurrencySelectorElement,
} from '../../../types';

const stripePromise: Promise<Stripe | null> = loadStripe('');
Expand Down Expand Up @@ -1137,11 +1138,28 @@ expressCheckoutElement.on(

const retrievedExpressCheckoutElement = elements.getElement('expressCheckout');

declare const currencySelectorElement: StripeCurrencySelectorElement;

currencySelectorElement
.on('ready', (e: {elementType: 'currencySelector'}) => {})
.on('focus', (e: {elementType: 'currencySelector'}) => {})
.on('blur', (e: {elementType: 'currencySelector'}) => {})
.on(
'loaderror',
(e: {
elementType: 'currencySelector';
error: {
type: string;
};
}) => {}
);

auBankAccountElement.destroy();
cardElement.destroy();
cardNumberElement.destroy();
cardCvcElement.destroy();
cardExpiryElement.destroy();
currencySelectorElement.destroy();
fpxBankElement.destroy();
ibanElement.destroy();
idealBankElement.destroy();
Expand Down
3 changes: 0 additions & 3 deletions types/api/confirmation-tokens.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ export interface ConfirmationTokenCreateParams {
billing_details?: PaymentMethodCreateParams.BillingDetails;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Specifies if the PaymentMethod should be redisplayed when using the Saved Payment Method feature
*/
allow_redisplay?: 'always' | 'limited' | 'unspecified';
Expand Down
14 changes: 14 additions & 0 deletions types/stripe-js/custom-checkout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {Appearance, CssFontSource, CustomFontSource} from './elements-group';
import {StripeError} from './stripe';
import {
StripeCurrencySelectorElement,
FieldsOption,
StripeElementBase,
StripeExpressCheckoutElement,
Expand Down Expand Up @@ -204,13 +205,20 @@ export type StripeCustomCheckoutTrial = {
trialPeriodDays: number;
};

export type StripeCustomCheckoutCurrencyOption = {
unitAmount: number;
currency: string;
currencyConversion?: {fxRate: number; sourceCurrency: string};
};

/* Custom Checkout session */
export interface StripeCustomCheckoutSession {
billingAddress: StripeCustomCheckoutContact | null;
businessName: string | null;
canConfirm: boolean;
confirmationRequirements: StripeCustomCheckoutConfirmationRequirement[];
currency: string;
currencyOptions: Array<StripeCustomCheckoutCurrencyOption> | null;
discountAmounts: Array<StripeCustomCheckoutDiscountAmount> | null;
email: string | null;
id: string;
Expand Down Expand Up @@ -427,6 +435,10 @@ export interface StripeCustomCheckout {
getElement(
elementType: 'expressCheckout'
): StripeCustomCheckoutExpressCheckoutElement | null;
/* Requires beta access: Contact [Stripe support](https://support.stripe.com/) for more information. */
getElement(
elementType: 'currencySelector'
): StripeCurrencySelectorElement | null;
createElement(
elementType: 'payment',
options?: StripeCustomCheckoutPaymentElementOptions
Expand All @@ -439,4 +451,6 @@ export interface StripeCustomCheckout {
elementType: 'expressCheckout',
options: StripeCustomCheckoutExpressCheckoutElementOptions
): StripeCustomCheckoutExpressCheckoutElement;
/* Requires beta access: Contact [Stripe support](https://support.stripe.com/) for more information. */
createElement(elementType: 'currencySelector'): StripeCurrencySelectorElement;
}
9 changes: 3 additions & 6 deletions types/stripe-js/elements-group.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
StripeAddressElement,
StripeAddressElementOptions,
StripeCurrencySelectorElement,
StripeShippingAddressElement,
StripeShippingAddressElementOptions,
StripePaymentRequestButtonElement,
Expand Down Expand Up @@ -332,9 +333,6 @@ export interface StripeElements {
/////////////////////////////

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Creates a `LinkAuthenticationElement`.
*/
create(
Expand All @@ -343,9 +341,6 @@ export interface StripeElements {
): StripeLinkAuthenticationElement;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Looks up a previously created `Element` by its type.
*/
getElement(
Expand Down Expand Up @@ -500,6 +495,7 @@ export type StripeElementType =
| 'cardNumber'
| 'cardExpiry'
| 'cardCvc'
| 'currencySelector'
| 'epsBank'
| 'expressCheckout'
| 'fpxBank'
Expand Down Expand Up @@ -531,6 +527,7 @@ export type StripeElement =
| StripeIbanElement
| StripeIdealBankElement
| StripeP24BankElement
| StripeCurrencySelectorElement
| StripeExpressCheckoutElement
| StripePaymentElement
| StripePaymentMethodMessagingElement
Expand Down
93 changes: 93 additions & 0 deletions types/stripe-js/elements/currency-selector.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {StripeElementBase} from './base';
import {StripeError} from '../stripe';

export type StripeCurrencySelectorElement = StripeElementBase & {
/**
* Triggered when the element is fully rendered and can accept `element.focus` calls.
*/
on(
eventType: 'ready',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
once(
eventType: 'ready',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
off(
eventType: 'ready',
handler?: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;

/**
* Triggered when the element gains focus.
*/
on(
eventType: 'focus',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
once(
eventType: 'focus',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
off(
eventType: 'focus',
handler?: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;

/**
* Triggered when the element loses focus.
*/
on(
eventType: 'blur',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
once(
eventType: 'blur',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
off(
eventType: 'blur',
handler?: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;

/**
* Triggered when the escape key is pressed within the element.
*/
on(
eventType: 'escape',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
once(
eventType: 'escape',
handler: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;
off(
eventType: 'escape',
handler?: (event: {elementType: 'currencySelector'}) => any
): StripeCurrencySelectorElement;

/**
* Triggered when the element fails to load.
*/
on(
eventType: 'loaderror',
handler: (event: {
elementType: 'currencySelector';
error: StripeError;
}) => any
): StripeCurrencySelectorElement;
once(
eventType: 'loaderror',
handler: (event: {
elementType: 'currencySelector';
error: StripeError;
}) => any
): StripeCurrencySelectorElement;
off(
eventType: 'loaderror',
handler?: (event: {
elementType: 'currencySelector';
error: StripeError;
}) => any
): StripeCurrencySelectorElement;
};
1 change: 1 addition & 0 deletions types/stripe-js/elements/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './card-cvc';
export * from './card-expiry';
export * from './card-number';
export * from './card';
export * from './currency-selector';
export * from './eps-bank';
export * from './express-checkout';
export * from './fpx-bank';
Expand Down
3 changes: 0 additions & 3 deletions types/stripe-js/payment-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,6 @@ export interface ConfirmPaymentData extends PaymentIntentConfirmParams {
billing_details?: PaymentMethodCreateParams.BillingDetails;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Specifies if the PaymentMethod should be redisplayed when using the Saved Payment Method feature
*/
allow_redisplay?: 'always' | 'limited' | 'unspecified';
Expand Down
3 changes: 0 additions & 3 deletions types/stripe-js/setup-intents.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export interface ConfirmSetupData extends SetupIntentConfirmParams {
billing_details?: PaymentMethodCreateParams.BillingDetails;

/**
* Requires beta access:
* Contact [Stripe support](https://support.stripe.com/) for more information.
*
* Specifies if the PaymentMethod should be redisplayed when using the Saved Payment Method feature
*/
allow_redisplay?: 'always' | 'limited' | 'unspecified';
Expand Down

0 comments on commit dba6332

Please sign in to comment.