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, do not rely on the redirect to success_url alone: subscribe to the session events (checkout.* family). Successful payment — checkout.session.completed:
Failed attempt — checkout.session.payment_failed:
  • Fields sit directly under data (there is no data.object). amount is in the currency’s major unit (35000 = 35,000 XAF).
  • Identify the payment by data.checkoutSessionId. data.orderId may appear on completed: do not rely on it.
  • For a session created from an invoice, data.invoiceId is added.
  • error is an opaque string, to be logged, not parsed.
  • checkout.session.payment_failed is not final: the session stays open and the customer can retry. It is emitted when the failure is known from the confirmation response; a timeout is carried by intent.expired.
  • checkout.session.expired is not emitted today.
  • A payment through a payment link emits payment_link.checkout.*, and a subscription session emits the subscription events, never checkout.session.*.
See Webhooks Documentation for signature and delivery 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