> ## 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.

# Embed reference

> Every option, callback and attribute of checkout.js and button.js, what the embedded form collects, and what the browser must never hold.

Two scripts put Checkout on your own page. Both are served from `js.easner.com`.

| Script | Use it when | Needs |
| - | - | - |
| `https://js.easner.com/v1/checkout.js` | You want the overlay or the inline form, with your own code and callbacks | A publishable key and a session `client_secret` |
| `https://js.easner.com/v1/button.js` | You want any element on a page to open the overlay, with no code of your own | A `data-easner-session` id or a payment link address |

For creating sessions, see [Checkout](https://docs.easner.com/checkout.md). This page covers the browser side only.

## What the browser holds

| Safe in the browser | Never in the browser |
| - | - |
| Publishable key (`easner_pk_test_…`, `easner_pk_live_…`) | Secret key (`easner_sk_…`) |
| Session `client_secret` and session id (`cs_…`) | Restricted keys, webhook signing secrets |

Create the session on your server with your secret key, read from the environment, and send only the `client_secret` (or the session id for `button.js`) to the page. `checkout.js` refuses a key that starts with `easner_sk_`, `sk_` or `rk_` by name, before anything is sent, and throws an error that says to use the publishable key. A publishable key can only call the validate route below. It cannot create sessions, read data or refund.

`onSuccess` and the button events run in the browser and can be faked. Fulfil orders from the `checkout.completed` [webhook](https://docs.easner.com/webhooks.md).

## checkout.js

Loading the script defines `window.EasnerCheckout` with three methods: `mount`, `openOverlay` and `destroy`. The pay form runs in a secure frame served from `checkout.easner.com`, so card details never touch your page and your page loads nothing but Easner. The script hands the frame your publishable key and client secret directly, never in a URL. If your site sends a Content Security Policy, allow the hosts in [Content Security Policy](#content-security-policy).

### Options

`mount` and `openOverlay` take the same options. `openOverlay` adds `title` and `onClose`.

| Option | Type | Default | Required | Behaviour |
| - | - | - | - | - |
| `publishableKey` | string | none | Yes | Must look like `easner_pk_test_` or `easner_pk_live_` followed by hex characters. Anything else throws "publishableKey is required". Test keys show a test band on the form. Use the key whose mode matches the session |
| `clientSecret` | string | none | Yes | The session `client_secret` from your server. The session id is read from it (the part before `_secret_`) to load the custom fields, terms and receipt number |
| `customerEmail` | string | none | No | Prefills the Email field, and is passed to the payment as the default email. If the session already has an email, the Email field is hidden and the session's email is used |
| `customerName` | string | none | No | Prefills the billing name |
| `onSuccess` | function, one argument | none | No | Runs once after a successful payment. See [Callbacks](#callbacks) |
| `onComplete` | function, one argument | none | No | Alias of `onSuccess`. If you set both, both run |
| `onError` | function, one argument | none | No | Runs with an `Error`. See [Callbacks](#callbacks) |
| `title` | string | Your business name, then `Pay` | No, overlay only | Replaces the title in the overlay header |
| `onClose` | function, no arguments | none | No, overlay only | Runs when the overlay closes, paid or not |

`mount(target, options)` takes the target as its first argument: a CSS selector string or a DOM element. If it matches nothing, `mount` throws "mount target not found". `mount` replaces the target's contents with the form's frame, which fills the target's width and grows and shrinks with the form, so give the target a width and no fixed height.

Both `mount` and `openOverlay` return a promise that resolves to an object with one method, `destroy()`. The promise resolves once the form is on screen, or rejects with an `Error` if it could not load.

### mount

Draws the pay form inside your own page. Your cart or order summary stays yours. The form shows its own **Payment complete** state.

```html theme={null}
<script src="https://js.easner.com/v1/checkout.js"></script>
<div id="checkout"></div>
<script>
  // Your server creates the session with its secret key and returns the client secret.
  fetch("/api/checkout", { method: "POST" })
    .then(function (r) { return r.json(); })
    .then(function (session) {
      return EasnerCheckout.mount("#checkout", {
        publishableKey: "easner_pk_test_…",
        clientSecret: session.client_secret,
        customerEmail: "ada@example.com",
        onSuccess: function () { window.location = "/thanks"; },
        onError: function (error) { console.error(error.message); }
      });
    });
</script>
```

### openOverlay

Opens a dialog over your page. The header shows your logo and business name (or `title`), then a summary of the order with a **View order details** toggle, then the form. It is a 480 pixel dialog on larger screens and a full-screen sheet on phones.

```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,
      title: "Lumen Coffee",
      onSuccess: function () { window.location = "/thanks"; },
      onClose: function () { console.log("closed"); }
    });
  });
</script>
```

Overlay behaviour:

* The page behind it stops scrolling, focus stays inside the dialog, and focus returns to the element that was focused when it opened.
* The Escape key, a click on the dimmed area, the close button and the **Done** button after paying all close it.
* While a payment is being confirmed, Escape, the dimmed area and the close button do nothing, so the result is not lost.

### destroy

`EasnerCheckout.destroy(target?)` removes what you mounted.

| Call | What happens |
| - | - |
| `destroy(mounted)` with the object that `mount` or `openOverlay` resolved to | Removes that one form or overlay |
| `destroy("#checkout")` or `destroy(element)` | Empties that element, then removes every form and overlay this script opened |
| `destroy()` | Removes every form and overlay this script opened |

Destroying an inline form runs no callbacks. Destroying an overlay closes it the same way the close button does, so it runs `onSuccess` and `onComplete` first if the payer had paid, then `onClose`. Unlike the close button, it does not wait for a payment in progress.

## Callbacks

| Callback | When it runs | Argument |
| - | - | - |
| `onSuccess` and `onComplete` (inline) | Once, as soon as the payment succeeds, including a bank payment that is still processing | The result of confirming the payment: an object with `type` set to `success` and the `session` |
| `onSuccess` and `onComplete` (overlay) | Once, when the overlay closes after a successful payment, just before `onClose`. Not when it closes unpaid | The same result object |
| `onClose` (overlay) | Every time the overlay closes, paid or not, after the success callbacks | None |
| `onError` | When the form could not load (bad key, key not active, the payment form library blocked, test payments not set up), and each time a payment is declined or fails | An `Error`. For a decline, its message is the plain-words title and body the payer sees |

Notes:

* A failed load also rejects the promise from `mount` or `openOverlay`, so you can use either `onError` or a `catch`. A missing mount target or a missing `clientSecret` in `mount` throws without calling `onError`.
* A decline does not close anything. The payer sees the message and can try again, so `onError` can run more than once.
* The success argument tells you the browser finished the payment. It does not prove funds arrived. Use the webhook to fulfil.

## The validate call

Before it draws anything, `checkout.js` checks the publishable key with:

```
GET /v1/checkout/publishable-keys/validate?key=easner_pk_test_…
```

The request needs no `Authorization` header. The script sends it to the API origin it was built with, not to the page's origin.

| Status | Meaning |
| - | - |
| `200` | The key is active. The body has `ok`, `mode` (`test` or `live`), `publishable_key` and `account_id` (what the script needs to load the payment form for your account), and `business` |
| `400` | `missing_key`: the `key` query parameter is empty |
| `401` or `403` | `invalid_publishable_key`: the key is unknown, revoked or not allowed. The embed shows "We couldn’t load the payment form" and calls `onError` |
| `503` | `test_payments_unconfigured`: a test key was used and test payments are not set up |

`business` carries `name`, `logo_url`, `accent` and `accent_fallback`. The overlay title, logo and accent come from it.

## Appearance and accent

You do not pass appearance options. What the embed looks like comes from your business settings.

| What | Where it comes from |
| - | - |
| Business name and logo in the overlay header | Your Checkout branding. `title` overrides the name. With no logo, the first letter of the name is shown in a tile |
| Accent colour | Your Checkout branding. It colours the Pay button, focus rings, links, the selected payment tab and the payment fields |
| Everything else (fonts, radius, layout, field styling) | Fixed by Easner. Payment methods are shown in a tabs layout, with digital wallets shown first when the device supports them |

Accent fallback: the accent is used only if white text on it has a contrast ratio of at least 4.5 to 1. If the accent is missing, is not a hex colour or is too light, the embed uses Easner blue instead. The validate call applies the same check and returns `accent_fallback` as `true` when it substituted the blue. Inline forms draw in Easner blue until the key check returns, then switch to your accent.

The embed has light appearance only. There is no dark option and no option to restyle it. Test keys add a test band above the form.

## What the embed collects

The form follows the session you created on your server. Nothing extra is passed to `EasnerCheckout`.

| You set on the session | The payer sees |
| - | - |
| Email, when the session has none | An **Email** field first. It is required and checked before paying |
| `collect.address` `billing` or `shipping` | An address form. With `collect.phone` it includes a phone number |
| `collect.phone` with no address | A **Phone number** field, required |
| `collect.custom_fields` | One text input per field (the first three are shown, labels are cut at 50 characters, values at 255). Optional fields say "(optional)". A missing required field stops the payment with "Enter" and the label in lower case |
| `collect.terms_url` | A required checkbox, "I agree to (business name)’s terms.", linking to your terms. The payment does not start until it is ticked |
| `allow_promotion_codes` | **Add promotion code**. A code that is not valid reads "That code isn’t valid." |
| A line item with `adjustable_quantity` | A quantity stepper. The total and the Pay button follow |

Custom field values and the terms answer are saved to Easner before the payment is confirmed. If saving fails, the payment does not start and the payer sees the reason. The embed also reads the custom fields, terms, and the receipt number from Easner's public session routes on the API origin of the script, with no credentials and no secret.

After a payment the form shows **Payment complete**, the **Amount paid**, and a **Receipt number** that reads "Receipt is on its way" until it exists. A bank payment still processing shows "Your payment is processing" and the amount only.

Saved cards are not offered in the embed. Nothing in the embed script attaches a saved customer to the session or draws saved payment methods. Use the hosted page or a payment link for that.

If the session details cannot be read from Easner, the form still shows what it can (email, wallets, payment methods, address when it has one), but custom fields and terms are skipped and the receipt number is not shown.

## button.js

`button.js` opens the same overlay for any element marked `data-easner-button`. It needs no publishable key and no code of your own. One listener on the page covers every button, including ones added later.

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

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

<!-- A payment link made in Console -->
<a data-easner-button href="https://pay.easner.com/lumen/house-blend">Buy coffee</a>
```

### Attributes

| Attribute | On | Behaviour |
| - | - | - |
| `data-easner-button` | The element to click | Marks it. No value. A `div` or `span` gets `role="button"` and `tabindex="0"` if it has none, and Enter and Space activate it |
| `data-easner-session` | The element | A Checkout Session id (`cs_…`, letters, digits and underscores). Opens that session in the overlay |
| `data-easner-link` | The element | A payment link address, `https://pay.easner.com/` then the easetag and slug, or a `plink_…` id |
| `href` | A link element | Read as the payment link when `data-easner-link` is absent. When `data-easner-session` is set, it is only the fallback address |
| `data-easner-api` | The `script` tag, not the button | Points the script at another Easner API origin. It must be https, or http on localhost. Default: the origin the script was loaded from |

### How it chooses what to open

1. If `data-easner-session` is a valid `cs_…` id, it reads that session from the API. If the session is open and can be paid in the overlay, the overlay opens. If it is not open (completed, expired), the browser goes to the session's hosted page instead.
2. Otherwise, if `data-easner-link` (or the `href` of a link) is set, it reads the payment link. The overlay opens only for a card or bank link with a fixed amount or a subscription, with online payments on and the link open. A link where the customer chooses the amount, a stablecoin link, a closed link, or any address that is not a payment link goes to that address instead.
3. A session id wins over a link on the same element. If neither is usable, the element's `href` is used as the destination, and a bare button with nothing usable does nothing.

If anything fails while resolving, or the payment form cannot load, the overlay is closed and the browser goes to the hosted page or the link address.

Clicks with Cmd, Ctrl, Shift or Alt held, and clicks other than the main button, keep the browser's own behaviour. While a button resolves it has `aria-busy="true"`, and a second click is ignored. Only one overlay can be open at a time.

### Events

`button.js` fires these on the element that was clicked. They bubble, so you can listen on `document`.

| Event | When | `event.detail` |
| - | - | - |
| `easner:complete` | The overlay closes after a successful payment | The result of confirming the payment (`type` is `success`) |
| `easner:close` | The overlay closes, paid or not, after `easner:complete` | None |

```html theme={null}
<script src="https://js.easner.com/v1/button.js"></script>
<button data-easner-button data-easner-session="cs_test_a1B2c3…">Pay now</button>
<script>
  document.addEventListener("easner:complete", function () {
    window.location = "/thanks";
  });
  document.addEventListener("easner:close", function () {
    console.log("overlay closed");
  });
</script>
```

Branding for the overlay (name, logo, accent) comes with the session or link from the API, so the same accent rules apply.

> [!WARNING]
>
> Never put `EASNER_SECRET_KEY` in a page, a script tag, a data attribute or front-end code. Only the publishable key and the session `client_secret` or id belong in the browser.

## Content Security Policy

Most sites need nothing here. If your site sends a `Content-Security-Policy` header, allow Easner's two hosts, or the pay form will not load:

| Directive | Hosts |
| - | - |
| `script-src` | `https://js.easner.com` |
| `frame-src` | `https://checkout.easner.com` |

Nothing else is needed: the payment form, wallets and 3D Secure run inside the frame.

## Allowed websites

With a **live** key, the form shows only on the websites on your allowed list (Console, Checkout settings, the same list that allows your return URLs). On any other site the frame shows "This website can’t take payments for this business" and `mount` or `openOverlay` rejects with that message. A test key shows the form anywhere, including `localhost`, so you can build before you list your site. If you have not listed any website yet, a live form shows anywhere until you do.


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