Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document new options and update method in shipping address element #339

Merged
merged 6 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/types/src/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,14 @@ const shippingAddressElement = elements.create('shippingAddress', {
},
},
disableAutocomplete: true,
fields: {
phone: 'always',
},
validation: {
phone: {
required: 'never',
},
},
});

shippingAddressElement
Expand All @@ -525,6 +533,14 @@ shippingAddressElement
}) => {}
);

shippingAddressElement.update({
validation: {
phone: {
required: 'always',
},
},
});

const retrievedShippingAddressElement: StripeShippingAddressElement | null = elements.getElement(
'shippingAddress'
);
Expand Down
26 changes: 26 additions & 0 deletions types/stripe-js/elements/shipping-address.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ export type StripeShippingAddressElement = StripeElementBase & {
eventType: 'loaderstart',
handler?: (event: {elementType: 'shippingAddress'}) => any
): StripeShippingAddressElement;

/**
* Updates the options the `ShippingAddressElement` was initialized with.
* Updates are merged into the existing configuration.
*/
update(
options: Partial<StripeShippingAddressElementOptions>
): StripeShippingAddressElement;
};

export interface StripeShippingAddressElementOptions {
Expand All @@ -148,12 +156,29 @@ export interface StripeShippingAddressElementOptions {
postal_code?: string | null;
country: string;
};
phone?: string | null;
};

/**
* Whether or not ShippingAddressElement provides autocomplete suggestions
*/
disableAutocomplete?: boolean;

/**
* Control which additional fields to display in the shippingAddress Element.
*/
fields?: {
phone?: 'always' | 'never' | 'auto';
};

/**
* Specify validation rules for the above additional fields.
*/
validation?: {
phone?: {
required: 'always' | 'never' | 'auto';
};
};
}

export interface StripeShippingAddressElementChangeEvent
Expand Down Expand Up @@ -191,5 +216,6 @@ export interface StripeShippingAddressElementChangeEvent
postal_code: string;
country: string;
};
phone?: string;
};
}