POST
/v1/checkout/sessionsOpens a checkout session. Your server reads the cart from your own records, never prices sent by the browser, and names each line's name, description, image, amount and quantity. Nothing is added to your product catalog. The answer carries the session's url: redirect your customer to it.
The url is shown once
The url comes back only when the session is created. Repeating the request with the same idempotency key returns a fresh url, and the earlier unused one stops working.
Endpoint
Request body
| Name | Type | Required | Description |
|---|---|---|---|
mode | enum | Required | payment, subscription or setup. |
ui_mode | enum | Optional | hosted_page, the default. |
line_items | array | Required | What it sells, up to 100 lines (20 recurring and 20 one-time in subscription mode; none in setup mode). Each has a quantity from 1 to 10,000 and a price_data with currency, unit_amount (in cents, up to 99,999,999), product_data (name, and optional description and images, up to 8 https addresses) and, in subscription mode, recurring (unit: day, week, month or year, and count). |
success_url | string | Required | Where the page sends the customer once they've paid. It may carry {CHECKOUT_SESSION_ID}, replaced by the session's ID. In live mode, its domain must be on your allowed return addresses. |
cancel_url | string | Optional | The page's way back to your site. |
customer | string | Optional | A customer of yours, cust_.... Leave it out for a guest. |
customer_email | string | Optional | A guest's email, filled in on the page. Only without customer. |
client_reference_id | string | Optional | Your own reference, such as an order or a cart, to find it again. |
metadata | object | Optional | Up to 50 keys of your own: keys up to 40 characters, values up to 500. |
collect | object | Optional | What the page asks for: billing_address (auto, only what the card needs, or required), shipping_address (boolean) with shipping_countries, phone, tax_id and terms_of_service (booleans). |
payment_description | string | Optional | What its payment says it's for. Default: its lines. |
integration_identifier | string | Optional | A tag of yours that groups sessions by integration, shown in the Dashboard. |
expires_at | timestamp | Optional | When it stops taking a payment: from 30 minutes to 24 hours from now. Default: 24 hours. |
Example request
Example response
Errors
| Code | When |
|---|---|
parameter_invalid | A field isn't valid: an amount out of bounds, a return address that isn't https, or a domain not on your allowed list (live mode). |
request_refused | Your business can't take live payments yet. |