Skip to content

Commit

Permalink
Duplicate types
Browse files Browse the repository at this point in the history
  • Loading branch information
danwang-stripe committed Mar 2, 2024
1 parent 7c7e211 commit e80ef80
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 70 deletions.
150 changes: 119 additions & 31 deletions types/stripe-js/custom-checkout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ import {StripeError} from './stripe';
import {
StripeElementBase,
StripeExpressCheckoutElement,
StripeExpressCheckoutElementBlur,
StripeExpressCheckoutElementConfirmEvent,
StripeExpressCheckoutElementEscape,
StripeExpressCheckoutElementFocus,
StripeExpressCheckoutElementLoaderror,
StripeExpressCheckoutElementOptions,
StripeExpressCheckoutElementReady,
StripeExpressCheckoutElementReadyEvent,
} from './elements';

/**
Expand Down Expand Up @@ -235,32 +231,124 @@ export type StripeCustomCheckoutExpressCheckoutElementConfirmEvent = StripeExpre
confirm: () => Promise<StripeCustomCheckoutResult>;
};

export type StripeCustomCheckoutExpressCheckoutElement = StripeElementBase &
StripeExpressCheckoutElementReady &
StripeExpressCheckoutElementFocus &
StripeExpressCheckoutElementBlur &
StripeExpressCheckoutElementEscape &
StripeExpressCheckoutElementLoaderror & {
update: StripeExpressCheckoutElement['update'];
on(
eventType: 'confirm',
handler: (
event: StripeCustomCheckoutExpressCheckoutElementConfirmEvent
) => any
): StripeCustomCheckoutExpressCheckoutElement;
once(
eventType: 'confirm',
handler: (
event: StripeCustomCheckoutExpressCheckoutElementConfirmEvent
) => any
): StripeCustomCheckoutExpressCheckoutElement;
off(
eventType: 'confirm',
handler?: (
event: StripeCustomCheckoutExpressCheckoutElementConfirmEvent
) => any
): StripeCustomCheckoutExpressCheckoutElement;
};
export type StripeCustomCheckoutExpressCheckoutElement = StripeElementBase & {
/**
* Triggered when the element is fully rendered and can accept `element.focus` calls.
*/
on(
eventType: 'ready',
handler: (event: StripeExpressCheckoutElementReadyEvent) => any
): StripeCustomCheckoutExpressCheckoutElement;
once(
eventType: 'ready',
handler: (event: StripeExpressCheckoutElementReadyEvent) => any
): StripeCustomCheckoutExpressCheckoutElement;
off(
eventType: 'ready',
handler?: (event: StripeExpressCheckoutElementReadyEvent) => any
): StripeCustomCheckoutExpressCheckoutElement;

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

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

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

/**
* Triggered when the element fails to load.
*/
on(
eventType: 'loaderror',
handler: (event: {
elementType: 'expressCheckout';
error: StripeError;
}) => any
): StripeCustomCheckoutExpressCheckoutElement;
once(
eventType: 'loaderror',
handler: (event: {
elementType: 'expressCheckout';
error: StripeError;
}) => any
): StripeCustomCheckoutExpressCheckoutElement;
off(
eventType: 'loaderror',
handler?: (event: {
elementType: 'expressCheckout';
error: StripeError;
}) => any
): StripeCustomCheckoutExpressCheckoutElement;

/**
* Triggered when a buyer authorizes a payment within a supported payment method.
*/
on(
eventType: 'confirm',
handler: (
event: StripeCustomCheckoutExpressCheckoutElementConfirmEvent
) => any
): StripeCustomCheckoutExpressCheckoutElement;
once(
eventType: 'confirm',
handler: (
event: StripeCustomCheckoutExpressCheckoutElementConfirmEvent
) => any
): StripeCustomCheckoutExpressCheckoutElement;
off(
eventType: 'confirm',
handler?: (
event: StripeCustomCheckoutExpressCheckoutElementConfirmEvent
) => any
): StripeCustomCheckoutExpressCheckoutElement;

/**
* Updates the options the `ExpressCheckoutElement` was initialized with.
* Updates are merged into the existing configuration.
*/
update: StripeExpressCheckoutElement['update'];
};

