Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer tools
Overview
About Stripe payments
Upgrade your integration
Payments analytics
Online payments
OverviewFind your use caseManaged Payments
Use Payment Links
Build a checkout page
    Overview
    Quickstarts
    Customise look and feel
    Collect additional information
    Collect taxes
    Dynamically update checkout
    Manage your product catalogue
    Subscriptions
    Manage payment methods
    Let customers pay in their local currency
    Add discounts, upsells, and optional items
    Set up future payments
    Save payment details during payment
    Manually approve payments on your server
    After the payment
    Elements with Checkout Sessions API beta changelog
    Migrate from legacy Checkout
    Migrate Checkout to use Prices
Build an advanced integration
Build an in-app integration
Payment Methods
Add payment methods
Manage payment methods
Faster checkout with Link
Payment interfaces
Payment Links
Checkout
Web Elements
In-app Elements
Payment scenarios
Custom payment flows
Flexible acquiring
Orchestration
In-person payments
Terminal
Other Stripe products
Financial Connections
Crypto
Climate
HomePaymentsBuild a checkout page

Set up future payments

Learn how to save payment details in a Checkout session and charge your customers later.

Copy page

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.

Use setup mode
Server-side

Pass mode=setup when creating the Checkout Session.

Command Line
cURL
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d mode=setup \ -d ui_mode=custom \ -d currency=usd

Then render your checkout page as usual.

Retrieve the payment method
Server-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_intent ID, retrieve the SetupIntent object. The returned object contains a payment_method ID that you can attach to a customer in the next step.

Attach the payment method to a Customer
Server-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.

Command Line
cURL
curl https://api.stripe.com/v1/payment_methods/
{{PAYMENT_METHOD_ID}}
/attach
\ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=
{{CUSTOMER_ID}}

Charge the payment method later
Server-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.
Command Line
cURL
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d amount=1099 \ -d currency=usd \ -d customer=
{{CUSTOMER_ID}}
\ -d payment_method=
{{PAYMENT_METHOD_ID}}
\ -d off_session=true \ -d confirm=true

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.

Command Line
cURL
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer=
{{CUSTOMER_ID}}
\ -d "line_items[0][price_data][currency]"=usd \ -d "line_items[0][price_data][product_data][name]"=T-shirt \ -d "line_items[0][price_data][unit_amount]"=1099 \ -d "line_items[0][quantity]"=1 \ -d mode=payment \ -d ui_mode=custom \ --data-urlencode return_url="https://example.com/return"
Was this page helpful?
YesNo
Need help? Contact Support.
Join our early access programme.
Check out our changelog.
Questions? Contact Sales.
LLM? Read llms.txt.
Powered by Markdoc