Save a customer's payment method without making a payment
Learn how to save a payment method and charge it later.
The Checkout Sessions API in setup
mode lets you save a customer’s payment details without an initial payment. This is helpful if you want to onboard customers now, set them up for payments, and charge them using the Payment Intents API in the future—when they’re offline.
Use this integration to set up recurring payments or to create one-time payments with a final amount determined later, often after the customer receives your service.
Card-present transactions
Card-present transactions, such as collecting card details through Stripe Terminal, use a different process for saving the payment method.
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.
Note
If you need to use manual server-side confirmation or your integration requires presenting payment methods separately, see our alternative guide.
Set up StripeServer-side
First, create a Stripe account or sign in.
Use our official libraries to access the Stripe API from your application:
Create a CustomerServer-side
To set up a payment method for future payments, you must attach it to a Customer. Create a Customer
object when your customer creates an account with your business. Customer
objects allow for reusing payment methods and tracking across multiple payments.
Use setup modeServer-side
Create a Checkout Session with mode=setup.
Attach the payment method to a CustomerServer-side
If you didn’t create the Checkout Session with an existing customer, use the ID of the PaymentMethod to attach the payment method to a customer.
Otherwise, the payment method automatically attaches to the customer you provided when creating the Checkout Session.
Retrieve the payment methodServer-side
After a customer successfully completes their Checkout Session, handle the checkout.session.completed webhook. Retrieve the Session object in the webhook, and then do the following:
- Get the value of the setup_intent key, which is the SetupIntent ID created during the Checkout Session.
- Use the SetupIntent ID to retrieve the SetupIntent object. The returned object contains a payment_method ID that you can attach to a customer in the next step.
Learn more about setting up webhooks.
Charge the payment method laterServer-side
After you attach the PaymentMethod to a customer, you can make an off-session payment using a PaymentIntent:
- Set customer to the customer ID and payment_method to payment method ID.
- Set off_session to
true
to indicate that the customer isn’t in your checkout flow during a payment attempt and can’t fulfill an authentication request made by a partner, such as a card issuer, bank, or other payment institution. If, during your checkout flow, a partner requests authentication, Stripe requests exemptions using customer information from a previous on-session transaction. If the conditions for exemption aren’t met, the PaymentIntent might result in an error. - Set the value of the PaymentIntent’s confirm property to
true
, which causes confirmation to occur immediately when you create the PaymentIntent.
If a payment attempt fails, the request also fails with a 402 HTTP status code, and the PaymentIntent status is requires_payment_method. Notify your customer to return to your application (for example, by sending an email or in-app notification) and direct your customer to a new Checkout Session to select another payment method.