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. Read the Build a checkout page guide to learn more.
Learn how to migrate your existing cards and Charges API integration.
Migrating your payment flow can be daunting. It is safe to incrementally adopt the Payment Intents API and use it in parallel with the Charges API. To this end, you can split up the migration into the following steps:
If applicable, migrate code that reads from Charge properties so that you have a consistent read path between charges created by the Charges API and charges created by the Payment Intents API. This ensures a read-side integration that works for both your old and new payments integrations.
Migrate your existing Charges API integration on Web, iOS, and Android to use the Payment Intents API.
While the Payment Intents API works on all API versions, we recommend that you upgrade to the latest API version. If you decide to use an API version older than 2019-02-11, note the following two changes as you go through the code examples:
requires_source has been renamed to requires_payment_method
requires_source_action has been renamed to requires_action
In addition, if you use one of our SDKs, upgrade to the latest version of the library in order to use the Payment Intents API.
Migrate your one-time payment flows
An integration built with Stripe.js & Elements consists of the following steps:
Register your intent to collect payment on the server side
Collect payment details on the client side
Initiate creation of the payment
Fulfill the customer’s order on the server side
Step 1: Register intent to collect payment on the server side
Step 2: Collect payment details on the client side
Use the confirmCardPayment function, which collects the payment information and submits it directly to Stripe.
Before
After
stripe.createToken(
cardElement
).then(function(token){// Send token to server});
stripe.confirmCardPayment(INTENT_SECRET_FROM_STEP_1,{
payment_method:{card: cardElement}}).then(function(result){if(result.error){// Display error.message in your UI.}else{// The payment has succeeded// Display a success message}});
Step 3: Initiate creation of the payment
In your existing integration, the final step is using tokenized payment information to create a charge on your server. This is no longer necessary, as the confirmCardPayment function—called in the previous step—initiates creation of the charge.
With automatic confirmation, the charge is created for you asynchronously based on customer action on the client side, so you must monitor webhooks to determine when the payment completes successfully. To perform steps like order fulfilment after a customer’s payment is successful, implement support for webhooks and monitor the payment_intent.succeeded event.
Before
After
If charge succeeds, fulfill.
Subscribe to the payment_intent.succeeded webhook and fulfill in the webhook handler.
Now that you have migrated, use the test cards in the following section to verify your upgraded integration handles 3D Secure authentication.
Migrate your integration that saves cards on Customer objects
A Payment Intents API integration that collects card information in the checkout flow consists of the following steps:
Register your intent to collect payment on the server side
Collect payment details on the client side
Initiate creation of the payment
Fulfill the customer’s order on the server side
Step 1: Register intent to collect payment on the server side
Create a PaymentIntent on your server. Set setup_future_usage to off_session if you primarily intend to charge users when they are outside your application, or on_session if you plan to charge them in the application. If you plan to use the card for both on and off session payments use off_session. Providing the setup_future_usage parameter along with a Customer ID will save the resulting PaymentMethod to that Customer after the PaymentIntent has been confirmed and any required actions from the customer are complete. Next, make the PaymentIntent accessible on the client side.
Step 2: Collect payment details on the client side
Use the confirmCardPayment function, which collects the payment information and submits it directly to Stripe.
Before
After
stripe.createToken(// or stripe.createSource
cardElement
).then(function(token){// Send token to server});
stripe.confirmCardPayment('{{INTENT_SECRET_FROM_STEP_1}}',{
payment_method:{card: cardElement},}).then(function(result){if(result.error){// Display error.message in your UI.}else{// The payment has succeeded// Display a success message}});
Finally, attach the payment method (paymentIntent.payment_method) to the customer.
In your existing integration, the final step is using tokenized payment information to create a charge on your server. This is no longer necessary, as the confirmCardPayment function—called in the previous step—initiates creation of the charge.
With automatic confirmation, the charge is created for you asynchronously based on customer action on the client side, so you must monitor webhooks to determine when the payment completes successfully. To perform steps like order fulfilment after a customer’s payment is successful, implement support for webhooks and monitor the payment_intent.succeeded event.
Before
After
If charge succeeds, fulfill.
Subscribe to the payment_intent.succeeded webhook and fulfill in the webhook handler.
Now that you have migrated, use the test cards in the following section to verify your upgraded integration handles 3D Secure authentication.
Access saved payment methods
To display the customer’s previously saved Cards, Sources, and PaymentMethods, list the payment methods instead of reading the sources property of the customer object. This is required because new PaymentMethods added to a customer will not be duplicated in the sources property of the customer object.
It’s important to thoroughly test your integration to make sure you’re correctly handling cards that require additional authentication and cards that don’t. Use these card numbers in test mode with any expiry date in the future and any three digit CVC code to validate your integration when authentication is required and when it’s not required.
Number
Authentication
Description
Required on setup or first transaction
This test card requires authentication for one-off payments. However, if you set up this card using the Setup Intents API and use the saved card for subsequent payments, no further authentication is needed.
Required
This test card requires authentication on all transactions.
Required
This test card requires authentication, but payments will be declined with an insufficient_funds failure code after successful authentication.
Supported
This test card supports authentication via 3D Secure 2, but does not require it. Payments using this card do not require additional authentication in test mode unless your test mode Radar rules request authentication.
Use these cards in your application or the payments demo to see the different behavior.