Utopia PaymentsDocs
Checkout sessions

Retrieve a checkout session

Returns one checkout session: its current status, the cart as it was priced, and the `payment_id` or `subscription_id` it produced once the customer paid. Read it when a customer comes back to your `return_url`, or to recover a checkout link that is still open. `checkout_url` is filled in only while the session is `open`, and a session past its 24 hours reads as `expired`. Only sessions created by the key's merchant and mode are visible.

GET
/checkout_sessions/{id}

Returns one checkout session: its current status, the cart as it was priced, and the payment_id or subscription_id it produced once the customer paid. Read it when a customer comes back to your return_url, or to recover a checkout link that is still open. checkout_url is filled in only while the session is open, and a session past its 24 hours reads as expired. Only sessions created by the key's merchant and mode are visible.

Authorization

secretKey
AuthorizationBearer <token>

Your secret key: sk_live_… or sk_test_….

In: header

Path Parameters

id*string

The checkout session's id, which starts with cks_.

Match^cks_[0-9a-f]{32}$

Response Body

application/json

application/json

application/json

curl -X GET "https://example.com/checkout_sessions/cks_3f2b8c1e9a4d4e7b8c2a1d5e6f7a8b9c"
{  "object": "checkout_session",  "session_id": "cks_3f2b8c1e9a4d4e7b8c2a1d5e6f7a8b9c",  "kind": "payment",  "status": "open",  "checkout_url": "http://example.com",  "total_amount": 0,  "currency": "AED",  "product_cart": [    {      "product_id": "pdt_3f2b8c1e9a4d4e7b8c2a1d5e6f7a8b9c",      "name": "string",      "quantity": 0,      "unit_amount": 0    }  ],  "customer": {    "name": "string",    "email": "user@example.com",    "phone_number": "string"  },  "return_url": "string",  "payment_id": "pay_3f2b8c1e9a4d4e7b8c2a1d5e6f7a8b9c",  "subscription_id": "sub_3f2b8c1e9a4d4e7b8c2a1d5e6f7a8b9c",  "metadata": {    "property1": "string",    "property2": "string"  },  "livemode": true,  "created_at": "2019-08-24T14:15:22Z",  "expires_at": "2019-08-24T14:15:22Z",  "completed_at": "2019-08-24T14:15:22Z"}

Create a checkout session POST

Returns a `checkout_url` to redirect the customer to. A cart with one recurring product starts a subscription; otherwise it takes a one-time payment. Sessions expire after 24 hours. Use it whenever a customer is ready to pay: the card is collected on Utopia's own page, so your server never handles card details. Every item must be in the same currency (`MIXED_CURRENCIES` otherwise), a subscription cart holds that one recurring product and nothing else (`INVALID_CART`), and a saved product must be `active` (`PRODUCT_NOT_ACTIVE`) and priced above zero (`INVALID_PRICE`). List each product once and raise its `quantity` rather than repeating it. Items priced inline are always one-time. An expired session reads as `expired` and has no `checkout_url` left to send anyone to. Send `Idempotency-Key` so a retried request returns the first session instead of creating a second one. A test key sees only test-mode products and creates only test-mode sessions.

Retrieve a payment GET

Returns one payment: what was charged, what has been refunded, Utopia's fee, what you keep (`net_amount`), who paid, and the checkout session or subscription it belongs to. Read it before fulfilling an order — the parameters appended to your `return_url` are only a hint — and after a `payment.succeeded` event when you would rather trust the API than the delivery. `fee_amount` and `net_amount` are `null` while a payment is processing and if it failed. A refund, made with `POST /payments/{id}/refunds` or from the dashboard, shows up here in `status` and `refunded_amount`.