What is a Checkout Session?
A Checkout Session represents your customer’s payment session. It controls what the customer sees on the payment page: products, amount, currency, and available options.Identifier format:
cs_ followed by 24 alphanumeric characters.Example: cs_abc123def456ghi789jkl012Session Modes
payment
One-time paymentFor one-time purchases of products or services.
subscription
SubscriptionTo create a recurring subscription with automatic billing.
setup
SetupTo save a payment method without making an immediate payment.
Create a Checkout Session
Basic Request
Required Parameters
Optional Parameters
Define Items (line_items)
You have two options for defining items:- Inline price (price_data)
- Existing price (price)
Define the price directly in the request:
Line Item Structure
Price Data Structure
Product Data Structure
Recurring Subscriptions
To create a subscription, usemode: "subscription" and add recurring in price_data:
Available Intervals
Advanced Options
Collect Addresses
Collect Phone Number
Allow Promo Codes
Apply a Promo Code Automatically
Customize the Payment Button
Adjustable Quantity
Allow the customer to modify quantity on the payment page:Complete Example
Response
Response Fields
Redirect the Customer
Once the session is created, redirect the customer to the payment URL:After Payment
Redirection
After payment, the customer is redirected tosuccess_url with the session ID:
Verify Status
Webhooks
For a robust integration, use webhooks to receive payment notifications:Session Statuses
Best Practices
Security
Security
- Always create sessions server-side
- Never store API keys client-side
- Verify status via API or webhooks
User Experience
User Experience
- Pre-fill email if you have it
- Use
client_reference_idto link to your order - Customize
submit_typebased on context
Error Handling
Error Handling
- Handle the case where customer cancels
- Plan for session expiration
- Use webhooks for edge cases
Next Steps
Webhooks
Receive real-time notifications
Promo Codes
Apply discounts to your sessions