## The Element Use `Element` instances to collect sensitive information in your checkout flow. ## The Payment Element The [Payment Element](https://docs.stripe.com/payments/payment-element.md) is an embeddable component for securely collecting payment details. The Payment Element supports dozens of payment methods with a single integration. ## Create the Payment Element `elements.create(type: 'payment', options?: object)` This method creates an instance of the Payment Element. - `type` The type of Element being created, which is `payment` in this case. - `options` Options for creating the Payment Element. - `layout` Specify the layout for the Payment Element. If you only pass a layout type (`'accordion'` or `‘tabs’`) without any additional parameters, the Payment Element renders using that layout and the default values associated with it. An object can also be passed to specify the layout with additional configuration. - `type` Defines the layout to render the Payment Element. - `defaultCollapsed` Controls if the Payment Element renders in a collapsed state (where no payment method is selected by default). When you leave this `undefined`, Stripe renders the experience that it determines will have the best conversion. - `radios` Controls when to render each Payment Method with a radio input next to its logo. The radios visually indicate the current selection of the Payment Element. Defaults to `'auto'`. - `'always'` — Always show radio inputs. - `'never'` — Never show radio inputs. - `'if_multiple'` — Show radio inputs only when there are multiple payment methods available. When there is only one payment method, no radio input is displayed. - `'auto'` — Stripe determines the best experience to optimize conversion. _This property is only applicable to the `accordion` layout._ - `spacedAccordionItems` When `true`, the Payment Methods render as standalone buttons with space in between them. _This property is only applicable to the `accordion` layout._ - `visibleAccordionItemsCount` Sets the max number of Payment Methods visible before using the "More" button to hide additional Payment Methods. Set this value to `0` to disable the "More" button and render all available Payment Methods. Default is `5`. _This property is only applicable to the `accordion` layout._ - `paymentMethodLogoPosition` Sets the position of the payment method logo in each accordion item. Default is `start`. _This property is only applicable to the `accordion` layout._ - `defaultValues` Provide initial customer information that will be displayed in the Payment Element. The form will render with empty fields if not provided. - `billingDetails` Specify customer's billing details, which lets you pre-fill a customer’s name, email, phone number and address if required by payment method. Pre-filling as much information as possible streamlines the checkout process. - `name` - `email` - `phone` - `address` - `line1` - `line2` - `city` The name of a city, town, village, etc. - `state` The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines. - `country` Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2. - `postal_code` The postal code or ZIP code, also known as PIN code in India. - `paymentMethods` Specify customer's default information for different payment methods. Pre-filling as much information as possible streamlines the checkout process. - `ideal` - `bank` A pre-filled iDEAL bank value for the Payment Element. Can only be one of the banks listed in the [iDEAL guide](https://docs.stripe.com/payments/ideal/accept-a-payment?ui=element.md#bank-reference) (e.g., `abn_amro`). - `payto` - `usePayId` When `true`, the PayTo payment method will default to showing the PayID input instead of BSB/account number fields. Customers can still switch between PayID and BSB/account number using the toggle link. - `card` Specify default settings for card payments. - `network` Specifies a network preference for [Card Brand Choice](https://docs.stripe.com/card-brand-choice.md). The first network in the array that matches a network on the entered co-branded card will be selected by default in the Card Brand Choice dropdown. See the [supported networks](https://docs.stripe.com/api/payment_methods/create.md#create_payment_method-card-networks-preferred) for valid values. - `business` Provide information about your business that will be displayed in the Payment Element. This information will be retrieved from your Stripe account if not provided. - `name` The name of your business. Your business name will be used to render mandate text for some payment methods. - `paymentMethodOrder` By default, the Payment Element will use a dynamic ordering that optimizes payment method display for each user. You can override the default order in which payment methods are displayed in the Payment Element with a list of payment method types. If the associated PaymentIntent has payment method types not specified in `paymentMethodOrder`, they will be displayed after the payment methods you specify. If you specify payment method types not on the associated PaymentIntent, they will be ignored. - `fields` By default, the Payment Element will collect all necessary details to complete a payment. For some payment methods, this means that the Payment Element will collect details like name or email that you may have already collected from the user. If this is the case, you can prevent the Payment Element from collecting these data by using the `fields` option. If you disable the collection of a certain field with the `fields` option, you must pass that same data to [stripe.confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment.md) or the payment will be rejected. Learn more about how to [customize which billing details to collect](https://docs.stripe.com/payments/payment-element/control-billing-details-collection.md) and see [below](https://docs.stripe.com/js/elements_object/create_payment_element.md#payment_element_create-customized_fields) for details. - `billingDetails` Specify `never` to avoid collecting all [billing details](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details) in the Payment Element. If you would like to disable only certain billing details, pass an object specifying which fields you would like to disable collection for. The default setting for each field or object is `auto`. - `name` - `email` - `phone` - `address` Specify `if_required` to only collect the minimum billing address fields required to complete the payment. You can omit and hide optional address fields in the card form, such as country and postal code. Unlike the `never` option, you don't need to include fields omitted in the Payment Element when confirming the payment. This can reduce the amount of information required to complete the form. Disabling address collection can negatively impact authorization rates and network fees for users on a network cost plus pricing plan. - `line1` - `line2` - `city` The name of a city, town, village, etc. - `state` The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines. - `country` Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2. - `postalCode` The postal code or ZIP code, also known as PIN code in India. - `readOnly` Applies a read-only state to the Payment Element so that payment details can’t be changed. Default is false. Enabling the `readOnly` option doesn't change the Payment Element's visual appearance. If you want to adjust the way the Payment Element looks, use the [Appearance API](https://docs.stripe.com/elements/appearance-api.md). - `terms` Control how mandates or other legal agreements are displayed in the Payment Element. Use `never` to never display legal agreements. The default setting is `auto`, which causes legal agreements to only be shown when necessary. Consult your legal and compliance advisors before making any changes to the text of mandates or legal agreements. You can't use the `terms` option to violate obligations under your Stripe agreement, Stripe policies, applicable laws or scheme rules. - `applePay` - `auBecsDebit` - `bancontact` - `card` - `cashapp` - `googlePay` - `ideal` - `paypal` - `sepaDebit` - `sofort` - `usBankAccount` - `wallets` By default, the Payment Element will display all the payment methods that the underlying Payment Intent was created with. However, wallets like Apple Pay and Google Pay are not payment methods per the Payment Intent API. They will show when the Payment Intent has the `card` payment method and the customer is using a supported platform and have an active card in their account. This is the `auto` behavior, and it is the default for choice for all wallets. If you do not want to show a given wallet as a payment option, you can set its property in `wallets` to `never`. - `applePay` - `googlePay` - `link` - `applePay` Specify Apple Pay specific options. These are passed through to the Apple Pay API. - `recurringPaymentRequest` Specify a request to set up a recurring payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `regularBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `trialBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `billingAgreement` - `deferredPaymentRequest` Specify a request to set up a deferred payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaydeferredpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `deferredBilling` - `amount` - `label` - `deferredPaymentDate` - `billingAgreement` - `freeCancellationDate` If set, you must also supply a freeCancellationDateTimeZone., - `freeCancellationDateTimeZone` "If set, you must also supply a freeCancellationDate., - `automaticReloadPaymentRequest` Specify a request to set up an automatic reload payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayautomaticreloadpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `automaticReloadBilling` - `amount` - `label` - `automaticReloadPaymentThresholdAmount` - `billingAgreement` ### with customized fields ### Option parameter - `fields` Pass an object to specify payment `fields` you don't want to collect with the Payment Element. - `billingDetails` Specify `never` to avoid collecting all [billing details](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details) in the Payment Element. If you would like to disable only certain billing details, pass an object specifying which fields you would like to disable collection for. The default setting for each field or object is `auto`. - `name` - `email` - `phone` - `address` Specify `if_required` to only collect the minimum billing address fields required to complete the payment. You can omit and hide optional address fields in the card form, such as country and postal code. Unlike the `never` option, you don't need to include fields omitted in the Payment Element when confirming the payment. This can reduce the amount of information required to complete the form. Disabling address collection can negatively impact authorization rates and network fees for users on a network cost plus pricing plan. - `line1` - `line2` - `city` The name of a city, town, village, etc. - `state` The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines. - `country` Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2. - `postalCode` The postal code or ZIP code, also known as PIN code in India. ### Example ```title Create a Payment Element with customized fields ``` ### Example ```title Create a Payment Element ``` ## Get a Payment Element `elements.getElement(type: 'payment')` This method retrieves a previously created Payment Element. - `type` The type of Element being retrieved, which is `payment` in this case. ### Example ```title Get a Payment Element ``` ## Update a Payment Element `element.update(options: object)` Updates the options the [Payment Element](https://docs.stripe.com/js/element/payment_element.md) was initialized with. Updates are merged into the existing configuration with a shallow merge. **NOTE**: Don't use `element.update()` to fetch updates from a [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) or [SetupIntent](https://docs.stripe.com/api/setup_intents.md). Use [elements.fetchUpdates()](https://docs.stripe.com/js/elements_object/fetch_updates.md) instead. - `options` Options for updating the Payment Element. - `defaultValues` Provide initial customer information that will be displayed in the Payment Element. The form will render with empty fields if not provided. - `billingDetails` Specify customer's billing details, which lets you pre-fill a customer’s name, email, phone number and address if required by payment method. Pre-filling as much information as possible streamlines the checkout process. - `name` - `email` - `phone` - `address` - `line1` - `line2` - `city` The name of a city, town, village, etc. - `state` The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines. - `country` Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2. - `postal_code` The postal code or ZIP code, also known as PIN code in India. - `paymentMethods` Specify customer's default information for different payment methods. Pre-filling as much information as possible streamlines the checkout process. - `ideal` - `bank` A pre-filled iDEAL bank value for the Payment Element. Can only be one of the banks listed in the [iDEAL guide](https://docs.stripe.com/payments/ideal/accept-a-payment?ui=element.md#bank-reference) (e.g., `abn_amro`). - `payto` - `usePayId` When `true`, the PayTo payment method will default to showing the PayID input instead of BSB/account number fields. Customers can still switch between PayID and BSB/account number using the toggle link. - `card` Specify default settings for card payments. - `network` Specifies a network preference for [Card Brand Choice](https://docs.stripe.com/card-brand-choice.md). The first network in the array that matches a network on the entered co-branded card will be selected by default in the Card Brand Choice dropdown. See the [supported networks](https://docs.stripe.com/api/payment_methods/create.md#create_payment_method-card-networks-preferred) for valid values. - `business` Provide information about your business that will be displayed in the Payment Element. This information will be retrieved from your Stripe account if not provided. - `name` The name of your business. Your business name will be used to render mandate text for some payment methods. - `paymentMethodOrder` By default, the Payment Element will use a dynamic ordering that optimizes payment method display for each user. You can override the default order in which payment methods are displayed in the Payment Element with a list of payment method types. If the associated PaymentIntent has payment method types not specified in `paymentMethodOrder`, they will be displayed after the payment methods you specify. If you specify payment method types not on the associated PaymentIntent, they will be ignored. - `fields` By default, the Payment Element will collect all necessary details to complete a payment. For some payment methods, this means that the Payment Element will collect details like name or email that you may have already collected from the user. If this is the case, you can prevent the Payment Element from collecting these data by using the `fields` option. If you disable the collection of a certain field with the `fields` option, you must pass that same data to [stripe.confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment.md) or the payment will be rejected. Learn more about how to [customize which billing details to collect](https://docs.stripe.com/payments/payment-element/control-billing-details-collection.md) and see [below](https://docs.stripe.com/js/elements_object/create_payment_element.md#payment_element_create-customized_fields) for details. - `billingDetails` Specify `never` to avoid collecting all [billing details](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details) in the Payment Element. If you would like to disable only certain billing details, pass an object specifying which fields you would like to disable collection for. The default setting for each field or object is `auto`. - `name` - `email` - `phone` - `address` Specify `if_required` to only collect the minimum billing address fields required to complete the payment. You can omit and hide optional address fields in the card form, such as country and postal code. Unlike the `never` option, you don't need to include fields omitted in the Payment Element when confirming the payment. This can reduce the amount of information required to complete the form. Disabling address collection can negatively impact authorization rates and network fees for users on a network cost plus pricing plan. - `line1` - `line2` - `city` The name of a city, town, village, etc. - `state` The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines. - `country` Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2. - `postalCode` The postal code or ZIP code, also known as PIN code in India. - `readOnly` Applies a read-only state to the Payment Element so that payment details can’t be changed. Default is false. Enabling the `readOnly` option doesn't change the Payment Element's visual appearance. If you want to adjust the way the Payment Element looks, use the [Appearance API](https://docs.stripe.com/elements/appearance-api.md). - `terms` Control how mandates or other legal agreements are displayed in the Payment Element. Use `never` to never display legal agreements. The default setting is `auto`, which causes legal agreements to only be shown when necessary. Consult your legal and compliance advisors before making any changes to the text of mandates or legal agreements. You can't use the `terms` option to violate obligations under your Stripe agreement, Stripe policies, applicable laws or scheme rules. - `applePay` - `auBecsDebit` - `bancontact` - `card` - `cashapp` - `googlePay` - `ideal` - `paypal` - `sepaDebit` - `sofort` - `usBankAccount` - `applePay` Specify Apple Pay specific options. These are passed through to the Apple Pay API. - `recurringPaymentRequest` Specify a request to set up a recurring payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `regularBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `trialBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `billingAgreement` - `deferredPaymentRequest` Specify a request to set up a deferred payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaydeferredpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `deferredBilling` - `amount` - `label` - `deferredPaymentDate` - `billingAgreement` - `freeCancellationDate` If set, you must also supply a freeCancellationDateTimeZone. - `freeCancellationDateTimeZone` If set, you must also supply a freeCancellationDate. These are [tz](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) timezones such as `America/Los_Angeles`, `Europe/Dublin`, and `Asia/Singapore`. - `automaticReloadPaymentRequest` Specify a request to set up an automatic reload payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayautomaticreloadpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `automaticReloadBilling` - `amount` - `label` - `automaticReloadPaymentThresholdAmount` - `billingAgreement` ### Example ```title Update a Payment Element ``` ## Fetch Server Updates `elements.fetchUpdates()` Used with the [Payment Element](https://docs.stripe.com/payments/payment-element.md). This method fetches updates from the associated [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) or [SetupIntent](https://docs.stripe.com/api/setup_intents.md) on an existing instance of `Elements`, and reflects these updates in the Payment Element. ### Example ```title Fetch Server Updates ``` ## Collapse a Payment Element `element.collapse()` This method collapses the Payment Element into a row of payment method tabs. ### Example ```title Collapse a Payment Element ``` ## The Express Checkout Element The Express Checkout Element is an embeddable component for accepting payments through one-click payment buttons. ## Create the Express Checkout Element `elements.create(type: 'expressCheckout', options?: object)` This method creates an instance of the Express Checkout Element. - `type` The type of Element being created, which is `expressCheckout` in this case. - `options` Options for creating the Express Checkout Element. - `allowedShippingCountries` By default, the Express Checkout Element allows all countries for shipping. You can specify which countries are allowed for shipping in the Express Checkout Element with a list of two-letter country codes. - `applePay` Specify Apple Pay specific options. These are passed through to the Apple Pay API. - `recurringPaymentRequest` Specify a request to set up a recurring payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `regularBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `trialBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `billingAgreement` - `deferredPaymentRequest` Specify a request to set up a deferred payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaydeferredpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `deferredBilling` - `amount` - `label` - `deferredPaymentDate` - `billingAgreement` - `freeCancellationDate` If set, you must also supply a freeCancellationDateTimeZone. - `freeCancellationDateTimeZone` If set, you must also supply a freeCancellationDate. These are [tz](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) timezones such as `America/Los_Angeles`, `Europe/Dublin`, and `Asia/Singapore`. - `automaticReloadPaymentRequest` Specify a request to set up an automatic reload payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayautomaticreloadpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `automaticReloadBilling` - `amount` - `label` - `automaticReloadPaymentThresholdAmount` - `billingAgreement` - `billingAddressRequired` Controls whether the Express Checkout Element collects the billing address. The default value depends on your integration: - If you pass `allowedShippingCountries`, `phoneNumberRequired`, `shippingAddressRequired`, `emailRequired`, `applePay`, `lineItems`, or `business` when creating the Express Checkout Element, `billingAddressRequired` defaults to false. - Otherwise, `billingAddressRequired` defaults to true. You can explicitly set `billingAddressRequired` to true or false to override the default behavior. We highly recommend that you collect the billing address because it can be used to perform address verifications and block fraudulent payments. - `business` Provide information about your business that's displayed in the Express Checkout Element. This information will be retrieved from your Stripe account if it's not provided. - `name` The name of your business. Your business name is used to signal to the customer who they're paying. Klarna always retrieves the business name from your Stripe account, even when this option is set. - `buttonHeight` By default, the height of the buttons are 44px. You can override this to specify a custom button height in the range of 40px-55px. - `buttonTheme` Specify the preferred button theme to use. By default, Elements determines the themes based on the specified [appearance option](https://docs.stripe.com/js/elements_object/create.md#stripe_elements-options-appearance). - `applePay` - `googlePay` - `paypal` - `klarna` - `buttonType` Specify the preferred button type to display. - `applePay` Default is `plain`. - `googlePay` Default is `buy`. - `paypal` Default is `paypal`. - `klarna` Default is `pay`. - `emailRequired` Collect the customer's email by setting this option to `true`. - `layout` Specify how the buttons are arranged in a grid-like layout in the Express Checkout Element. Elements determines the layout by using certain factors, such as available space, number of buttons, and the defined `layout` object. - `maxColumns` Defines the maximum number of columns the Express Checkout Element can use to render. Default is `0`, meaning unlimited. - `maxRows` Defines the maximum number of rows the Express Checkout Element can use to render. Default is `0`, meaning unlimited. - `overflow` Specify whether or not to always hide the overflow menu or allow Elements to determine when to show the overflow menu. Default is `auto`. You can't specify both `overflow: 'never'` and set `maxRows` to a number greater than 0. - `lineItems` An array of LineItem objects. These LineItems are shown as line items in the payment interface, if line items are supported. You can represent discounts as negative amount LineItems. - `name` The name of the line item surfaced to the customer in the payment interface. - `amount` The amount in the currency's subunit (for example, cents, yen, etc.). - `paymentMethods` By default, the Express Checkout Element displays all payment methods possible as a result of your Dashboard configuration. This is the `auto` behavior. If you don't want to show a given payment method as a payment option, set its property in `paymentMethods` to `never`. - `amazonPay` - `applePay` Apple Pay has additional configurations that determine when Stripe can show it. By default, Apple Pay shows when the customer is using a supported platform and when we determine it's advantageous for your conversion. This is the `auto` behavior. If you want to always show Apple Pay when the customer is using a supported platform, you can set its property in `paymentMethods` to `always`. This causes Apple Pay to be shown in supported browsers even when the customer isn't logged in to Apple Pay, resulting in a sign-in flow. Apple Pay on desktop Chromium browsers is only supported on MacOS when its property in `paymentMethods` is set to `always`. - `googlePay` Google Pay has additional configurations that determine when Stripe can show it. By default, Google Pay shows when the customer is using a supported platform and when we determine it's advantageous for your conversion. This is the `auto` behavior. If you want to always show Google Pay when the customer is using a supported platform, you can set its property in `paymentMethods` to `always`. This causes Google Pay to be shown in supported browsers even when the customer isn't logged in to Google Pay, resulting in a sign-in flow. - `link` - `paypal` - `klarna` - `paymentMethodOrder` By default, the Express Checkout Element uses a dynamic ordering that optimizes payment method display for each user. You can override the default order in which payment methods display in the Express Checkout Element with a list of payment method types. If there are payment methods that will show that are not specified in `paymentMethodOrder`, they display after the payment methods you specify. If you specify payment methods that will not show, they are ignored. - `phoneNumberRequired` Collect the customer's phone number by setting this option to `true`. PayPal doesn't provide a phone number, even when this option is set to `true`. Google Pay makes a best effort to return the phone number registered to the wallet, but doesn't guarantee it will be provided in all cases. - `shippingAddressRequired` Collect the customer's shipping address by setting this option to `true`. If `true`, you must also supply a valid `shippingRates` option in either the `create`, `click`, or `shippingaddresschange` events. - `shippingRates` An array of ShippingRate objects. The first shipping rate listed appears in the payment interface as the default option. - `id` Unique identifier for the object. - `amount` The amount to charge for shipping. - `displayName` The name of the shipping rate, displayed to the customer in the payment interface. - `deliveryEstimate` The estimated range for how long shipping takes, displayed to the customer in the payment interface. We recommended using the object format, but you can use a string instead. - `maximum` The upper bound of the estimated range. If empty, it represents no upper bound (for example, infinite). - `unit` A unit of time. - `value` Must be greater than 0. - `minimum` The lower bound of the estimated range. If empty, it represents no lower bound. - `unit` A unit of time. - `value` Must be greater than 0. ### Example ```title Create an Express Checkout Element ``` ## Get an Express Checkout Element `elements.getElement(type: 'expressCheckout')` This method retrieves a previously created Express Checkout Element. - `type` The type of Element being retrieved, which is `expressCheckout` in this case. ### Example ```title Get an Express Checkout Element ``` ## Update an Express Checkout Element `element.update(options: object)` Updates the options the [Express Checkout Element](https://docs.stripe.com/js/element/express_checkout_element.md) was initialized with. Updates merge into the existing configuration. - `options` Options for updating the Express Checkout Element. - `allowedShippingCountries` By default, the Express Checkout Element allows all countries for shipping. You can specify which countries are allowed for shipping in the Express Checkout Element with a list of two-letter country codes. - `billingAddressRequired` Controls whether the Express Checkout Element collects the billing address. The default value depends on your integration: - If you pass `allowedShippingCountries`, `phoneNumberRequired`, `shippingAddressRequired`, `emailRequired`, `applePay`, `lineItems`, or `business` when creating the Express Checkout Element, `billingAddressRequired` defaults to false. - Otherwise, `billingAddressRequired` defaults to true. You can explicitly set `billingAddressRequired` to true or false to override the default behavior. We highly recommend that you collect the billing address because it can be used to perform address verifications and block fraudulent payments. - `emailRequired` Collect the customer's email by setting this option to `true`. - `layout` Specify how the buttons are arranged in a grid-like layout in the Express Checkout Element. Elements determines the layout by using certain factors, such as available space, number of buttons, and the defined `layout` object. - `maxColumns` Defines the maximum number of columns the Express Checkout Element can use to render. Default is `0`, meaning unlimited. - `maxRows` Defines the maximum number of rows the Express Checkout Element can use to render. Default is `0`, meaning unlimited. - `overflow` Specify whether or not to always hide the overflow menu or allow Elements to determine when to show the overflow menu. Default is `auto`. You can't specify both `overflow: 'never'` and set `maxRows` to a number greater than 0. - `paymentMethodOrder` By default, the Express Checkout Element uses a dynamic ordering that optimizes payment method display for each user. You can override the default order in which payment methods display in the Express Checkout Element with a list of payment method types. If there are payment methods that will show that are not specified in `paymentMethodOrder`, they display after the payment methods you specify. If you specify payment methods that will not show, they are ignored. - `phoneNumberRequired` Collect the customer's phone number by setting this option to `true`. PayPal doesn't provide a phone number, even when this option is set to `true`. Google Pay makes a best effort to return the phone number registered to the wallet, but doesn't guarantee it will be provided in all cases. - `shippingAddressRequired` Collect the customer's shipping address by setting this option to `true`. If `true`, you must also supply a valid `shippingRates` option in either the `create`, `click`, or `shippingaddresschange` events. ### Example ```title Update an Express Checkout Element ``` ## Click event `expressCheckoutElement.on(event: 'click', handler: function)` The `click` event is triggered from an Express Checkout Element when the customer clicks a payment button. Use this event to configure the payment interface. - `event` The name of the event. In this case, `click`. - `handler` `handler(event) => void` is a **callback function** you provide that's called after the event is fired. After it's called, it passes an event object with the following properties: - `elementType` The type of element the event is fired from, which is `expressCheckout` in this case. - `expressPaymentType` The payment method the customer checks out with. - `resolve` A function `resolve(payload) => void` that's called to show the payment interface. You must call this function within 1 second if you handle the `click` event. - `allowedShippingCountries (deprecated)` _This parameter has been deprecated in favor of the `allowedShippingCountries` param on the [create](https://docs.stripe.com/js/elements_object/create_express_checkout_element.md#express_checkout_element_create-options-allowedShippingCountries) function._ By default, the Express Checkout Element allows all countries for shipping. You can specify which countries are allowed for shipping in the Express Checkout Element with a list of two-letter country codes. - `applePay` Specify Apple Pay specific options. These are passed through to the Apple Pay API. - `recurringPaymentRequest` Specify a request to set up a recurring payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `regularBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `trialBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `billingAgreement` - `deferredPaymentRequest` Specify a request to set up a deferred payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaydeferredpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `deferredBilling` - `amount` - `label` - `deferredPaymentDate` - `billingAgreement` - `freeCancellationDate` If set, you must also supply a freeCancellationDateTimeZone. - `freeCancellationDateTimeZone` If set, you must also supply a freeCancellationDate. These are [tz](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) timezones such as `America/Los_Angeles`, `Europe/Dublin`, and `Asia/Singapore`. - `automaticReloadPaymentRequest` Specify a request to set up an automatic reload payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayautomaticreloadpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `automaticReloadBilling` - `amount` - `label` - `automaticReloadPaymentThresholdAmount` - `billingAgreement` - `billingAddressRequired (deprecated)` _This parameter has been deprecated in favor of the `billingAddressRequired` param on the [create](https://docs.stripe.com/js/elements_object/create_express_checkout_element.md#express_checkout_element_create-options-billingAddressRequired) function._ By default, the Express Checkout Element collects the billing address. You can disable this by setting `billingAddressRequired` to `false`. We highly recommend that you collect the billing address because it can be used to perform address verifications and block fraudulent payments. - `business (deprecated)` _This parameter has been deprecated in favor of the `business` param on the [create](https://docs.stripe.com/js/elements_object/create_express_checkout_element.md#express_checkout_element_create-options-business) function._ Provide information about your business that's displayed in the Express Checkout Element. This information will be retrieved from your Stripe account if it's not provided. - `name` The name of your business. Your business name is used to signal to the customer who they're paying. Klarna always retrieves the business name from your Stripe account, even when this option is set. - `emailRequired (deprecated)` _This parameter has been deprecated in favor of the `emailRequired` param on the [create](https://docs.stripe.com/js/elements_object/create_express_checkout_element.md#express_checkout_element_create-options-emailRequired) function._ Collect the customer's email by setting this option to `true`. - `lineItems` An array of LineItem objects. These LineItems are shown as line items in the payment interface, if line items are supported. You can represent discounts as negative amount LineItems. - `name` The name of the line item surfaced to the customer in the payment interface. - `amount` The amount in the currency's subunit (for example, cents, yen, etc.). - `phoneNumberRequired (deprecated)` _This parameter has been deprecated in favor of the `phoneNumberRequired` param on the [create](https://docs.stripe.com/js/elements_object/create_express_checkout_element.md#express_checkout_element_create-options-phoneNumberRequired) function._ Collect the customer's phone number by setting this option to `true`. PayPal doesn't provide a phone number, even when this option is set to `true`. - `shippingAddressRequired (deprecated)` _This parameter has been deprecated in favor of the `shippingAddressRequired` param on the [create](https://docs.stripe.com/js/elements_object/create_express_checkout_element.md#express_checkout_element_create-options-shippingAddressRequired) function._ Collect the customer's shipping address by setting this option to `true`. If `true`, you must also supply a valid `shippingRates` option in either the `create`, `click`, or `shippingaddresschange` events. - `shippingRates` An array of ShippingRate objects. The first shipping rate listed appears in the payment interface as the default option. - `id` Unique identifier for the object. - `amount` The amount to charge for shipping. - `displayName` The name of the shipping rate, displayed to the customer in the payment interface. - `deliveryEstimate` The estimated range for how long shipping takes, displayed to the customer in the payment interface. We recommended using the object format, but you can use a string instead. - `maximum` The upper bound of the estimated range. If empty, it represents no upper bound (for example, infinite). - `unit` A unit of time. - `value` Must be greater than 0. - `minimum` The lower bound of the estimated range. If empty, it represents no lower bound. - `unit` A unit of time. - `value` Must be greater than 0. - `reject` A function `reject() => void` that's called to cancel the payment interface. You must call this function within 1 second if you handle the `click` event. ### Example ```title Handle an express checkout element click event ``` ## Confirm event `expressCheckoutElement.on(event: string, handler: function)` The `confirm` event is triggered from an Express Checkout Element when the customer finalizes their payment. Use this event to trigger payment confirmation. - `event` The name of the event. In this case, `confirm`. - `handler` A callback function `handler(event) => void` you provide that's called after the event is fired. When called, it passes an event object with the following properties: - `elementType` The type of element the event fires from, which is `expressCheckout` in this case. - `expressPaymentType` The payment method the customer checks out with. - `paymentFailed` A function `paymentFailed(payload) => void` that's called if you're unable to process the customer's payment. - `reason` Default is `'fail'`. The payment interface might surface the reason to provide a hint to the customer on why their payment failed. - `message` A short, concise, localized error message to display on the payment sheet. If none is provided, the payment sheet will display a generic error message for the given reason. **Note:** Custom error messages may not be supported or may be truncated by certain wallets. - `billingDetails` Object containing information about the customer's billing details. - `name` The name of the customer. - `email` The email address of the customer. - `phone` The phone number of the customer. - `address` The billing address of the customer. **Note:** When using PayPal, the full billing address of the customer is not always exposed. Typically, only the country code is passed back from PayPal. To access the full billing address, you would need to request it from PayPal directly. - `line1` - `line2` - `city` - `state` - `postal_code` - `country` - `shippingAddress` Object containing information about the customer's shipping address. - `name` The name of the recipient. - `address` The shipping address of the customer. - `line1` - `line2` - `city` - `state` - `postal_code` - `country` - `shippingRate` Object containing information about the selected shipping rate. - `id` Unique identifier for the object. - `amount` The amount to charge for shipping. - `displayName` The name of the shipping rate, displayed to the customer in the payment interface. - `deliveryEstimate` The estimated range for how long shipping takes, displayed to the customer in the payment interface. We recommended using the object format, but you can use a string instead. - `maximum` The upper bound of the estimated range. If empty, it represents no upper bound (for example, infinite). - `unit` A unit of time. - `value` Must be greater than 0. - `minimum` The lower bound of the estimated range. If empty, it represents no lower bound. - `unit` A unit of time. - `value` Must be greater than 0. ### Example ```title Handle 'confirm' event ``` ## Cancel event `expressCheckoutElement.on(event: string, handler: function)` The `cancel` event is triggered from an Express Checkout Element when the payment interface is dismissed. Note that in some browsers, the payment interface might be dismissed by the customer even after they authorize the payment. This means that you might receive a `cancel` event after receiving a `confirm` event. If you're using the `cancel` event as a hook for canceling the customer's order, make sure you also refund the payment that you just created. - `event` The name of the event. In this case, `cancel`. - `handler` A callback function that you provide that's called after the event is fired. ### Example ```title Handle 'cancel' event ``` ## Shippingaddresschange event `expressCheckoutElement.on(event: string, handler: function)` The `shippingaddresschange` event is triggered from an Express Checkout Element whenever the customer selects a new address in the payment interface. This event is not available for Elements with Checkout Sessions (EwCS integrations). When using an Express Checkout Element with a Checkout Session, shipping address changes are managed through the Checkout Session itself. You can update the session on your server after the customer completes their payment rather than responding to this event during the payment flow. - `event` The name of the event. In this case, `shippingaddresschange`. - `handler` A callback function `handler(event) => void` you provide that's called after the event is fired. After it's called, it passes an event object with the following properties: - `elementType` The type of element the event is fired from, which is `expressCheckout` in this case. - `resolve` A function `resolve(payload) => void` that's called if the recipient's shipping address is valid. - `applePay` Specify Apple Pay specific options. These are passed through to the Apple Pay API. - `recurringPaymentRequest` Specify a request to set up a recurring payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `regularBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `trialBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `automaticReloadPaymentRequest` Specify a request to set up an automatic reload payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayautomaticreloadpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `automaticReloadBilling` - `amount` - `label` - `automaticReloadPaymentThresholdAmount` - `lineItems` An array of LineItem objects. These LineItems are shown as line items in the payment interface, if line items are supported. - `name` The name of the line item surfaced to the customer in the payment interface. - `amount` The amount in the currency's subunit (for example, cents, yen, etc.). - `shippingRates` An array of ShippingRate objects. The first shipping rate listed appears in the payment interface as the default option. - `id` Unique identifier for the object. - `amount` The amount to charge for shipping. - `displayName` The name of the shipping rate, displayed to the customer in the payment interface. - `deliveryEstimate` The estimated range for how long shipping takes, displayed to the customer in the payment interface. We recommended using the object format, but you can use a string instead. - `maximum` The upper bound of the estimated range. If empty, it represents no upper bound (for example, infinite). - `unit` A unit of time. - `value` Must be greater than 0. - `minimum` The lower bound of the estimated range. If empty, it represents no lower bound. - `unit` A unit of time. - `value` Must be greater than 0. - `reject` A function `reject() => void` that's called if the recipient's shipping address is invalid. - `name` The name of the recipient. - `address` The shipping address of the recipient. To maintain privacy, browsers might anonymize the shipping address by removing sensitive information that isn't necessary to calculate shipping costs. Depending on the country, some fields can be missing or partially redacted. For example, the shipping address in the US can only contain a city, state, and ZIP code. The full shipping address appears in the [confirm event](https://docs.stripe.com/js/elements_object/express_checkout_element_confirm_event.md#express_checkout_element_on_confirm-handler-shippingAddress) object after the purchase is confirmed in the browser’s payment interface. - `city` - `state` - `postal_code` - `country` ### Example ```title Handle 'shippingaddresschange' event ``` ## Shippingratechange event `expressCheckoutElement.on(event: string, handler: function)` The `shippingratechange` event is triggered from an Express Checkout Element whenever the customer selects a new shipping rate in the payment interface. This event is not available for Elements with Checkout Sessions (EwCS integrations). When using an Express Checkout Element with a Checkout Session, shipping rate changes are managed through the Checkout Session itself. You can update the session on your server after the customer completes their payment rather than responding to this event during the payment flow. - `event` The name of the event. In this case, `shippingratechange`. - `handler` A callback function `handler(event) => void` you provide that's called after the event is fired. After it's called, it passes an event object with the following properties: - `elementType` The type of element the event is fired from, which is `expressCheckout` in this case. - `resolve` A function `resolve(payload) => void` that's called if the customer's shipping rate is valid. - `applePay` Specify Apple Pay specific options. These are passed through to the Apple Pay API. - `recurringPaymentRequest` Specify a request to set up a recurring payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrecurringpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `regularBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `trialBilling` - `amount` - `label` - `recurringPaymentStartDate` - `recurringPaymentEndDate` - `recurringPaymentIntervalUnit` - `recurringPaymentIntervalCount` - `automaticReloadPaymentRequest` Specify a request to set up an automatic reload payment. See the [Apple Pay documentation](https://developer.apple.com/documentation/apple_pay_on_the_web/applepayautomaticreloadpaymentrequest) for more details. - `paymentDescription` - `managementURL` - `automaticReloadBilling` - `amount` - `label` - `automaticReloadPaymentThresholdAmount` - `lineItems` An array of LineItem objects. These LineItems are shown as line items in the payment interface, if line items are supported. - `name` The name of the line item surfaced to the customer in the payment interface. - `amount` The amount in the currency's subunit (for example, cents, yen, etc.). - `shippingRates` An array of ShippingRate objects. The first shipping rate listed appears in the payment interface as the default option. - `id` Unique identifier for the object. - `amount` The amount to charge for shipping. - `displayName` The name of the shipping rate, displayed to the customer in the payment interface. - `deliveryEstimate` The estimated range for how long shipping takes, displayed to the customer in the payment interface. We recommended using the object format, but you can use a string instead. - `maximum` The upper bound of the estimated range. If empty, it represents no upper bound (for example, infinite). - `unit` A unit of time. - `value` Must be greater than 0. - `minimum` The lower bound of the estimated range. If empty, it represents no lower bound. - `unit` A unit of time. - `value` Must be greater than 0. - `reject` A function `reject() => void` that's called if the customer's shipping rate is invalid. - `shippingRate` The shipping rate selected by the customer. - `id` Unique identifier for the object. - `amount` The amount to charge for shipping. - `displayName` The name of the shipping rate, displayed to the customer in the payment interface. - `deliveryEstimate` The estimated range for how long shipping takes, displayed to the customer in the payment interface. We recommended using the object format, but you can use a string instead. - `maximum` The upper bound of the estimated range. If empty, it represents no upper bound (for example, infinite). - `unit` A unit of time. - `value` Must be greater than 0. - `minimum` The lower bound of the estimated range. If empty, it represents no lower bound. - `unit` A unit of time. - `value` Must be greater than 0. ### Example ```title Handle 'shippingratechange' event ``` ## The Link Authentication Element The [Link Authentication Element](https://docs.stripe.com/payments/link/accept-a-payment.md) is an embeddable component for collecting email addresses and allow users to log into Link on your checkout page. ## Create the Link Authentication Element `elements.create(type: 'linkAuthentication', options?: object)` This method creates an instance of the Link Authentication Element. - `type` The type of Element being created, which is `linkAuthentication` in this case. - `options` Options for creating the Link Authentication Element. - `defaultValues` Provide the initial contact information that will be displayed in the Link Authentication Element. The form will render with empty fields if not provided. - `email` ### Example ```title Create a Link Authentication Element ``` ## Get a Link Authentication Element `elements.getElement(type: 'linkAuthentication')` This method retrieves a previously created Link Authentication Element. - `type` The type of Element being retrieved, which is `linkAuthentication` in this case. ### Example ```title Get a Link Authentication Element ``` ## The Address Element The Address Element is an embeddable component for collecting local and international billing and shipping addresses. ## Create the Address Element `elements.create(type: 'address', options: object)` This method creates an instance of the Address Element. **NOTE**: If you are creating multiple instances of the Address Element, configuration of the checkbox to sync shipping and billing addresses exists in the creation of the [Elements](https://docs.stripe.com/js/elements_object/create.md#stripe_elements-options-syncAddressCheckbox) instance. - `type` The type of Element being created, which is `address` in this case. You can create multiple Address Elements, one of each mode, in a single Elements instance. - `options` Options for creating the Address Element. - `mode` Specify which mode you would like to use Address Element for. When `shipping` mode is used with the Payment Element and Link Authentication Element, it will automatically pass shipping information when confirming Payment Intent or Setup Intent. When `billing` mode is used with the Payment Element, it will automatically pass the billing information when confirming Payment Intent or Setup Intent. - `autocomplete` By default, the Address Element will have autocomplete enabled with Stripe provided Google Maps API key for certain countries if any of the following condition is met: * If Payment Element is mounted in the same elements group as Address Element in a single page application. * If the Address Element is used in an active Link session. [Contact Legal before editing or deleting the Google Maps autocomplete callout]: # By using autocomplete, you agree to comply with the [Google Maps Platform Acceptable Use Policy](https://cloud.google.com/maps-platform/terms/aup). If you violate this policy, we might disable autocomplete, or take any other action as necessary. You can customize the autocomplete setting with this option. - `mode` Specify `disabled` to disable autocomplete in the Address Element. Specify `google_maps_api` to enable [Google Maps API](https://developers.google.com/maps/documentation/javascript/places) with your own key. It will only be used when Stripe provided Google Maps API key is not available. The default setting is `automatic`, where we’ll support autocomplete when possible. - `apiKey` Specify your own [Google Maps API key](https://developers.google.com/maps/documentation/javascript/places#add-places-api-to-the-api-keys-api-restrictions-list) with it. **Only needs to be passed in when `autocomplete.mode` is set to `google_maps_api`.** - `allowedCountries` By default, the Address Element will display all countries for selection. You can specify which countries are displayed in the Address Element with a list of two-letter country codes. If only one country is specified, the country field will not display. - `blockPoBox` By default, PO boxes are considered a valid address type. You can override this to invalidate PO Boxes. - `contacts` An array of objects that can be displayed as saved addresses in the Address Element. The first contact will be automatically selected. If using a [CustomerSession](https://docs.stripe.com/api/customer_sessions.md), Address Element will ignore contacts and render saved billing addresses instead. - `name` The name of the contact. This might be a person, or a business name. - `address` The address of the contact. - `line1` - `line2` - `city` The name of a city, town, village, etc. - `state` The most coarse subdivision of a country. Depending on the country, this might correspond to a state, a province, an oblast, a prefecture, or something else along these lines. - `postal_code` The postal code or ZIP code, also known as PIN code in India. - `country` Two-letter country code, capitalized. Valid two-letter country codes are specified by ISO3166 alpha-2. - `phone` The phone number of the contact. The [fields.phone](https://docs.stripe.com/js/elements_object/create_address_element.md#address_element_create-options-fields-phone) option must be set to `always` if this property is specified. - `defaultValues` Provide the initial information that will be displayed in the Address Element. The form will render with empty fields if not provided. - `name` Provide the initial full name or organization name. - `firstName` Provide the initial first name. The [display.name](https://docs.stripe.com/js/elements_object/create_address_element.md#address_element_create-options-display-name) option must be set to `split` if this property is specified. - `lastName` Provide the initial last name. The [display.name](https://docs.stripe.com/js/elements_object/create_address_element.md#address_element_create-options-display-name) option must be set to `split` if this property is specified. - `phone` Provide the initial phone number value. The [fields.phone](https://docs.stripe.com/js/elements_object/create_address_element.md#address_element_create-options-fields-phone) option must be set to `always` if this property is specified. - `address` Provide the initial address details. - `line1` - `line2` - `city` - `state` - `postal_code` - `country` - `fields` By default, the Address Element will collect all the necessary information needed for an address. In some cases, it might be necessary to collect other types of information. You can specify other types of fields to render in the form with this option. - `phone` Specify `always` to enable phone number collection in the Address Element. Only collect phone numbers if you need them for the transaction. Default is `auto`. - `validation` By default, the Address Element will enforce preset validation for each field. You can customize the settings by using this option. - `phone` - `required` Specify `always` to make phone number a required field. The [fields.phone](https://docs.stripe.com/js/elements_object/create_address_element.md#address_element_create-options-fields-phone) option must be set to `always` if this property is specified. Default is `auto`. - `display` You can customize how certain fields are displayed. - `name` By default, the Address Element will display a full name field. Specify 'split' to display a first name field and a last name field. Specify 'organization' to display an organization field. ### Example ```title Create an Address Element ``` ## Get an Address Element `elements.getElement(type: 'address', options?: object)` This method retrieves a previously created Address Element. - `type` The type of Element being retrieved, which is `address` in this case. - `options` Options for retrieving the Address Element. - `mode` Required when using multiple Address Elements. Specify which mode of the Address Element you would like to retrieve. ### Example ```title Get an Address Element ``` ## Update an Address Element `element.update(options: object)` Updates the options the [Address Element](https://docs.stripe.com/js/element/address_element.md) was initialized with. Updates are merged into the existing configuration. - `options` Options for updating the Address Element. - `fields` By default, the Address Element will collect all the necessary information needed for an address. In some cases, it might be necessary to collect other types of information. You can specify other types of fields to render in the form with this option. - `phone` Specify `always` to enable phone number collection in the Address Element. Only collect phone numbers if you need them for the transaction. Default is `auto`. - `validation` By default, the Address Element will enforce preset validation for each field. You can customize the settings by using this option. - `phone` - `required` Specify `always` to make phone number a required field. The [fields.phone](https://docs.stripe.com/js/elements_object/create_address_element.md#address_element_create-options-fields-phone) option must be set to `always` if this property is specified. Default is `auto`. ### Example ```title Update an Address Element ``` ## Get value from an Address Element `element.getValue(options?: object)` Validates and retrieves form values from an Address Element. If there are any input validation errors, the errors will display by their respective fields. - `options` An optional options object to control the format of the returned values. - `format` Controls the format of the `state` field in the returned address value. * `latin`: Return the state in Latin characters (for example, "Tokyo"). * `localized`: Return the state in the locale's native script (for example, "東京"). If unspecified in Stripe.js Clover and below, format is determined by a heuristic based on the customer's browser language. If unspecified in Stripe.js Dahlia and above, defaults to `latin`. ### Example ```title Get value from an Address Element ``` ## The Tax ID Element The [Tax ID Element](https://docs.stripe.com/elements/tax-id-element.md) is an embeddable component for collecting customer tax ID information for tax reporting and compliance purposes. ## Create a Tax ID Element `elements.create(type: 'taxId', options?: object)` This method creates an instance of the Tax ID Element. > This feature requires the `elements_tax_id_1` beta. To use it, pass `betas: ['elements_tax_id_1']` when initializing Stripe.js. - `type` The type of Element being created, which is `taxId` in this case. - `options` Tax ID Element initialization options. - `visibility` By default, the Tax ID Element displays when the user is in a country that supports tax ID collection. Specify `always` to display the element regardless of the user's country. Specify `never` to hide the element completely. - `fields` By default, the Tax ID Element collects all tax ID information. If it's not necessary for you to collect all fields, you can disable Tax ID Element collection of certain fields with the `fields` option. - `businessName` Specify `always` to collect the business name. Specify `never` to not collect the business name. Default is `auto`. - `validation` By default, the Tax ID Element will enforce preset validation for each field. You can customize the settings by using this option. - `businessName` - `required` Specify `always` to make business name a required field. Specify `never` to make business name an optional field. Default is `auto`. - `taxId` - `required` Specify `always` to make tax ID a required field. Specify `never` to make tax ID an optional field. Default is `auto`. - `verification` Configure real-time tax ID verification. Requires the `elements_tax_id_verification_1` beta. To use it, pass `betas: ['elements_tax_id_1', 'elements_tax_id_verification_1']` when initializing Stripe.js - `taxId` - `mode` Specify `if_supported` to enable real-time tax ID verification for supported tax ID types. Specify `never` to disable verification. Default is `never`. ### Example ```title Create a Tax ID Element ``` ## Retrieve a Tax ID Element `elements.getElement(type: 'taxId')` This method retrieves a previously created Tax ID Element. - `type` The type of Element being retrieved, which is `taxId` in this case. ### Example ```title Retrieve a Tax ID Element ``` ## Get value from a Tax ID Element `element.getValue()` Validates and retrieves form values from a Tax ID Element. If there are any input validation errors, the errors are displayed by their associated fields. ### Example ```title Get value from a Tax ID Element ``` ## Issuing Elements [Issuing Elements](https://docs.stripe.com/issuing/elements.md) allows you to display the sensitive data of your Issuing cards in a PCI-compliant manner. ## Create an Element `elements.create(type: string, options: object)` This method creates an instance of an individual Issuing Element. It takes the `type` of Element to create as well as an `options` object. ## Other Elements Stripe also offers a [set of Elements for individual payment methods](https://docs.stripe.com/payments/elements.md) that you can use in your payment flows. ## Create an Element `elements.create(type: string, options?: object)` This method creates an instance of an individual `Element`. It takes the `type` of `Element` to create as well as an `options` object. ## Get an Element `elements.getElement(type: string)` This method looks up a previously created [Element](https://docs.stripe.com/js/element.md) by its type. - `type` The type of [Element](https://docs.stripe.com/js/elements_object/create_element.md) to lookup. ### Example ```title Get an Element ``` ## Update an Element `element.update(options: object)` Updates the options the [Element](https://docs.stripe.com/js/element.md) was initialized with. Updates are merged into the existing configuration. If you collect certain information in a different part of your interface (e.g., ZIP or postal code), use `element.update` with the appropriate information. The styles of an `Element` can be dynamically changed using `element.update`. This method can be used to simulate CSS media queries that automatically adjust the size of elements when viewed on different devices. ## Style the Element container Style the container you mount an [Element](https://docs.stripe.com/js/element.md) to as if it were an `` on your page. For example, to control `padding` and `border` on an `Element`, set these properties on the container. This is usually done by re-using the classes that you have applied to your DOM `` elements. After the `Element` is mounted, the `.StripeElement` class is added to the container. Additionally, the following classes are automatically added to the container when the `Element` is complete, empty, focused, invalid, or autofilled by the browser: * `.StripeElement--complete` * `.StripeElement--empty` * `.StripeElement--focus` * `.StripeElement--invalid` * `.StripeElement--webkit-autofill` (Chrome and Safari only) These class names can be customized using the `classes` [option](https://docs.stripe.com/js/elements_object/create_element.md#elements_create-options-classes) when you [create an Element](#elements_create). ### Example ```title The Element container ``` ## Input validation Stripe elements validate customer input as it is typed. To help your customers catch mistakes, listen to `change` events on an `Element` and display any errors. ### Example ```title Display validation errors from an Element ``` ## Postal code formatting The `card` element automatically determines your customer’s billing address country based on their card number. Using this information, the postal code field validation reflects whether that country uses numeric or alphanumeric-formatted postal codes, or if the country uses postal codes at all. For instance, if a U.S. card is entered, the postal code field only accepts a five-digit numeric value. If it’s a UK card, an alphanumeric value can be provided instead. Many of our test cards have a U.S. billing address country. When using these to test your payment form, you must also use a five-digit U.S. ZIP code (e.g., 12345). To test elements with other postal code formats, use our [international test card numbers](https://docs.stripe.com/testing.md#international-cards). ## Mount an Element `element.mount(domElement: string | DOM element)` The `element.mount` method attaches your [Element](https://docs.stripe.com/js/element.md) to the DOM. `element.mount` accepts either a CSS Selector (e.g., `'#payment-element'`) or a DOM element. You need to create a container DOM element to mount an `Element`. Add an empty placeholder `div` to your payment form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect payment information. - `domElement` The CSS selector or DOM element where your [Element](https://docs.stripe.com/js/element.md) will be mounted. ### Example ```title Mount an Element ``` ## Element methods Below are a number of methods that are in common between all [Element](https://docs.stripe.com/js/element.md) UIs. Wait until the [ready event](https://docs.stripe.com/js/element/events/on_ready.md) is triggered before calling these methods. ## Blur an Element `element.blur()` Blurs the [Element](https://docs.stripe.com/js/element.md). ### Example ```title Blur an Element ``` ## Clear an Element's values `element.clear()` Clears the value(s) of the [Element](https://docs.stripe.com/js/element.md). ### Example ```title Clear an Element ``` ## Destroy an Element `element.destroy()` Removes the [Element](https://docs.stripe.com/js/element.md) from the DOM and destroys it. A destroyed `Element` can not be re-activated or re-mounted to the DOM. ### Example ```title Destroy an Element ``` ## Focus an Element `element.focus()` Focuses the [Element](https://docs.stripe.com/js/element.md). > This method will currently not work on iOS 13+ due to a system limitation. ### Example ```title Focus an Element ``` ## Unmount an Element `element.unmount()` Unmounts the [Element](https://docs.stripe.com/js/element.md) from the DOM. Call [`element.mount`](https://docs.stripe.com/js/element/mount.md) to re-attach it to the DOM. ### Example ```title Unmount an Element ``` ## Element events Communicate with your [Element](https://docs.stripe.com/js/element.md) by listening to an event. An Element might emit any of the events below. All events have a payload object that has an `elementType` property with the type of the `Element` that emitted the event. ## Change event `element.on(event: 'change', handler: function)` The change event is triggered when any value in the change event payload changes. The event payload always contains certain keys, in addition to some `Element`-specific keys. > Consult with your legal counsel regarding your requirements and obligations about how you collect, use, and store customers' personal data ## Ready event `element.on(event: 'ready', handler: function)` Triggered when the `Element` is fully rendered and methods on the instance, like `element.focus()` and `element.update()`, can be called. - `event` The name of the event. In this case, `ready`. - `handler` `handler(event) => void` is a **callback function** that you provide that will be called when the event is fired. After it's called, it passes an event object with the following properties: - `elementType` The type of element the event is fired from. - `availablePaymentMethods` This field is **only** present on the `expressCheckout` Element. Describes which buttons render in the Element. Returns undefined if no buttons will render. - `link` - `applePay` - `googlePay` - `paypal` - `amazonPay` - `klarna` ### Example ```title Handle an Element ready event ``` ## Focus event `element.on(event: 'focus', handler: function)` Triggered when the `Element` gains focus. - `event` The name of the event. In this case, `focus`. - `handler` `handler(event) => void` is a **callback function** that you provide that will be called when the event is fired. ### Example ```title Handle an Element focus event ``` ## Blur event `element.on(event: 'blur', handler: function)` Triggered when the `Element` loses focus. - `event` The name of the event. In this case, `blur`. - `handler` `handler(event) => void` is a **callback function** that you provide that will be called when the event is fired. ### Example ```title Handle an Element blur event ``` ## Escape event `element.on(event: 'escape', handler: function)` Triggered when the escape key is pressed within an Element. - `event` The name of the event. In this case, `escape`. - `handler` `handler(event) => void` is a **callback function** that you provide that will be called when the event is fired. ### Example ```title Handle an Element escape event ``` ## Click event `element.on(event: 'click', handler: function)` ## LoadError event `element.on(event: 'loaderror', handler: function)` Triggered when the `Element` fails to load. **This event is only emitted from the `payment`, `linkAuthentication`, `address`, `expressCheckout`, `currencySelector`, `taxId`, `card`, and `cardNumber` Elements.** - `event` The name of the event. In this case, `loaderror`. - `handler` `handler(event) => void` is a **callback function** that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties: - `elementType` The type of element that emitted this event. - `error` An `error` object that describes the failure. ### Example ```title Handle an Element loaderror event ``` ## LoadStart event `element.on(event: 'loaderstart', handler: function)` Triggered when the [loader](https://docs.stripe.com/js/elements_object/create.md#stripe_elements-options-loader) UI is mounted to the DOM and ready to be displayed. **This event is only emitted from the `payment`, `linkAuthentication`, and `address` Elements.** - `event` The name of the event. In this case, `loaderstart`. - `handler` `handler(event) => void` is a **callback function** that you provide that will be called when the event is fired. When called it will be passed an event object with the following properties: - `elementType` The type of element that emitted this event. ### Example ```title Handle an Element loaderstart event ``` ## NetworksChange event `element.on(event: 'networkschange', handler: function)` Triggered when there is a change to the available networks the provided card can run on. If the list of available networks is still loading, an event with `networks: null` and `loading: true` is triggered. When the list of available networks loads, Stripe triggers an additional event that contains the list of these networks and shows `loading: false`. Refer to our [card brand choice guide](https://docs.stripe.com/card-brand-choice.md#identifying-the-available-card-networks) for further details.