Enregistrer le moyen de paiement d'un client lors d'un paiement
Découvrez comment enregistrer le mode de paiement du client lorsque vous confirmez un PaymentIntent.
Use the Checkout Sessions API to save payment details during a purchase. This is useful for situations such as:
- Charging a customer for an e-commerce order and storing the payment details for future purchases.
- Initiating the first payment in a series of recurring payments.
- Charging a deposit and storing the payment details to charge the full amount later.
Compliance
You’re responsible for your compliance with all applicable laws, regulations, and network rules when saving a customer’s payment details. These requirements generally apply if you want to save your customer’s payment method for future use, such as displaying a customer’s payment method to them in the checkout flow for a future purchase or charging them when they’re not actively using your website or app. Add terms to your website or app that state how you plan to save payment method details and allow customers to opt in.
When you save a payment method, you can only use it for the specific usage you have included in your terms. To charge a payment method when a customer is offline and save it as an option for future purchases, make sure that you explicitly collect consent from the customer for this specific use. For example, include a “Save my payment method for future use” checkbox to collect consent.
To charge a customer when they’re offline, make sure your terms include the following:
- The customer’s agreement to your initiating a payment or a series of payments on their behalf for specified transactions.
- The anticipated timing and frequency of payments (for example, if the charges are for scheduled installments, subscription payments, or unscheduled top-ups).
- How you determine the payment amount.
- Your cancellation policy, if the payment method is for a subscription service.
Make sure you keep a record of your customer’s written agreement to these terms.
Remarque
When using Elements with the Checkout Sessions API, only cards are supported for saved payment methods. You can’t save other payment methods, such as bank accounts.
Configurer StripeCôté serveur
Tout d’abord, inscrivez-vous pour créer un compte Stripe.
Utilisez nos bibliothèques officielles pour accéder à l’API Stripe à partir de votre application :
Créer un clientCôté serveur
Pour configurer une carte en vue de paiements futurs, vous devez l’associer à un client. Lorsque votre client ouvre un compte chez vous, créez un objet Customer, qui permet de réutiliser des moyens de paiement et d’assurer le suivi de plusieurs paiements.
Comparer les références Customers v1 et Accounts v2
Si votre plateforme Connect utilise des comptes configurés par le client, utilisez notre guide pour remplacer le Client et des références d’événements dans votre code avec les références équivalentes de l’API Accounts v2.
Lorsque la création réussit, l’objet Customer est renvoyé. Vous pouvez consulter l’objet pour identifier l’id du client et stocker cette valeur dans votre base de données pour la récupérer ultérieurement.
Vous pouvez trouver ces clients dans la page Clients du Dashboard.
Enable saved payment methods
Avertissement
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.
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 create a new one by setting customer_creation to always on the Checkout Session.
After you create the Checkout Session, use the client secret returned in the response to build your checkout page.
Remarque
In the latest version of Stripe.js, specifying enableSave to auto is optional because that’s the default value when saved payment methods are enabled on the Checkout Session.
Reuse a previously saved payment method
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.
Remarque
In the latest version of Stripe.js, enableRedisplay defaults to auto when saved payment methods are enabled on the Checkout Session.
The Payment Element automatically redisplays previously saved payment methods for your customer to use during checkout when saved payment methods are enabled on the Checkout Session.
FacultatifBuild a saved payment method UI
Collect consent
Avertissement
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 method details. The following example shows how to obtain consent using a checkbox.
When you call confirm, you can indicate to Stripe that your customer has provided consent 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.
Render saved payment methods
Use the savedPaymentMethods array on the front end to render the customer’s available payment methods.
Remarque
The savedPaymentMethods array includes only the payment methods that have allow_redisplay set to always. Follow the steps for collecting consent from your customer and make sure to properly set the allow_ parameter.
Confirm with a saved payment method
When your customer selects a saved payment method and is ready to complete checkout, call confirm and pass in the paymentMethod ID.