Set up future payments
Learn how to save payment details in a Checkout session and charge your customers later.
You can save a customer’s payment details for use later without collecting an initial payment using Checkout Session’s setup mode. This is helpful if you want to onboard customers now, set them up for payments, and charge them in the future – when they’re offline.
Retrieve the payment methodServer-side
After a customer successfully completes their Checkout Session, handle the checkout.session.completed webhook, which contains the Session object. Learn more about setting up webhooks.
After you have retrieved the Session object:
- Get the value of the setup_intent key, which is the ID for the SetupIntent created during the Checkout Session.
- Using the
setup_
ID, retrieve the SetupIntent object. The returned object contains a payment_method ID that you can attach to a customer in the next step.intent
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 PaymentMethod to a Customer.
Otherwise, the PaymentMethod will automatically be attached to the Customer you provided when creating the Checkout Session.
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 ID of the Customer and payment_method to the ID of the PaymentMethod.
- Set off_session to
true
to indicate that the customer isn’t in your checkout flow during a payment attempt and can’t fulfil 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 throw an error. - Set the value of the PaymentIntent’s confirm property to
true
, which causes confirmation to occur immediately when you create the PaymentIntent.
When a payment attempt fails, the request also fails with a 402 HTTP status code and the status of the PaymentIntent 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.