调至内容部分
创建账户
或
登录
Stripe 文档徽标
/
询问人工智能
创建账户
登录
开始
付款
销售收入
平台和交易市场
资金管理
开发人员资源
概览
关于 Stripe 支付
升级您的集成
支付分析
线上付款
概览查找您的用例Managed Payments
使用 Payment Link
构建结账页面
构建高级集成
构建应用内集成
支付方式
添加支付方式
管理支付方式
用 Link 更快结账
支付接口
Payment Links
结账
Web Elements
    概览
    Payment Element
      Payment Element 最佳实践
      Card Element 对比
      通过 Payment Intent 迁移到了 Payment Element
      通过 Checkout Session 迁移到了 Payment Element
      迁移到 Confirmation Token
    Express Checkout Element
    Address Element
    货币选择器组件
    Link Authentication Element
    Payment Method Messaging Element
    税号 Element
In-app Payments
支付场景
处理多种货币
自定义支付流程
灵活收单
编排
线下支付
Terminal
超越支付功能
成立公司
加密货币
Financial Connections
Climate
了解欺诈
Radar 欺诈保护
管理争议
验证身份
首页付款Web ElementsPayment Element

Migrate to the Payment Element with the Payment Intents API

Accept many payment methods with a single Element.

注意

If your integration still uses the Charges API with tokens, follow the Migrating to the Payment Intents API guide first.

Interested in using Stripe Billing, Tax, discounts, shipping, or currency conversion?

We’re developing a Payment Element integration that manages subscriptions, tax, discounts, shipping, and currency conversion. To learn more, see Build a checkout page.

Previously, each payment method (cards, iDEAL, and so on) required a separate Element. By migrating to the Payment Element, you can accept many payment methods with a single Element.

PaymentIntents and SetupIntents each have their own set of migration guidelines. See the appropriate guide for your integration path, including example code.

If your existing integration uses the Setup Intents API for future payments, follow the steps below to use the Payment Element.

Enable payment methods

注意

This integration path doesn’t support BLIK or pre-authorized debits that use the Automated Clearing Settlement System (ACSS).

View your payment methods settings and enable the payment methods you want to support. You need at least one payment method enabled to create a SetupIntent.

By default, Stripe enables cards and other prevalent payment methods that can help you reach more customers, but we recommend turning on additional payment methods that are relevant for your business and customers. See Payment method support for product and payment method support, and our pricing page for fees.

Update Elements instance
Client-side

Next, update your client-side code to pass the mode and currency when you create the Elements instance. For use with a SetupIntent, set the mode to 'setup' and the currency to what you’ll charge your customer in the future.

升级前
升级后
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); const elements = stripe.elements();
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); const options = { mode: 'setup', currency: 'usd', }; const elements = stripe.elements(options);

可选Additional Elements options
Client-side

The Elements object accepts additional options that influence payment collection. Based on the options provided, the Payment Element displays available payment methods from those you’ve enabled. Learn more about payment method support.

PropertyTypeDescriptionRequired
mode
  • payment
  • setup
  • subscription
Indicates whether the Payment Element is used with a PaymentIntent, SetupIntent, or Subscription.Yes
currencystringThe currency of the amount to charge the customer.Yes
amountnumberThe amount to charge the customer, shown in Apple Pay, Google Pay, or BNPL UIs.For payment and subscription mode
setupFutureUsage
  • off_session
  • on_session
Indicates that you intend to make future payments with the payment details collected by the Payment Element. No
captureMethod
  • automatic
  • automatic_async
  • manual
Controls when to capture the funds from the customer’s account.No
onBehalfOfstringConnect only. The Stripe account ID, which is the business of record. See use cases to determine if this option is relevant for your integration.No
paymentMethodTypesstring[]A list of payment method types to render. You can omit this attribute to manage your payment methods in the Stripe Dashboard.No
paymentMethodConfigurationstringThe payment method configuration to use when managing your payment methods in the Stripe Dashboard. If not specified, your default configuration is used.No
paymentMethodCreationmanualAllows PaymentMethods to be created from the Elements instance using stripe.createPaymentMethod.No
paymentMethodOptions{us_bank_account: {verification_method: string}}Verification options for the us_bank_account payment method. Accepts the same verification methods as Payment Intents.No
paymentMethodOptions{card: {installments: {enabled: boolean}}}Allows manually enabling the card installment plan selection UI if applicable when you aren’t managing your payment methods in the Stripe Dashboard. You must set mode='payment' and explicitly specify paymentMethodTypes. Otherwise an error is raised. Incompatible with paymentMethodCreation='manual'.No

Add the Payment Element
Client-side

If you’re using React Stripe.js, update to the latest package to use the Payment Element.

You can now replace the Card Element and individual payment methods Elements with the Payment Element. The Payment Element automatically adjusts to collect input fields based on the payment method and country (for example, full billing address collection for SEPA Direct Debit) so you don’t have to maintain customized input fields anymore.

The following example replaces CardElement with PaymentElement:

checkout.html
JavaScript
React
No results
<form id="payment-form"> <div id="card-element"> </div> <div id="payment-element"> <!-- Mount the Payment Element here --> </div> <button id="submit">Submit</button> </form>
checkout.js
JavaScript
React
No results
const cardElement = elements.create("card"); cardElement.mount("#card-element"); const paymentElement = elements.create("payment"); paymentElement.mount("#payment-element");

If your payment flow already always collects details like the customer’s name or email address, you can prevent the Payment Element from collecting this information by passing the fields option when creating the Payment Element. If you disable the collection of a certain field, you must pass that same data back with stripe.confirmSetup.

Update your SetupIntent creation call
Server-side

