# Show a checkout list

List your store's agent checkouts for your staff inside your own admin tool with <provenance-checkout-list>, with tabs, filters, a sort and paging, and open the selected order in its own panel.

`<provenance-checkout-list>` lists your store's agent checkouts (each [checkout assessment](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md)) for your staff, inside your own admin tool, newest first. Each row is one line: the status with a dot, the order reference, the total, what became of the cart approval and the time. Your staff filter it, search it by order, sort it and page through it; a selected row opens in a panel beside the rows.

**Before you begin:** a publishable key (see [embeds](https://provenanceauth.com/docs/embeds.md#1-create-a-publishable-key)) and a secret key with the `authorize` scope. The embed needs Pro or the Free trial in live, and works on any plan in sandbox; the same status words show on the console's **Checkout** page on every plan.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
```

## 1. Mint a list session on your server

Your server mints a short session for the list with [`POST /v1/embed/tokens`](https://provenanceauth.com/docs/api/embeds.md#post-v1-embed-tokens) and `widget: "checkout_list"`. A list takes no `object_id`: it's scoped to your account. Put it behind a route your admin page calls, after your own sign-in check:

In the SDK tabs, `prov` (Node, Python) and `embed` (Go) are your server-side clients, set up as in [admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md#3-mint-a-session-for-an-embed).

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/embed/tokens \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "widget": "checkout_list", "filters": { "outcome": "in_review" }, "ttl": 900 }'
```

**Node**

```ts
// GET /admin/provenance/session?widget=checkout_list (your route, behind your staff sign-in)
const session = await prov.embed.createToken({ widget: "checkout_list", filters: { outcome: "in_review" }, ttl: 900 });
res.json({ token: session.embedToken });
```

**Python**

```python
token = prov.embed.create_token(widget="checkout_list", filters={"outcome": "in_review"}, ttl=900)["embed_token"]
```

**Go**

```go
session, err := embed.CreateToken(ctx, pv.EmbedTokenParams{
	Widget:  pv.WidgetCheckoutList,
	Filters: &pv.CheckoutListFilters{Outcome: "in_review"},
	TTL:     900,
})
```

| Field | What it does |
| --- | --- |
| `filters` | Optional. Filters the session always applies, which the browser can't change: `outcome` (`frictionless`, `challenge`, `reject`, or `in_review` for orders waiting for your review), `approval_status`, `order_id`, `created_gte`, `created_lte`. Pin `outcome: "in_review"` for a review queue. |
| `ttl` | Seconds, up to 900 (15 minutes). |

The order reference always shows, so a checkout list takes no `show`. A key without the `authorize` scope gets `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope). A filter that isn't one of the list's, or a value it doesn't take, is `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid).

## 2. Drop the list in your page

```bash
npm install @provenance/embed
```

```html
<script type="module" src="https://unpkg.com/@provenance/embed"></script>

<provenance-checkout-list id="orders" base-url="https://sandbox-api.provenanceauth.com" publishable-key="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  filters="outcome,order,created" page-size="25"></provenance-checkout-list>

<script>
  const list = document.querySelector("provenance-checkout-list");
  // No context: the list's own session. { objectId, widget }: the session for the row its panel opens.
  list.getToken = async ({ objectId, widget } = {}) => {
    const q = objectId ? `widget=${widget}&id=${objectId}` : "widget=checkout_list";
    return (await (await fetch(`/admin/provenance/session?${q}`)).json()).token;
  };
</script>
```

A selected row opens in the list's own panel: beside the rows on a column 600 px or wider, with the order's reference, **Previous**, **Next** and **Close**; narrower, as the whole element with **Back**. One "Powered by Provenance" sits under both.

The panel asks the list's `getToken({ objectId, widget: "checkout_result" })` for the order's ID (`cas_…`), and your server mints a `checkout_result` session for exactly that order, so the list never widens what it can read.

| Attribute | What it does |
| --- | --- |
| `filters` | The filters shown, from `outcome` (Approved, Challenged, Rejected, In review), `order` (a search on the order reference) and `created` (Any time, Today, Last 7 days, Last 30 days). `outcome,created` when absent. A pinned filter has no tab, chip or menu entry. |
| `sort` | The order on load, one of **Newest first** (`-created`), **Oldest first** (`created`), **Largest total** (`-amount`) or **Smallest total** (`amount`). Newest first when absent. |
| `sorts` | The orders the sort button offers, a comma list (for example `-created,-amount`). All of them when absent. |
| `detail` | `panel` (the default) opens a selected row in the list's own panel. `none` only emits `pv:select`. |
| `page-size` | Rows per page, 10 to 100. 25 when absent. |
| `select-first` | Select the first row on load (with the panel, it opens on that row). |
| `hide-suffix` | Text your server adds to the end of each order reference, such as a tenant's tag. Rows and the panel show the reference without it. The search and a pinned `order_id` still match the whole reference. |

Above the rows: tabs for `outcome` (All, Challenged, In review and Rejected), a **Filter** chip for the other filters you show, a chip for each filter in use (its button removes it) and a sort button that names the current order.

Under the rows, the range ("1–25") and **Newer** and **Older** page by cursor, with no page numbers or totals. The filters, the sort and the page stay inside the element; to keep them in your page's address, listen for `pv:list_change`.

To show the order somewhere else on your page, set `detail="none"` and either handle `pv:select` yourself or put a `<provenance-checkout-result for="orders">` beside it (a list that a result element follows never opens its own panel):

```js
list.addEventListener("pv:select", (e) => {
  const { kind, id } = e.detail; // kind: "checkout", id: "cas_…"
  openOrder(id);
});
```

In React:

```tsx
import { ProvenanceCheckoutList } from "@provenance/embed/react";

<ProvenanceCheckoutList
  id="orders"
  baseUrl={process.env.NEXT_PUBLIC_PROVENANCE_API!}
  publishableKey="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  filters={["outcome", "order", "created"]}
  sort="-amount"
  getToken={async ({ objectId, widget } = {}) => {
    const q = objectId ? `widget=${widget}&id=${objectId}` : "widget=checkout_list";
    return (await (await fetch(`/admin/provenance/session?${q}`)).json()).token;
  }}
/>;
```

## What it shows

Each row, and where it comes from in [`GET /v1/authorize/checkout_assessments`](https://provenanceauth.com/docs/api/assessments.md#get-v1-authorize-checkout-assessments):

| Part | Example | From |
| --- | --- | --- |
| Status | The order's one status: Approved, Challenged, Rejected, In review or Expired | The cart approval's `status` once a shopper was asked, else `outcome` (see [order status](https://provenanceauth.com/docs/embeds/checkout-result.md#order-status)) |
| Order | 1042 | `order_id` |
| Total | The cart total, in its currency | The cart's `total` and `currency` |
| Detail | Shopper approved, or the rule that decided | The cart approval's `status`, else `policy.rule.name`, else `reason` |
| Time | 1:23 pm today, Nov 14 before | `created_at` |

The list's filters are the API list's own, the ones a session can pin (step 1); the order search matches any part of the reference, in any case. The element never gets the cart's lines, the binding, the approver, the billing address or the IP. To see what it gets, call `GET /v1/embed/checkout_list` with the session.

## Events

| Event | When | Detail |
| --- | --- | --- |
| `pv:ready` | The session opened | `widget`, `object_id`, `mode` |
| `pv:select` | A row was selected (click, Enter or Space) | `kind: "checkout"`, `id` |
| `pv:list_change` | The filters, the sort or the page changed | `filters`, `cursor`, `sort` |
| `pv:token_refresh_failed` | `getToken()` couldn't renew the session | `widget` |
| `pv:error` | The element couldn't start or read a page | `code`, `message` |

## Embed, console or your own

|  | This embed | The console | Your own UI on the API |
| --- | --- | --- | --- |
| Where | Your admin tool | **Authorize › Checkout** | Anywhere you like |
| Plan | Pro, or the Free trial; any plan in sandbox | Every plan | Every plan |
| Work | Mint two kinds of session, drop one tag | None | Page the list, map the words, read each approval |

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `400` [`embed_filter_pinned`](https://provenanceauth.com/docs/platform/errors.md#embed_filter_pinned) | The page asked for another value of a pinned filter | Leave it out; the session applies it. |
| `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid) on `sort` or `cursor` | A `sort` the list doesn't take, or a cursor made in another order | Use an order from the `sort` row above; start again without the cursor. |
| `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope) | The key has no `authorize` scope | Mint with an Authorize key. |
| `401` [`embed_token_invalid`](https://provenanceauth.com/docs/platform/errors.md#embed_token_invalid) | The session expired or is for another widget | Mint a new one, or give the element `getToken()`. |
| `503` [`embed_result_unavailable`](https://provenanceauth.com/docs/platform/errors.md#embed_result_unavailable) | The list couldn't be read | Retry shortly. |

## See also

- [Embeds](https://provenanceauth.com/docs/embeds.md)
- [Checkout result in your admin](https://provenanceauth.com/docs/embeds/checkout-result.md)
- [Capture list in your admin](https://provenanceauth.com/docs/embeds/capture-list.md)
- [Admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md)
