Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/types/src/invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,22 @@ elements.create('payment', {
},
});

// invalid type for walletOptions.emailRequired
// @ts-expect-error: No overload matches this call
elements.create('payment', {
walletOptions: {
emailRequired: 'yes',
},
});

// invalid type for walletOptions.phoneNumberRequired
// @ts-expect-error: No overload matches this call
elements.create('payment', {
walletOptions: {
phoneNumberRequired: 'yes',
},
});

paymentElement.on('change', (e) => {
// @ts-expect-error: `error` is not present on PaymentElement "change" event.
if (e.error) {
Expand Down Expand Up @@ -649,6 +665,22 @@ checkoutElementsSdk.createShippingAddressElement({
},
});

// invalid type for walletOptions.emailRequired in EwCS
checkoutElementsSdk.createPaymentElement({
walletOptions: {
// @ts-expect-error: Type 'string' is not assignable to type 'boolean | undefined'
emailRequired: 'yes',
},
});

// invalid type for walletOptions.phoneNumberRequired in EwCS
checkoutElementsSdk.createPaymentElement({
walletOptions: {
// @ts-expect-error: Type 'string' is not assignable to type 'boolean | undefined'
phoneNumberRequired: 'yes',
},
});

const checkoutFormSdk = stripe.initCheckoutFormSdk({
clientSecret: 'cs_test_foo',
});
Expand Down
17 changes: 17 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ const paymentElement: StripePaymentElement = elements.create('payment', {
googlePay: 'auto',
link: 'auto',
},
walletOptions: {
emailRequired: true,
phoneNumberRequired: true,
},
layout: {
type: 'accordion',
visibleAccordionItemsCount: 2,
Expand Down Expand Up @@ -581,6 +585,13 @@ paymentElement.update({
},
});

paymentElement.update({
walletOptions: {
emailRequired: true,
phoneNumberRequired: false,
},
});

let paymentElementDefaults: StripePaymentElement = elements.create('payment');
paymentElementDefaults = elements.create('payment', {});

Expand Down Expand Up @@ -3693,6 +3704,12 @@ const checkoutElementsSdk = stripe.initCheckoutElementsSdk({
clientSecret: 'cs_test_foo',
});
const checkoutPaymentElement: StripePaymentElement = checkoutElementsSdk.createPaymentElement();
checkoutElementsSdk.createPaymentElement({
walletOptions: {
emailRequired: true,
phoneNumberRequired: true,
},
});
checkoutElementsSdk.getPaymentElement();
const checkoutAddressElement: StripeAddressElement = checkoutElementsSdk.createBillingAddressElement();
checkoutElementsSdk.getBillingAddressElement();
Expand Down
2 changes: 2 additions & 0 deletions types/stripe-js/checkout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Layout,
TermsOption,
StripePaymentElement,
PaymentWalletOptionsOption,
} from './elements/payment';
import {ContactOption, StripeAddressElement} from './elements/address';
import {Appearance, CssFontSource, CustomFontSource} from './elements-group';
Expand Down Expand Up @@ -405,6 +406,7 @@ export type StripeCheckoutPaymentElementOptions = {
terms?: TermsOption;
fields?: FieldsOption;
wallets?: PaymentWalletsOption;
walletOptions?: PaymentWalletOptionsOption;
};

export type StripeCheckoutAddressElementOptions = {
Expand Down
10 changes: 10 additions & 0 deletions types/stripe-js/elements/payment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ export interface PaymentWalletsOption {
link?: PaymentWalletOption;
}

export interface PaymentWalletOptionsOption {
emailRequired?: boolean;
phoneNumberRequired?: boolean;
}

export type Layout = 'tabs' | 'accordion' | 'auto';
type RadiosOption = 'auto' | 'never' | 'always' | 'if_multiple';

Expand Down Expand Up @@ -390,6 +395,11 @@ export interface StripePaymentElementOptions {
*/
wallets?: PaymentWalletsOption;

/**
* Control wallet behavior options in the Payment Element.
*/
walletOptions?: PaymentWalletOptionsOption;

/**
* Specify a layout to use when rendering a Payment Element.
*/
Expand Down