Because the Payment Element allows you to accept multiple payment methods, we recommend using automatic_payment_methods. When you enable it, Stripe evaluates the currency, payment method restrictions, and other parameters to determine the list of payment methods available for your customers. We prioritize payment methods that increase conversion and are most relevant to the currency and location of the customer.

Add the automatic_payment_methods attribute to the endpoint on your server that creates the SetupIntent.

Any of the additional elements options passed when creating the Elements group in the earlier step should also be passed when creating the SetupIntent.

Command Line
curl
Ruby
Python
PHP
Node.js
Stripe CLI
No results
curl https://api.stripe.com/v1/setup_intents \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:
\ -H "Stripe-Version: 2025-08-27.basil" \ -d "customer"="{{CUSTOMER_ID}}" \ -d "automatic_payment_methods[enabled]"=true

注意

You can’t save some payment methods for future payments. For more information, see Payment method integration options.

Update the submit handler
Client-side

Instead of using individual confirm methods like stripe.confirmCardSetup or stripe.confirmP24Setup, use stripe.confirmSetup to collect payment information and submit it to Stripe.

To confirm the SetupIntent, make the following updates to your submit handler:

  • Call await elements.submit() to trigger form validation and collect any data required for wallets.
  • Optional: Move SetupIntent creation to the submit handler. This way you only create the SetupIntent when the user is ready to submit their payment method details.
  • Pass the elements instance you used to create the Payment Element and the clientSecret from the SetupIntent as parameters to stripe.confirmSetup.

When called, stripe.confirmSetup attempts to complete any required actions, such as authenticating your customers by displaying a 3DS dialog or redirecting them to a bank authorization page. When confirmation is complete, users are directed to the return_url you configured, which normally corresponds to a page on your website that provides the status of the SetupIntent.

If you want to keep the same flow for saving card payment details and only redirect for redirect-based payment methods, set redirect to if_required.

The following code examples replaces stripe.confirmCardSetup with stripe.confirmSetup:

升级前
升级后
// Create the SetupIntent and obtain clientSecret const res = await fetch("/create-intent", { method: "POST", headers: {"Content-Type": "application/json"}, }); const {client_secret: clientSecret} = await res.json(); const handleSubmit = async (event) => { event.preventDefault(); if (!stripe) { // Stripe.js hasn't yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } setLoading(true); const {error} = await stripe.confirmCardSetup(clientSecret, { payment_method: { card: elements.getElement(CardElement) } }); if (error) { handleError(error); } };
const handleSubmit = async (event) => { event.preventDefault(); if (!stripe) { // Stripe.js hasn't yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } setLoading(true); // Trigger form validation and wallet collection const {error: submitError} = await elements.submit(); if (submitError) { handleError(submitError); return; } // Create the SetupIntent and obtain clientSecret const res = await fetch("/create-intent", { method: "POST", headers: {"Content-Type": "application/json"}, }); const {client_secret: clientSecret} = await res.json(); // Use the clientSecret and Elements instance to confirm the setup const {error} = await stripe.confirmSetup({ elements, clientSecret, confirmParams: { return_url: 'https://example.com/order/123/complete', }, // Uncomment below if you only want redirect for redirect-based payments // redirect: "if_required", }); if (error) { handleError(error); } };

Test the integration

Use test payment details and the test redirect page to verify your integration. Click the tabs below to view details for each payment method.

Payment methodScenarioHow to test
Credit cardThe card setup succeeds and doesn’t require authentication.Fill out the credit card form using the credit card number 4242 4242 4242 4242 with any expiration, CVC, and postal code.
Credit cardThe card requires authentication for the initial setup, then succeeds for subsequent payments.Fill out the credit card form using the credit card number 4000 0025 0000 3155 with any expiration, CVC, and postal code.
Credit cardThe card requires authentication for the initial setup and also requires authentication for subsequent payments.Fill out the credit card form using the credit card number 4000 0027 6000 3184 with any expiration, CVC, and postal code.
Credit cardThe card is declined during setup.Fill out the credit card form using the credit card number 4000 0000 0000 9995 with any expiration, CVC, and postal code.

Test charging a saved SEPA Debit PaymentMethod

Confirming the SetupIntent using iDEAL, Bancontact, or Sofort, generates a SEPA Direct Debit PaymentMethod. SEPA Direct Debit is a delayed notification payment method that transitions to an intermediate processing state before transitioning several days later to a succeeded or requires_payment_method state.

Set payment_method.billing_details.email to one of the following values to test the PaymentIntent status transitions. You can include your own custom text at the beginning of the email address followed by an underscore. For example, test_1_generatedSepaDebitIntentsFail@example.com results in a SEPA Direct Debit PaymentMethod that always fails when used with a PaymentIntent.

Email AddressDescription
generatedSepaDebitIntentsSucceed@example.comThe PaymentIntent status transitions from processing to succeeded.
generatedSepaDebitIntentsSucceedDelayed@example.comThe PaymentIntent status transitions from processing to succeeded after at least three minutes.
generatedSepaDebitIntentsFail@example.comThe PaymentIntent status transitions from processing to requires_payment_method.
generatedSepaDebitIntentsFailDelayed@example.comThe PaymentIntent status transitions from processing to requires_payment_method after at least three minutes.
generatedSepaDebitIntentsSucceedDisputed@example.comThe PaymentIntent status transitions from processing to succeeded, but a dispute is created immediately.
此页面的内容有帮助吗?
是否
  • 需要帮助?联系支持。
  • 加入我们的早期使用计划。
  • 查看我们的更改日志。
  • 有问题?联系销售。
  • LLM? Read llms.txt.
  • Powered by Markdoc