Skip to content

Commit

Permalink
Add loaderror to card and cardNumber elements (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinalong-stripe authored Apr 3, 2024
1 parent cfd6efa commit a91238b
Showing 3 changed files with 55 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
@@ -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',
17 changes: 17 additions & 0 deletions types/stripe-js/elements/card-number.d.ts
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 17 additions & 0 deletions types/stripe-js/elements/card.d.ts
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit a91238b

Please sign in to comment.