Skip to main content

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_abc123def456ghi789jkl012

Session 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:
Define the price directly in the request:

Line Item Structure

Price Data Structure

Product Data Structure

Recurring Subscriptions

To create a subscription, use mode: "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 to success_url with the session ID:

Verify Status

Never trust the redirect alone. Always verify the session status server-side.

Webhooks

For a robust integration, use webhooks to receive payment notifications:
See Webhooks Documentation for more details.

Session Statuses

Best Practices

  • Always create sessions server-side
  • Never store API keys client-side
  • Verify status via API or webhooks
  • Pre-fill email if you have it
  • Use client_reference_id to link to your order
  • Customize submit_type based on context
  • 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