{"object":"doc","slug":"checkout","title":"Hosted checkout","summary":"A checkout session is a ZeroPoint-hosted payment page for a fixed amount. You create it on your server, send the buyer to its url, and fulfil on the checkout.session.completed webhook.","tags":["concept","checkout","payments","keyed"],"body":"# Hosted checkout\n\nA **checkout session** (`cs_...`) is a payment page that ZeroPoint hosts for one purchase at a fixed amount. Your server creates the session, redirects the buyer to its `url`, and the buyer types a card on our page. Your code never handles card data and never builds a card form.\n\nUse it when you want a buyer to pay without building a checkout page. Use the [embedded card form](collect.md) and `POST /v1/payments` instead when the card form must sit inside your own page.\n\n## What a session holds\n\n- `merchant_id`: the merchant taking the payment.\n- `line_items`: 1 to 100 lines, each either a one-time catalog price of this merchant (`{\"price\": \"price_...\", \"quantity\": 1}`) or an inline `price_data` (`currency: usd`, `unit_amount` in integer cents, `product_data.name`) with a `quantity`. The server computes `amount_total` from them when the session is created; nothing the browser sends changes it. The total must be at least 1 cent.\n- Promotion codes in payment mode: `allow_promotion_codes: true` shows a code field on the page, or `discounts: [{\"promotion_code\": \"promo_...\"}]` applies one, on a session with one catalog price line. A code that brings the total to $0 completes the order with no card (`payment_status: no_payment_required`); fulfil it on `checkout.session.completed` as any other.\n- `success_url` (required) and `cancel_url` (optional): where the buyer goes after paying, and the back link on the page. In test mode any `https` URL works, and `http` only for `localhost`.\n- `client_reference_id`: your order or user id. Send it on every create.\n- `expires_at`: 30 minutes to 24 hours ahead; 24 hours by default.\n- `customer_email` and `metadata` (up to 50 string pairs) are optional and echoed back.\n\n## States\n\n| `status` | `payment_status` | Meaning |\n|---|---|---|\n| `open` | `unpaid` | The buyer can pay. `url` is set. |\n| `open` | `processing` | A payment attempt is in flight, or its outcome is being confirmed (the session is **held**). Another card is refused until the outcome is known. |\n| `complete` | `paid` | The payment succeeded. `payment` names it (`pay_...`). |\n| `expired` | `unpaid` | Closed without payment: `expires_at` passed, or you called expire. |\n\nA session is completed or expired once, never both, and never reopened. `url` is `null` once the session is not `open`: the link stops working when the session closes.\n\nA held session (`payment_status: processing`) is ZeroPoint's addition to the Stripe model. When the processor's answer for an attempt is unknown, the session waits for evidence instead of letting the buyer pay twice. It completes or expires by itself once the outcome is known; you do nothing.\n\n## Events\n\n- `checkout.session.completed`: the session is `complete`. Fulfil here, once per session id.\n- `checkout.session.expired`: the session closed unpaid.\n\nEach attempt is also a keyed payment with the usual `payment.*` events. The event's `data.object` is the session as `GET /v1/checkout/sessions/{session_id}` returns it, with `url` null.\n\nAn attempt of a held session can end `payment.failed` with `failure_code: processor_unverified` and later be proven captured at the processor. That payment is then adopted: you receive `payment.succeeded` for the same payment id with `adopted: true`, then `checkout.session.completed`. So do not release stock or cancel an order on a `payment.failed` with `processor_unverified`; wait for the session to complete or expire.\n\n## Scopes\n\n- `checkout_sessions:write`: create and expire.\n- `checkout_sessions:read`: retrieve and list. The sandbox console shows sessions read-only under this scope, never with their `url`.\n\nNew sandbox keys carry both. A key or agent connection made before checkout existed may need to reconnect.\n\n## The page link is a secret\n\nThe token inside `url` opens the payment page. It appears only in `url` of a create or retrieve answer while the session is open. It is never in an event, a webhook, a console answer or a log. Do not store `url` longer than the purchase needs, and do not put it in your own logs.\n\n## Subscription mode\n\nSubscription mode is available. Send `mode: subscription` to sell a recurring plan on the hosted page:\n\n- `line_items`: exactly one line, with a recurring catalog `price` (`price_...`) and `quantity: 1`. A one-time price answers `price_not_recurring`; `price_data` answers `parameter_unavailable` in this mode.\n- `customer` is optional. Without it, the session creates a new customer at the first confirm (never one found by email). Do not send `customer_creation`.\n- `subscription_data.metadata` is copied to the subscription. Trials (`subscription_data.trial_period_days`) are not available yet.\n- A promotion code goes in `discounts: [{\"promotion_code\": \"promo_...\"}]`. `amount_total` is the first invoice's amount, discount included, and the first charge is exactly that amount. A first amount of $0 is refused.\n\nWhen the buyer pays, the subscription starts `active`, its first invoice is paid, the card is saved to the customer for the renewals, and `checkout.session.completed` names the `subscription`. A declined card leaves the session open for another card, and the subscription it started stays `incomplete` (listed by `GET /v1/subscriptions`, with no event) until a later card on that session is captured, or `incomplete_expired` when the session expires. Grant nothing on `incomplete`.\n\nOne buyer, one purchase at a time. The same buyer is matched on the merchant and the price, by your identity: the `customer` id you named, the `client_reference_id` you sent (compared exactly), or the `customer_email` you passed on a session that names no customer (trimmed and in lower case). A named customer is matched by its id only; the email stored on that customer record is never compared, so two customer records that share an address are two buyers. Only for the first rule below is the buyer also matched by an email typed on the page. A typed email is never matched against your identity's emails, so it cannot block or reveal another buyer. Nothing is charged, and no customer or subscription is written, when:\n\n- another first payment for the same buyer and price is still being confirmed, from another session or the API, for as long as that takes. A proven decline does not block: the buyer can try again at once;\n- the same buyer completed this plan in another checkout after this session was created. This session then expires;\n- the merchant's `subscription_guard` is not `off` (it is `product` by default) and the customer you identified already has a live subscription (`active`, `past_due` or `unpaid`) the guard matches, or another of their subscriptions is changing to one: under `price` the same price, under `product` any price of the same product, under `customer` any subscription at this merchant. Under `product` and `customer` the first rule above looks that wide too: a first payment for another price of the product (or for anything, under `customer`) still being confirmed blocks as well. A plan change is never blocked by the subscription being changed; under `price` and `product` a change onto a price or product the customer holds on another subscription is refused the same way (`409 subscription_exists`), under `customer` a change onto a product another of their subscriptions holds (a customer under that guard normally has no other), and while a first payment for the target is still being confirmed it answers `409 subscription_create_unresolved`. Other merchants are never compared. The buyer is matched the same way at every door: the subscription's customer id and the `client_reference_id` and `customer_email` of the checkout that bought it. An email counts only when you passed it as `customer_email` on a session with no customer, never the email of a customer record and never one typed on the page. A subscription you create through the API matches a later checkout only through `customer`: send `customer` at checkout too, since a checkout that carries only a `client_reference_id` or `customer_email` makes its own customer and does not match it. Reuse one customer per user: a platform that creates a new `cus_` for the same person at every checkout is not protected (each record is a new buyer). Changing the guard does not touch existing subscriptions. A scheduled change that would give the buyer a price twice is refused only when it falls due; until then GET, the portal and `invoice.upcoming` still show it, so cancel conflicting scheduled changes before tightening the guard. When one falls due it is canceled instead, and a failed upgrade does not bring back a downgrade onto such a price: the `customer.subscription.updated` event then carries `data.reason.code` (`scheduled_change_refused_subscription_exists` or `scheduled_change_not_restored`) and names the subscription that holds the price. An email typed on the page is never used for this rule. With the guard on, a subscription session that names no buyer is refused at create with `400 customer_identity_required`: send `customer`, `client_reference_id` or `customer_email`.\n\nThese are the buyer's identity now. Send one stable `client_reference_id` per buyer (your user id), not per order, cart, location, campaign or household: with the guard on, every buyer after the first under a shared value is refused. Put into `customer_email` only an address your app has verified: the create's answer says whether that buyer already has the plan, so an address typed into your own unauthenticated form should go in as the buyer types it on our page, not as `customer_email`. Send the same identity form for a buyer every time: a purchase identified by a verified `customer_email` and one naming a `customer` are not matched to each other, in either order. A `client_reference_id` shared by two customer records says they are one buyer: for two children use one customer per child and do not send the parent's user id as `client_reference_id` on both, or set the guard to `price` or `off`.\n\nYour create is told with `409 subscription_create_unresolved` (naming the subscription and invoice), `409 checkout_outcome_unknown` (naming `held_session_id`) or `409 subscription_exists` (naming the subscription), when you sent your identity. After a refused Pay the session's `duplicate_refusal` says why (`subscription_create_unresolved`, `subscription_completed_elsewhere` or `subscription_exists`); only your key can read it, and the next confirm clears it. These create refusals are kept under the request's Idempotency-Key for 24 hours, as every refusal of this route is: once the first payment is resolved, send the next create under a new key.\n\nWhat the buyer sees depends on who identified them. With your identity, the page answers `409 checkout_subscription_refused` for every refusal, with one sentence: \"We could not start this subscription. Nothing was charged. If you already subscribed, you do not need to do anything. Otherwise go back to {merchant} and start again.\" ({merchant} is the merchant's display name.) After 3 such answers the session expires. An address that gets 10 such answers at one merchant in an hour is asked to wait before it starts another subscription payment at that merchant, up to 6 minutes per further refusal. Only refusals on your identity count toward the 3 per session and the 10 per hour; a refusal on a typed email alone counts toward neither. A buyer resuming the session's own payment already under way is never held back, and other merchants are not affected. When the buyer is known only by an email typed on the page, only the first rule applies: while another payment for that email and plan is being confirmed, Pay is refused with the page's ordinary `400 parameter_invalid`, \"This payment could not be started. Reload the page and try again.\", and nothing is charged. So a visitor who types an address can learn that some payment for it is being confirmed right now; nothing about an existing subscription is ever shown. A typed email that matches a past purchase, or a live subscriber, goes ahead as any other purchase, so a real subscriber can buy the same plan again without being stopped. Pass `customer` or `client_reference_id` so a repeat buyer gets a clear message and the other rules apply, and tell them in your own app, which knows the customer.\n\n## Not available yet\n\n- Google Pay and Apple Pay on the hosted page: card entry only for now.\n- Tax: no tax is computed and there is no tax line. `automatic_tax.enabled: true` answers `parameter_unavailable`; `total_details.amount_tax` is always 0.\n- Live mode: enabled per platform by ZeroPoint. Until then a live create answers `checkout_unavailable`.\n\nNext: [Accept payments with hosted checkout](accept-payments-with-checkout.md).","updated":1795275945}