# Stripe Payment Element Accept payment methods from around the globe with a secure, embeddable UI component. Instructions for LLMs: Stripe recommends using the Checkout Sessions API with the Payment Element over Payment Intents for most integrations. Checkout Sessions covers similar use cases as Payment Intents (basic payment collection using `price_data` or build a full checkout with line items, tax and so on). Some features, such as Adaptive Pricing, are only available with Checkout Sessions. Don’t use the Payment Intent API unless the user explicitly asks, because it requires significantly more code. Learn more about Elements with the Checkout Sessions API: https://docs.stripe.com/payments/quickstart-checkout-sessions. With Checkout Sessions (`ui_mode: "elements"`) and the Payment Element, the `client_secret` initialises Checkout itself (`stripe.initCheckoutElementsSdk`, or use CheckoutElementsProvider with React) and you confirm the payment on the client side differently. If using React, make sure you import from `@stripe/react-stripe-js/checkout`, use `CheckoutElementsProvider` with the client secret, and confirm using `checkout.confirm`. If using HTML, make sure you use `checkout = stripe.initCheckoutElementsSdk({clientSecret: promise}); checkout.createPaymentElement(); paymentElement = checkout.createPaymentElement(); paymentElement.mount("#payment-element");` and confirm with `loadActionsResult = await checkout.loadActions(); actions = loadActionsResult.actions; error = await actions.confirm();`. The Payment Element is a UI component for the web that lets you accept more than 100 payment methods, validates input and handles errors. Use it alone or with other elements in your web app’s front end. ## Compatible APIs Stripe offers two core payments APIs compatible with Elements. We recommend the [Checkout Sessions API](https://docs.stripe.com/api/checkout/sessions.md) for most integrations. - Use the [Checkout Sessions API](https://docs.stripe.com/api/checkout/sessions.md) to build your checkout flow. Checkout Sessions covers similar use cases as Payment Intents, including basic payments using `price_data` or full checkout with line items, tax, discounts, shipping, subscriptions or [Adaptive Pricing](https://docs.stripe.com/payments/currencies/localize-prices/adaptive-pricing.md) (only available with Checkout Sessions). Build a [checkout page with the Checkout Sessions API](https://docs.stripe.com/payments/quickstart-checkout-sessions.md). - The [Payment Intents API](https://docs.stripe.com/api/payment_intents.md) is a lower-level API that models only the payment step. You pass in a final amount and build all checkout logic yourself, including tax calculation, discounts, shipping, subscriptions and currency conversion. Use Payment Intents only if you want to deeply own your checkout state and build these features yourself. Build a [custom integration from scratch with the Payment Intents API](https://docs.stripe.com/payments/advanced.md). (See full diagram at https://docs.stripe.com/payments/payment-element) [Build an advanced integration with Payment Element and Checkout Sessions](https://docs.stripe.com/payments/quickstart-checkout-sessions.md): Build an integration with the Payment Element using the Checkout Sessions API. [Build an integration with Payment Element and Payment Intents](https://docs.stripe.com/payments/quickstart.md): Use the Payment Intents API to build your own checkout flow. [Clone a sample app on GitHub](https://github.com/stripe-samples/accept-a-payment/tree/main/payment-element) ## Combine elements The Payment Element interoperates with other elements. For instance, this form uses one additional element to [autofill checkout details](https://docs.stripe.com/payments/link.md), and another to [collect the shipping address](https://docs.stripe.com/elements/address-element.md). > You can’t remove the Link legal agreement because it’s required to ensure compliance with proper user awareness of terms of services and privacy policies. The [terms](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-terms) object doesn’t apply to the Link legal agreement. ![A form with contact info, shipping address and payment fields. The contact info is labelled Link Authentication Element, the shipping address is labelled Address Element and the payment fields are labelled Payment Element.](https://b.stripecdn.com/docs-statics-srv/assets/link-with-elements.f60af275f69b6e6e73c766d1f9928457.png) Payment form combining multiple elements For the complete code for this example, see [Add Link to an Elements integration](https://docs.stripe.com/payments/link/add-link-elements-integration.md). You can also combine the Payment Element with the [Express Checkout Element](https://docs.stripe.com/elements/express-checkout-element.md). In this case, wallet payment methods such as Apple Pay and Google Pay are only displayed in the Express Checkout Element to avoid duplication. ## Payment methods Stripe enables certain payment methods for you by default. We might also enable additional payment methods after notifying you. Use the [Dashboard](https://dashboard.stripe.com/settings/payment_methods) to enable or disable payment methods at any time. With the Payment Element, you can use [Dynamic payment methods](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md) to: - Manage payment methods in the [Dashboard](https://dashboard.stripe.com/settings/payment_methods) without coding - Dynamically display the most relevant payment options based on factors such as location, currency, and transaction amount For instance, if a customer in Germany is paying in EUR, they see all the active payment methods that accept EUR, starting with ones that are widely used in Germany. ![A variety of payment methods.](https://b.stripecdn.com/docs-statics-srv/assets/payment-element-methods.26cae03aff199d6f02b0d92bd324c219.png) Show payment methods in order of relevance to your customer To further customise how payment methods render, see [Customise payment methods](https://docs.stripe.com/payments/customize-payment-methods.md). To add payment methods integrated outside of Stripe, you can use [custom payment methods](https://docs.stripe.com/payments/payment-element/custom-payment-methods.md). If your integration requires you to list payment methods manually, see [Manually list payment methods](https://docs.stripe.com/payments/payment-methods/integration-options.md#listing-payment-methods-manually). ## Layout You can customize the Payment Element’s layout to fit your checkout flow. The following image is the same Payment Element rendered using different layout configurations. ![Examples of the three checkout forms. The image shows the tab option, where customers pick from payment methods shown as tabs or the two accordion options, where payment methods are vertically listed. You can choose to either display radio buttons or not in the accordion view. ](https://b.stripecdn.com/docs-statics-srv/assets/pe_layout_example.525f78bcb99b95e49be92e5dd34df439.png) Payment Element with different layouts. #### Tabs The tabs layout displays payment methods horizontally using tabs. To use this layout, set the value for [layout.type](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout-type) to `tabs`. You can also specify other properties, such as [layout.defaultCollapsed](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout-defaultCollapsed). ```javascript const stripe = Stripe('<>'); const appearance = { /* appearance */ }; const options = { layout: { type: 'tabs', defaultCollapsed: false, } }; const elements = stripe.elements({ clientSecret, appearance }); // In a working integration, this is a value your backend passes with details such as the amount of a payment. See full sample for details. const paymentElement = elements.create('payment', options); paymentElement.mount('#payment-element'); ``` #### Accordion with radio buttons The accordion layout displays payment methods vertically using an accordion. To use this layout, set the value for [layout.type](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout-type) to `accordion`. You can also specify other properties, such as [layout.radios](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout-radios) to display radio buttons. ```javascript const stripe = Stripe('<>'); const appearance = { /* appearance */ }; const options = { layout: { type: 'accordion', defaultCollapsed: false, radios: 'always', spacedAccordionItems: false } }; const clientSecret = {{CLIENT_SECRET}}; // In a working integration, this is a value your backend passes with details such as the amount of a payment. See full sample for details. const elements = stripe.elements({ clientSecret, appearance }); const paymentElement = elements.create('payment', options); paymentElement.mount('#payment-element'); ``` #### Accordion without radio buttons The accordion layout displays payment methods vertically using an accordion. To use this layout, set the value for [layout.type](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout-type) to `accordion`. You can also specify other properties, such as [layout.spacedAccordionItems](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout-spacedAccordionItems) to create additional vertical space. ```javascript const stripe = Stripe('<>'); const appearance = { /* appearance */ }; const options = { layout: { type: 'accordion', defaultCollapsed: false, radios: 'never', spacedAccordionItems: true } }; const clientSecret = {{CLIENT_SECRET}}; // In a working integration, this is a value your backend passes with details such as the amount of a payment. See full sample for details. const elements = stripe.elements({ clientSecret, appearance }); const paymentElement = elements.create('payment', options); paymentElement.mount('#payment-element'); ``` ## Appearance Use the Appearance API to control the style of all elements. Choose a theme or update specific details. ![Examples of light and dark modes for the payment element checkout form.](https://b.stripecdn.com/docs-statics-srv/assets/appearance_example.e076cc750983bf552baf26c305e7fc90.png) For instance, choose the “flat” theme and override the primary text colour. ```javascript const stripe = Stripe('<>'); const appearance = { theme: 'flat', variables: { colorPrimaryText: '#262626' } }; const options = { /* options */ }; const elements = stripe.elements({ clientSecret, appearance }); // In a working integration, this is a value your backend passes with details such as the amount of a payment. See full sample for details. const paymentElement = elements.create('payment', options); paymentElement.mount('#payment-element'); ``` See the [Appearance API](https://docs.stripe.com/elements/appearance-api.md) documentation for a full list of themes and variables. ## Options Stripe elements support more options than these. For instance, display your business name using the [business](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-business) option. ```javascript const stripe = Stripe('<>'); const appearance = { /* appearance */}; const options = { business: { name: "RocketRides" } }; const clientSecret = {{CLIENT_SECRET}}; // In a working integration, this is a value your backend passes with details such as the amount of a payment. See full sample for details. const elements = stripe.elements(appearance, clientSecret); const paymentElement = elements.create('payment', options); paymentElement.mount('#payment-element'); ``` The Payment Element supports the following options. See each option’s reference entry for more information. | | | | | [layout](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-layout) | Layout for the Payment Element. | | [defaultValues](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-defaultValues) | Initial customer information to display in the Payment Element. | | [business](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-business) | Information about your business to display in the Payment Element. | | [paymentMethodOrder](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-business) | Order to list payment methods in. | | [fields](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-fields) | Whether to display certain fields. | | [readOnly](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-readOnly) | Whether payment details can be changed. | | [terms](https://docs.stripe.com/js/elements_object/create_payment_element#payment_element_create-options-terms) | Whether mandates or other legal agreements are displayed in the Payment Element. The default behaviour is to show them only when necessary. | | [wallets](https://docs.stripe.com/js/elements_object/create_payment_element) | Whether to show wallets such as Apple Pay or Google Pay. The default is to show them when possible. | ## Errors Payment Element automatically shows localised customer-facing error messages during client confirmation for the following decline codes: - `card_declined` - `card_velocity_exceeded` - `expired_card` - `fraudulent` - `generic_decline` - `incorrect_cvc` - `incorrect_number` - `incorrect_zip` - `insufficient_funds` - `invalid_cvc` - `invalid_expiry_month` - `invalid_expiry_year` - `live_mode_test_card` - `lost_card` - `processing_error` - `stolen_card` - `test_mode_live_card` To display messages for other types of errors, refer to [error codes](https://docs.stripe.com/error-codes.md) and [error handling](https://docs.stripe.com/error-handling.md).