Migrate to the Payment Intents API
Payment Element integration features
You can integrate with the Payment Element to manage subscriptions, tax, discounts, shipping, and currency conversion. To learn more, see the Build a checkout page guide.
Learn how to migrate your existing cards and Charges API integration.
Migrating your payment flow can be daunting. It’s 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:
- Update your API version and your client library.
- 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.
- Migrate your integration that saves cards on Customer objects.
- Test with regulatory test cards to ensure your upgraded integration handles authentication correctly.
Update your API version and your client library
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_has been renamed tosource requires_payment_ method requires_has been renamed tosource_ action requires_action
In addition, if you use one of our SDKs, upgrade to the latest version of the library 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
Create a PaymentIntent on your server and make it accessible on the client side.
Not possible before
curl https://api.stripe.com/v1/payment_intents \ -u: \ -d "amount"=1099 \ -d "currency"="usd"sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
Step 2: Collect payment details on the client side
Use the confirmCardPayment function, which collects the payment information and submits it directly to Stripe.
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.
curl https://api.stripe.com/v1/charges \ -u: \ -d "source"="{{FROM_PREVIOUS_STEP}}" \ -d "amount"=1099 \ -d "currency"="usd"sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
Completed in previous step
Step 4: Fulfill the customer’s order
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 fulfillment after a customer’s payment is successful, implement support for webhooks and monitor the payment_ event.
If charge succeeds, fulfill.
Subscribe to the payment_ 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_ if you primarily intend to charge users when they’re outside of your application, or on_ 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_. Providing the setup_ 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.
Not possible before
curl https://api.stripe.com/v1/payment_intents \ -u: \ -d "setup_future_usage"="off_session" \ -d "amount"=1099 \ -d "currency"="usd"sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
Step 2: Collect payment details on the client side
Use the confirmCardPayment function, which collects the payment information and submits it directly to Stripe.
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.) to the customer.
curl https://api.stripe.com/v1/customers/{{CUSTOMER_ID}}/sources \ -u: \ -d "source"="{{TOKEN_OR_SOURCE}}"sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
curl https://api.stripe.com/v1/payment_method/{{PAYMENT_METHOD_ID}}/attach \ -u: \ -d "customer"="{{CUSTOMER_ID}}"sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
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.
curl https://api.stripe.com/v1/charges \ -u: \ -d "source"="{{FROM_PREVIOUS_STEP}}" \ -d "customer"="{{CUSTOMER_ID}}" \ -d "amount"=1099 \ -d "currency"="usd"sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
Completed in previous step
Step 4: Fulfill the customer’s order
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 fulfillment after a customer’s payment is successful, implement support for webhooks and monitor the payment_ event.
If charge succeeds, fulfill.
Subscribe to the payment_ 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 won’t be duplicated in the sources property of the customer object.
customer.sources
curl https://api.stripe.com/v1/payment_methods?customer={{CUSTOMER_ID}}&type=card \ -u:sk_test_Hrs6SAopgFPF0bZXSN3f6ELN
Test the integration
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 a sandbox with any expiration 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-time 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_ failure code after successful authentication. | |
| Supported | This test card supports authentication through 3D Secure 2, but doesn’t require it. Payments using this card don’t require additional authentication in a sandbox unless your sandbox Radar rules request authentication. |
Use these cards in your application or the payments demo to see the different behavior.