export interface StripeCustomCheckout {
/* Custom Checkout methods */
Expand Down
48 changes: 9 additions & 39 deletions types/stripe-js/elements/express-checkout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {StripeElementBase} from './base';
import {StripeError} from '../stripe';
import {ApplePayOption, ApplePayUpdateOption} from './apple-pay';

export type StripeExpressCheckoutElementReady = {
export type StripeExpressCheckoutElement = StripeElementBase & {
/**
* Triggered when the element is fully rendered and can accept `element.focus` calls.
*/
Expand All @@ -18,9 +18,7 @@ export type StripeExpressCheckoutElementReady = {
eventType: 'ready',
handler?: (event: StripeExpressCheckoutElementReadyEvent) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementClick = {
/**
* Triggered when a button on the element is clicked.
*/
Expand All @@ -36,9 +34,7 @@ export type StripeExpressCheckoutElementClick = {
eventType: 'click',
handler?: (event: StripeExpressCheckoutElementClickEvent) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementFocus = {
/**
* Triggered when the element gains focus.
*/
Expand All @@ -54,9 +50,7 @@ export type StripeExpressCheckoutElementFocus = {
eventType: 'focus',
handler?: (event: {elementType: 'expressCheckout'}) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementBlur = {
/**
* Triggered when the element loses focus.
*/
Expand All @@ -72,9 +66,7 @@ export type StripeExpressCheckoutElementBlur = {
eventType: 'blur',
handler?: (event: {elementType: 'expressCheckout'}) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementEscape = {
/**
* Triggered when the escape key is pressed within the element.
*/
Expand All @@ -90,9 +82,7 @@ export type StripeExpressCheckoutElementEscape = {
eventType: 'escape',
handler?: (event: {elementType: 'expressCheckout'}) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementLoaderror = {
/**
* Triggered when the element fails to load.
*/
Expand All @@ -117,9 +107,7 @@ export type StripeExpressCheckoutElementLoaderror = {
error: StripeError;
}) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementConfirm = {
/**
* Triggered when a buyer authorizes a payment within a supported payment method.
*/
Expand All @@ -135,9 +123,7 @@ export type StripeExpressCheckoutElementConfirm = {
eventType: 'confirm',
handler?: (event: StripeExpressCheckoutElementConfirmEvent) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementCancel = {
/**
* Triggered when a payment interface is dismissed (e.g., a buyer closes the payment interface)
*/
Expand All @@ -153,9 +139,7 @@ export type StripeExpressCheckoutElementCancel = {
eventType: 'cancel',
handler?: (event: {elementType: 'expressCheckout'}) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementShippingaddresschange = {
/**
* Triggered when a buyer selects a different shipping address.
*/
Expand All @@ -177,9 +161,7 @@ export type StripeExpressCheckoutElementShippingaddresschange = {
event: StripeExpressCheckoutElementShippingAddressChangeEvent
) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElementShippingratechange = {
/**
* Triggered when a buyer selects a different shipping rate.
*/
Expand All @@ -197,27 +179,15 @@ export type StripeExpressCheckoutElementShippingratechange = {
event: StripeExpressCheckoutElementShippingRateChangeEvent
) => any
): StripeExpressCheckoutElement;
};

export type StripeExpressCheckoutElement = StripeElementBase &
StripeExpressCheckoutElementReady &
StripeExpressCheckoutElementClick &
StripeExpressCheckoutElementFocus &
StripeExpressCheckoutElementBlur &
StripeExpressCheckoutElementEscape &
StripeExpressCheckoutElementLoaderror &
StripeExpressCheckoutElementConfirm &
StripeExpressCheckoutElementCancel &
StripeExpressCheckoutElementShippingaddresschange &
StripeExpressCheckoutElementShippingratechange & {
/**
* Updates the options the `ExpressCheckoutElement` was initialized with.
* Updates are merged into the existing configuration.
*/
update(
options: StripeExpressCheckoutElementUpdateOptions
): StripeExpressCheckoutElement;
};
/**
* Updates the options the `ExpressCheckoutElement` was initialized with.
* Updates are merged into the existing configuration.
*/
update(
options: StripeExpressCheckoutElementUpdateOptions
): StripeExpressCheckoutElement;
};

export type ExpressPaymentType = 'google_pay' | 'apple_pay' | 'link' | 'paypal';

Expand Down

0 comments on commit e80ef80

Please sign in to comment.