# Chargeback protection

Show your store's Chargeback protection view to your staff inside your own admin tool with <provenance-chargeback-protection>, read only.

`<provenance-chargeback-protection>` shows your store's [Chargeback protection](https://provenanceauth.com/docs/authorize/guides/chargeback-responses.md#7-chargeback-protection) view to your staff inside your own admin tool, read only. It shows the same records and words as **Authorize › Chargeback protection** in the console: "Protection used, $X of $Y" over the last 6 months with a meter, orders protected, disputed and proof sent, and the tabs **Protected**, **Disputed** and **Not protected**. Each order is one line: its status, the order, why it is or isn't protected, the amount and the date.

If your account has no program, the element says "Chargeback protection isn't on for this account." and opens on **Not protected**. That tab lists your own agent orders that would not qualify, with why. It never shows sample 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.

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

## 1. Mint a session on your server

Your server mints a short session with [`POST /v1/embed/tokens`](https://provenanceauth.com/docs/api/embeds.md#post-v1-embed-tokens) and `widget: "chargeback_protection"`. The session is scoped to your account, so it needs nothing else. Put it behind a route your admin page calls, after your own sign-in check:

**curl**

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

**Node**

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

**Python**

```python
token = prov.embed.create_token(widget="chargeback_protection", ttl=900)["embed_token"]
```

A key without the `authorize` scope gets `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope).

## 2. Drop the element in your page

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

<provenance-chargeback-protection base-url="https://sandbox-api.provenanceauth.com" publishable-key="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  docs-url="https://provenanceauth.com/docs"></provenance-chargeback-protection>

<script>
  const view = document.querySelector("provenance-chargeback-protection");
  view.getToken = async () => (await (await fetch("/admin/provenance/session?widget=chargeback_protection")).json()).token;
</script>
```

| Attribute | What it does |
| --- | --- |
| `docs-url` | Optional. The Provenance docs address for the empty state's link, `https://provenanceauth.com/docs`. Without it, the empty state has no link. |

The tabs answer clicks and the arrow keys. The element emits `pv:ready` and, after each read, `pv:result` with `{ kind: "chargeback_protection", on, tab }`.

## What it shows

The element reads `GET /v1/embed/chargeback_protection`: the summary of [`GET /v1/authorize/chargeback_protection`](https://provenanceauth.com/docs/api/chargebacks.md#get-v1-authorize-chargeback-protection) without the program IDs, and one tab of [`GET /v1/authorize/chargeback_protection/orders`](https://provenanceauth.com/docs/api/chargebacks.md#get-v1-authorize-chargeback-protection-orders).

| Part | From |
| --- | --- |
| Protection used, $X of $Y | `protection_used` and `protection_limit` over `window_days` (180) |
| Orders protected, Disputed, Proof sent | `counts` and `proof` |
| Each order's status | `status`: Protected, Disputed (a decided one reads Disputed › Won or Disputed › Lost), Not protected, Proof sent |
| Why | `why`, in words: for example "Approved with a passkey", "Over the order limit" or, with no program, "No passkey approval on the order" |

The element states your program's records only. It doesn't promise a payout, and the program's terms aren't published yet.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `401` [`embed_token_invalid`](https://provenanceauth.com/docs/platform/errors.md#embed_token_invalid) | The session expired, or it isn't a `chargeback_protection` session for this account | Return a fresh token from `getToken`. |
| `503` [`embed_result_unavailable`](https://provenanceauth.com/docs/platform/errors.md#embed_result_unavailable) | The records couldn't be read | The element shows nothing in their place. Retry shortly. |

## See also

- [Chargeback responses](https://provenanceauth.com/docs/authorize/guides/chargeback-responses.md#7-chargeback-protection): the view in the console.
- [Admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md): sessions, events and styling for every admin element.
