Save payment details during payment
Learn how to accept a payment and save your customer's payment details for future purchases.
Notiz
Support for saved payment methods using Elements and the Checkout Sessions API only includes cards. It doesn’t support other saved payment methods, such as bank accounts.
Enable saved payment methods
To allow a customer to save their payment method for future use, specify the saved_payment_method_options.payment_method_save parameter when creating the Checkout Session.
Saving a payment method requires a Customer. Pass an existing customer, or, to create a new customer, set the Checkout Session’s customer_creation to always
.
After you create the Checkout Session, use the client secret returned in the response to build your checkout page.
Collect consent
Vorsicht
Global privacy laws are complicated and nuanced. Before implementing the ability to store customer payment method details, work with your legal team to make sure that it complies with your privacy and compliance framework.
In most cases, you must collect a customer’s consent before you save their payment methods. The following example shows how to obtain consent using a checkbox.
Indicate to Stripe whether your customer has provided consent when you call confirm by passing the savePaymentMethod
parameter. When you save a customer’s payment details, you’re responsible for complying with all applicable laws, regulations, and network rules.
Reuse a previously saved payment method
You can redisplay previously saved payment methods for your customer to use during checkout.
Identify your customer
Each saved payment method is linked to a Customer object. Before creating the Checkout Session, authenticate your customer, and pass the corresponding Customer ID to the Checkout Session.
Render saved payment methods
Use the savedPaymentMethods array on the front end to render the customer’s available payment methods.
Notiz
The savedPaymentMethods
array includes only the payment methods that have allow_redisplay set to always
. Follow the steps to collecting consent from your customer, which ensures that allow_
is properly set.
Confirm with a saved payment method
When your customer has selected a saved payment method and is ready to complete checkout, call confirm, passing in the paymentMethod ID.