diff --git a/tests/types/src/valid.ts b/tests/types/src/valid.ts index fb481471..6c5042c8 100644 --- a/tests/types/src/valid.ts +++ b/tests/types/src/valid.ts @@ -573,14 +573,33 @@ cardElement console.error(e.error.message); } }) - .on('networkschange', (e: {elementType: 'card'}) => {}); + .on('networkschange', (e: {elementType: 'card'}) => {}) + .on( + 'loaderror', + (e: { + elementType: 'card'; + error: { + type: string; + }; + }) => {} + ); const onceHandler = () => {}; cardElement.once('ready', onceHandler); cardElement.off('ready', onceHandler); cardElement.off('change'); -cardNumberElement.on('networkschange', (e: {elementType: 'cardNumber'}) => {}); +cardNumberElement + .on('networkschange', (e: {elementType: 'cardNumber'}) => {}) + .on( + 'loaderror', + (e: { + elementType: 'cardNumber'; + error: { + type: string; + }; + }) => {} + ); auBankAccountElement.on( 'change', diff --git a/types/stripe-js/elements/card-number.d.ts b/types/stripe-js/elements/card-number.d.ts index fb631079..e5a8daa5 100644 --- a/types/stripe-js/elements/card-number.d.ts +++ b/types/stripe-js/elements/card-number.d.ts @@ -4,6 +4,7 @@ import { StripeElementClasses, StripeElementChangeEvent, } from './base'; +import {StripeError} from '../stripe'; import {CardNetworkBrand} from '../elements-group'; export type StripeCardNumberElement = StripeElementBase & { @@ -103,6 +104,22 @@ export type StripeCardNumberElement = StripeElementBase & { handler?: (event: {elementType: 'cardNumber'}) => any ): StripeCardNumberElement; + /** + * Triggered when the element fails to load. + */ + on( + eventType: 'loaderror', + handler: (event: {elementType: 'cardNumber'; error: StripeError}) => any + ): StripeCardNumberElement; + once( + eventType: 'loaderror', + handler: (event: {elementType: 'cardNumber'; error: StripeError}) => any + ): StripeCardNumberElement; + off( + eventType: 'loaderror', + handler?: (event: {elementType: 'cardNumber'; error: StripeError}) => any + ): StripeCardNumberElement; + /** * Updates the options the `CardNumberElement` was initialized with. * Updates are merged into the existing configuration. diff --git a/types/stripe-js/elements/card.d.ts b/types/stripe-js/elements/card.d.ts index 82297a29..e4d0344d 100644 --- a/types/stripe-js/elements/card.d.ts +++ b/types/stripe-js/elements/card.d.ts @@ -4,6 +4,7 @@ import { StripeElementClasses, StripeElementChangeEvent, } from './base'; +import {StripeError} from '../stripe'; import {CardNetworkBrand} from '../elements-group'; export type StripeCardElement = StripeElementBase & { @@ -103,6 +104,22 @@ export type StripeCardElement = StripeElementBase & { handler?: (event: {elementType: 'card'}) => any ): StripeCardElement; + /** + * Triggered when the element fails to load. + */ + on( + eventType: 'loaderror', + handler: (event: {elementType: 'card'; error: StripeError}) => any + ): StripeCardElement; + once( + eventType: 'loaderror', + handler: (event: {elementType: 'card'; error: StripeError}) => any + ): StripeCardElement; + off( + eventType: 'loaderror', + handler?: (event: {elementType: 'card'; error: StripeError}) => any + ): StripeCardElement; + /** * Updates the options the `CardElement` was initialized with. * Updates are merged into the existing configuration.