> ## Documentation Index
> Fetch the complete documentation index at: https://docs.easner.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Checkout

> Take card and bank payments and subscriptions on your website. Funds land on your business balance.

Checkout takes online payments on your website. Your server creates a **session** with the amount and your secret key. The browser only ever gets the session `url`, or a publishable key and the session `client_secret`.

When a payment succeeds, funds land on **your** business balance, the same place as invoices and payment links. Checkout is not Receive: it never credits a customer `acct_`. To fund a customer vault, use [Receive](https://docs.easner.com/receive.md).

Checkout does not take USDC. A stablecoin payment link shows your static wallet address only. There is no USDC session or quote on the API.

> [!NOTE]
>
> **Scope:** `checkout`
>
> Before your first call in Test: add your website as an allowed website (Console, Checkout, your site, Settings), and mint a key with the `checkout` scope in Settings, API keys. The fastest route is Console, Checkout, Integrate. It writes the code below for your language. See [Quickstart](https://docs.easner.com/quickstart.md). Test needs no verification or payment setup. Live needs your business verified and online payments turned on and set up (Settings → Payments).

## Three ways to open checkout

| Surface | You do | Customer sees |
| - | - | - |
| Hosted page | Redirect to the session `url` (`https://checkout.easner.com/cs_…`) | A page Easner hosts, then your `success_url` |
| Overlay | Call `EasnerCheckout.openOverlay` with the `client_secret` | A panel over your page |
| Inline | Call `EasnerCheckout.mount` with the `client_secret` | The pay form inside your own checkout page |

The hosted page needs no script and no publishable key. The overlay and inline forms load `https://js.easner.com/v1/checkout.js` and a publishable key (`easner_pk_test_…`).

## Create a session

`POST /v1/checkout/sessions`. Always send `Idempotency-Key`, one stable key per order, so a retry never creates a second session.

```bash curl theme={null}
curl https://api.easner.com/v1/checkout/sessions \
  -H "Authorization: Bearer $EASNER_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: checkout-ord_1042" \
  -d '{
    "mode": "payment",
    "currency": "usd",
    "line_items": [
      { "name": "House blend, 1 kg", "amount": 2400, "quantity": 2 },
      { "name": "Pour-over kettle", "amount": 6500 }
    ],
    "customer_email": "ada@example.com",
    "success_url": "https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}",
    "cancel_url": "https://yoursite.com/cart",
    "metadata": { "order_id": "ord_1042" }
  }'
```

```js Node theme={null}
const response = await fetch("https://api.easner.com/v1/checkout/sessions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.EASNER_SECRET_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": `checkout-${orderId}`,
  },
  body: JSON.stringify({
    mode: "payment",
    currency: "usd",
    line_items: [
      { name: "House blend, 1 kg", amount: 2400, quantity: 2 },
      { name: "Pour-over kettle", amount: 6500 },
    ],
    customer_email: "ada@example.com",
    success_url: "https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}",
    cancel_url: "https://yoursite.com/cart",
    metadata: { order_id: orderId },
  }),
});
const session = await response.json();
if (!response.ok) throw new Error(session.error.code);
```

```python Python theme={null}
import os
import requests

response = requests.post(
    "https://api.easner.com/v1/checkout/sessions",
    headers={
        "Authorization": f"Bearer {os.environ['EASNER_SECRET_KEY']}",
        "Idempotency-Key": f"checkout-{order_id}",
    },
    json={
        "mode": "payment",
        "currency": "usd",
        "line_items": [
            {"name": "House blend, 1 kg", "amount": 2400, "quantity": 2},
            {"name": "Pour-over kettle", "amount": 6500},
        ],
        "customer_email": "ada@example.com",
        "success_url": "https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}",
        "cancel_url": "https://yoursite.com/cart",
        "metadata": {"order_id": order_id},
    },
    timeout=30,
)
session = response.json()
response.raise_for_status()
```

```php PHP theme={null}
<?php
$ch = curl_init("https://api.easner.com/v1/checkout/sessions");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("EASNER_SECRET_KEY"),
        "Content-Type: application/json",
        "Idempotency-Key: checkout-" . $orderId,
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "mode" => "payment",
        "currency" => "usd",
        "line_items" => [
            ["name" => "House blend, 1 kg", "amount" => 2400, "quantity" => 2],
            ["name" => "Pour-over kettle", "amount" => 6500],
        ],
        "customer_email" => "ada@example.com",
        "success_url" => "https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}",
        "cancel_url" => "https://yoursite.com/cart",
        "metadata" => ["order_id" => $orderId],
    ]),
]);
$session = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
```

```ruby Ruby theme={null}
require "net/http"
require "json"

uri = URI("https://api.easner.com/v1/checkout/sessions")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{ENV.fetch('EASNER_SECRET_KEY')}"
request["Content-Type"] = "application/json"
request["Idempotency-Key"] = "checkout-#{order_id}"
request.body = {
  mode: "payment",
  currency: "usd",
  line_items: [
    { name: "House blend, 1 kg", amount: 2400, quantity: 2 },
    { name: "Pour-over kettle", amount: 6500 }
  ],
  customer_email: "ada@example.com",
  success_url: "https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}",
  cancel_url: "https://yoursite.com/cart",
  metadata: { order_id: order_id }
}.to_json

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
session = JSON.parse(response.body)
```

Response, `201` (`200` when an `Idempotency-Key` replays an existing session):

```json theme={null}
{
  "object": "checkout.session",
  "id": "cs_test_a1B2c3…",
  "checkout_session_id": "cs_test_a1B2c3…",
  "client_secret": "cs_test_a1B2c3…_secret_…",
  "url": "https://checkout.easner.com/cs_test_a1B2c3…",
  "status": "open",
  "mode": "payment",
  "amount": 11300,
  "amount_total": 11300,
  "amount_due_today": 11300,
  "currency": "USD",
  "line_items": [
    {
      "name": "House blend, 1 kg",
      "description": null,
      "image_url": null,
      "quantity": 2,
      "unit_amount_cents": 2400,
      "amount_cents": 4800,
      "adjustable_quantity": null,
      "kind": "item"
    }
  ],
  "trial_days": null,
  "payment_method_collection": "always",
  "trial_end_behavior": null,
  "customer": null,
  "customer_email": "ada@example.com",
  "customer_name": null,
  "metadata": { "order_id": "ord_1042" },
  "expires_at": "2026-10-10T10:00:00.000Z",
  "livemode": false
}
```

Hand the browser **only** `url` (hosted) or `client_secret` (overlay and inline). Keep the rest on your server.

### Fields

Every field on the session, including each line item, is on [Create a checkout session](https://docs.easner.com/api-reference/checkout-sessions/create-a-checkout-session.md). That page is the contract.

`expires_in` is whole seconds, 1800 (30 minutes) to 86400 (24 hours), default 86400. Outside that range, or not a whole number, is `400` `invalid_expires_in`. It is never clamped. `metadata` keys starting `easner_` are reserved and dropped. A customer id that is not yours in this mode is `400` `customer_not_found`.

`payment_method_collection: "if_required"` starts a trial with no card. It needs `mode: subscription` and a trial, or the call is `400` `invalid_payment_method_collection`. See [Start a trial without a card](https://docs.easner.com/subscriptions.md#start-a-trial-without-a-card).

A line with no `name` and no `price` is titled "Online payment". A catalog `price` supplies the name, amount and currency, and a recurring price makes the session a subscription. Copy the id from Console, Checkout, Products. A live payment link can also copy it from Banking, Collections, Links. A tiered price comes back with `tier_breakdown`. See [Tiered prices](https://docs.easner.com/products-and-prices.md#tiered-prices).

`success_url` and `cancel_url` must be full `https://` addresses on a website you added in Console, Checkout, your site, Settings. In test mode, `http://localhost`, `http://127.0.0.1` and `https://localhost` (any port) work without being on that list. If you list no websites yet the check is skipped. If omitted, the site's saved URLs or your Checkout defaults apply, then an Easner thank-you page. A browser `Origin` header that is not on your list also gets 400 `origin_not_allowed`, except localhost in test mode.

## Open checkout

### Hosted page

Redirect the browser to `session.url`.

```js theme={null}
// POST /checkout on your server
res.redirect(303, session.url);
```

The customer pays on `https://checkout.easner.com/cs_…` and returns to `success_url`.

### Overlay

```html theme={null}
<script src="https://js.easner.com/v1/checkout.js"></script>
<button id="pay">Check out</button>
<script>
  document.getElementById("pay").addEventListener("click", async function () {
    var res = await fetch("/api/checkout", { method: "POST" });
    var session = await res.json();
    EasnerCheckout.openOverlay({
      publishableKey: "easner_pk_test_…",
      clientSecret: session.client_secret,
      onSuccess: function () { window.location = "/thanks"; },
      onClose: function () {}
    });
  });
</script>
```

### Inline

```html theme={null}
<script src="https://js.easner.com/v1/checkout.js"></script>
<div id="checkout"></div>
<script>
  fetch("/api/checkout", { method: "POST" })
    .then(function (r) { return r.json(); })
    .then(function (session) {
      EasnerCheckout.mount("#checkout", {
        publishableKey: "easner_pk_test_…",
        clientSecret: session.client_secret,
        onSuccess: function () { window.location = "/thanks"; }
      });
    });
</script>
```

`EasnerCheckout` has three methods: `mount(target, options)`, `openOverlay(options)` and `destroy(target?)`. Options: `publishableKey`, `clientSecret`, optional `customerEmail`, `customerName`, `onSuccess` (alias `onComplete`), `onError`, and for the overlay `title` and `onClose`. The overlay is titled with your business name and uses your accent colour.

### What the overlay and inline form collect

The embedded form follows the session you created, so nothing extra is passed to `EasnerCheckout`:

| You set on the session | The payer sees |
| - | - |
| `collect.address` `billing` or `shipping` | A billing or shipping address form. With `collect.phone` it includes a phone number |
| `collect.phone` with no address | A **Phone number** field |
| `collect.custom_fields` | One labelled text input per field. Optional fields say "(optional)"; a missing required one stops the payment with "Enter" plus the field label in lower case |
| `collect.terms_url` | A required checkbox, "I agree to (your business name)'s terms.", linking to your terms. The payment is refused until it is ticked |
| `allow_promotion_codes` | **Add promotion code** whenever this mode has a code. Omit it and the field still shows. `false` hides it. An invalid code reads "That code isn't valid."; a valid one shows as a chip with the amount off and a remove button |
| A line item with `adjustable_quantity` | A quantity stepper inside its limits. The total and the Pay button follow |

The result shows **Payment complete**, the **Amount paid** and the **Receipt number** (the same number as the PDF and the email). The number appears a moment after the payment settles; until then the row reads "Receipt is on its way". A bank payment that is still processing shows the amount only. Custom fields, terms and the receipt number are read from, and saved to, Easner's public session endpoints on the host that served `checkout.js`; no secret is sent from the browser.

Saved cards for returning payers are not drawn in the embedded form: the session is created on your server, so Easner cannot attach the payer's saved details to it from the browser. Use the hosted page or a payment link for that.

Swapping `easner_pk_test_…` for `easner_pk_live_…` is part of going live. Use the key whose mode matches the session.

> [!WARNING]
>
> `onSuccess` runs in the browser and can be faked. Fulfil the order from the `checkout.completed` [webhook](https://docs.easner.com/webhooks.md), never from `onSuccess` or the return URL alone.

### Website button

For a static page with no code of your own, load the button script and mark any element:

```html theme={null}
<script src="https://js.easner.com/v1/button.js"></script>

<!-- Pay a session you created on your server -->
<button data-easner-button data-easner-session="cs_test_a1B2c3…">Pay now</button>
```

`data-easner-session` takes a `cs_…` id. The button opens the overlay on your page. No publishable key is needed. If the overlay cannot take the payment, it sends the customer to the hosted page instead. The element fires `easner:complete` when paid and `easner:close` when the overlay closes. Cmd or Ctrl click opens the link normally.

Optional attributes on the script tag: `data-easner-api` points the script at another Easner API origin (https, or localhost over http).

## Retrieve and list sessions

`GET /v1/checkout/sessions/cs_…` reads one session by its id in the path. `GET /v1/checkout/sessions?id=cs_…` reads the same session with the id as a query parameter.

```bash theme={null}
curl https://api.easner.com/v1/checkout/sessions/cs_test_a1B2c3… \
  -H "Authorization: Bearer $EASNER_SECRET_KEY"
```

Every field is on [Retrieve a checkout session](https://docs.easner.com/api-reference/checkout-sessions/retrieve-a-checkout-session.md). That page is the contract.

| `status` | Meaning |
| - | - |
| `open` | Waiting for the customer |
| `processing` | A US bank debit was submitted. It is credited only if it succeeds. Do not fulfil yet |
| `complete` | Paid (or `no_payment_required` for a free trial) |
| `expired` | Not paid in time |
| `failed` | The attempt failed |

`payment_status` is `paid`, `unpaid`, `processing`, `no_payment_required`, `failed` or `null`. A session from another mode or business is `404 not_found`.

Use this read on your return page to show an honest status. Fulfil from the webhook.

### List sessions

`GET /v1/checkout/sessions` lists the sessions of this mode, newest first. It covers website and payment-link sessions. Invoice sessions are not listed. For line items, discounts and tax, read the session. The query fields are on [List checkout sessions](https://docs.easner.com/api-reference/checkout-sessions/list-checkout-sessions.md). That page is the contract.

```bash theme={null}
curl "https://api.easner.com/v1/checkout/sessions?status=complete&created[gte]=1759276800&limit=50" \
  -H "Authorization: Bearer $EASNER_SECRET_KEY"
```

An `open` session past its `expires_at` is listed as `expired`. A `customer` or `payment_link` that is not yours in this mode is `404 not_found`. `created[gte]` and `created[lte]` take Unix seconds or ISO 8601, both ends included. Page with `limit` (1 to 100, default 20) and `starting_after`. See [v1 reference](https://docs.easner.com/reference.md#lists).

The list reads Easner's record, so a status can lag its webhook by a moment. Retrieve one session for the live status. Sessions with the same creation time can fall on either side of a page boundary, so use `created` filters when you need an exact window.

### Customers and payments

Checkout customers and the payments they made have their own reads. Both are scoped to your business and mode, and both are separate from banking customers (`cus_`, `GET /v1/customers`).

| Method | Path | What it returns |
| - | - | - |
| `GET` | `/v1/customers/checkout` | Checkout customers, newest first. Each has a UUID `id` (the `customer` on sessions), `email`, `name`, `company`, `livemode` and `created` |
| `GET` | `/v1/customers/checkout/:id` | One customer, with `saved_payment_method` (the default card or bank account: `type`, `brand` and `last4` only) and `portal` (`enabled`, from Settings, Payments) |
| `GET` | `/v1/payments` | Settled checkout payments, newest first, by settlement id: `checkout_session` (`cs_…`, or `null` for a subscription renewal), `amount`, `currency`, `status` (`paid`, `refunded` or `partially_refunded`), `refunded_cents` and `created`. Filters: `status` and `created[gte]` / `created[lte]` |
| `GET` | `/v1/payments/:id` | One payment by its settlement id, with `customer`, `payment_link`, `subscription_id`, `payment_intent` and your `metadata` |

A session that is still processing, or that failed, is not a payment and is not listed. Read it from `GET /v1/checkout/sessions/:id`.

## Subscriptions

```json theme={null}
{
  "mode": "subscription",
  "currency": "usd",
  "line_items": [{ "name": "Beans every month", "amount": 3600, "quantity": 1 }],
  "recurring": { "interval": "month", "interval_count": 1 },
  "trial_days": 14,
  "customer_email": "ada@example.com",
  "success_url": "https://yoursite.com/thanks?session_id={CHECKOUT_SESSION_ID}",
  "cancel_url": "https://yoursite.com/plans",
  "metadata": { "user_id": "123", "plan": "pro" }
}
```

During a trial, `amount_due_today` is `0` and the button reads "Start free trial". Unlock access on `checkout.completed`, then keep it in sync with `subscription.updated`, `subscription.canceled` and `subscription.payment_failed`. Renewals happen without the customer on your site, so the webhooks are the only signal. Customers manage their own subscription, payment method and receipts in the [customer portal](https://docs.easner.com/customer-portal.md).

**Per-seat pricing.** Charge per user with the seat count as the quantity. Make a recurring [catalog price](https://docs.easner.com/products-and-prices.md#per-seat-pricing) with `per_seat: true` and a `min_quantity`, then send it as `line_items[].price` with `quantity` set to the seats. A quantity below the minimum is `400` `invalid_quantity`, and a per-seat line can go up to 10,000. Add `adjustable_quantity` if the customer should change the seats on the page. Later they can change the seats in the portal, or you can change them with `POST /v1/subscriptions/:id`. See [Subscriptions](https://docs.easner.com/subscriptions.md#change-seats-or-price).

**Trials take a card.** A free trial asks for a card up front, so the subscription can continue when the trial ends. Nothing is charged during the trial, and the button reads "Start free trial".

**Discounts.** If a [customer discount](https://docs.easner.com/checkout-discounts.md#customer-discounts) exists for the session's `customer_email`, it applies automatically, and the session does not show the promotion code field.

## Refunds and the portal

Refund all or part of a payment with `POST /v1/refunds`: [Refunds](https://docs.easner.com/refunds.md). Send a customer to their account page with `POST /v1/customer_portal/sessions`: [Customer portal](https://docs.easner.com/customer-portal.md).

## Idempotency

`Idempotency-Key` (up to 255 characters, longer is `400` `invalid_idempotency_key`; scoped to your business) on `POST /v1/checkout/sessions`:

* Same key and same body: you get the **same session** back (`200`, amounts as stored the first time).
* Same key and a different body: `409 idempotency_mismatch`.
* Same key while the first call is still creating its session: `409 idempotency_in_progress`. Retry after a second.

Use one stable key per order, such as `checkout-ord_1042`. A new random key on every retry defeats the protection.

## Test and live

Test keys create test sessions. Pay with `4242 4242 4242 4242`, any future expiry, any CVC. `4000 0000 0000 0002` is declined. Nothing is charged and test payments never touch your live balance. A test session only exists in test mode. A live key is needed for live sessions. See [Test and live](https://docs.easner.com/test-and-live.md) for the go-live checklist.

## Events

Tick these on a webhook endpoint in Console, Settings, Webhooks. Full payloads: [Webhooks](https://docs.easner.com/webhooks.md).

| Event | Expected |
| - | - |
| `checkout.completed` | Payment succeeded (or a free trial started). Fulfil. Funds land on your balance |
| `checkout.async_succeeded` | A delayed bank debit charged (not sent for cards). Informational: fulfil from `checkout.completed` |
| `checkout.failed` | The payment failed or the bank debit did not go through. Do not fulfil |
| `payment.available` | Funds are usable on your business balance |
| `subscription.updated`, `subscription.canceled` | A renewal, plan change or cancellation |
| `subscription.payment_failed` | A renewal could not be charged. Ask the customer to update their payment method |
| `refund.created`, `refund.updated`, `refund.failed` | A refund was made, changed or did not go through |
| `dispute.created`, `dispute.updated`, `dispute.closed` | A chargeback was opened, changed or decided |

## Expected

* The amount and your secret key never reach the browser.
* You fulfil in the webhook, using the `metadata` you sent.
* Console, Banking Home and `GET /v1/transactions` (type `checkout`) show the payment.
* A checkout payment never credits a customer `acct_`.

> [card] [Webhooks](https://docs.easner.com/webhooks.md)
>
> Signature check, retries, and every payload.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.