# Approved terms (intent binding)

The customer approves exact terms, not a general wish. The agent binds those terms to a hash. The shop re-quotes at checkout. If a material term changed, the approval is void, no handoff is issued, and the customer sees a diff.

## The gap this closes

An agent may pick the right product, and then price, availability, shipping terms or the merchant change before checkout. The checkout handoff confirms a payment. It does not by itself prove that the customer approved what is about to be charged. Intent binding keeps the customer's original intent intact from the first proposal to the payment.

Added in `1.1.0-draft`. The fields are optional. A shop that does not advertise `terms.binding` in its discovery document behaves as in 1.0.0, and an agent must not assume binding there.

## Terms snapshot

The snapshot is one JSON object. It holds every term the customer approves. Amounts are decimal strings, never floating point numbers. Times are RFC 3339 in UTC. Schema: [`/schemas/terms-snapshot.schema.json`](https://agenthandelstandard.se/schemas/terms-snapshot.schema.json).

| Field | Meaning |
|---|---|
| `quote_id` | The shop's identifier for the quote. |
| `merchant` | `id`, `name` and `origin` of the merchant of record. |
| `items[]` | `id`, `name`, `qty`, `unit_price`, `line_total`, `availability` (`in_stock`, `backorder`, `made_to_order`) and optional `available_from`. |
| `currency` | ISO 4217 code. One currency for the whole snapshot. |
| `subtotal`, `total` | Items before shipping, and the amount the customer pays. |
| `taxes[]` | `type`, `rate`, `amount` and `included`. |
| `shipping` | `method`, `carrier`, `cost`, `eta_date` and a `destination` with country and an optional postcode area. |
| `valid_from`, `valid_until` | The validity window of the quote. |
| `tolerance` | Optional. How much change the customer allows. See below. Missing means zero. |

## Hash and signature

- `terms_hash` is `sha256:` followed by the hex SHA-256 of the snapshot in canonical JSON (RFC 8785). Any change to any term gives another hash.
- A shop may sign its quote. The signature is a detached JWS (RFC 7515, RFC 7797) over the hash, in `quote_signature`, with a key from the shop's published JWKS. A shop that signs is advertised as `signed_quotes: true` in discovery.
- The shop may return a ready snapshot and hash with its quote. The agent must not edit it. If the agent builds the snapshot itself, it must copy the values from the shop's own quote.
- The customer's approval, and later any approver's approval, is bound to the hash. See [approval evidence](https://agenthandelstandard.se/authority/#approval).

## Flow

1. The agent collects items and gets a shipping quote.
2. The agent builds the snapshot and its `terms_hash`.
3. The customer is shown exactly those terms and approves them. The approval is bound to the hash.
4. The agent calls `POST /checkout/prepare` with `approved_terms`.
5. The shop re-quotes the same items and compares the result with the snapshot.
6. If the terms match, or any change is inside the tolerance, the shop issues the handoff URL. If not, it answers 409 `terms_changed` and issues nothing.

## Re-quote at checkout

A shop that advertises `terms.binding` must re-quote on every `/checkout/prepare` that carries `approved_terms`. It must not trust the submitted prices. It compares the live quote with the snapshot term by term.

| Result | HTTP | What the shop does |
|---|---|---|
| Match | 200 | Issues the handoff. Returns `terms_check.status: "match"` and the hash. |
| Changed, inside tolerance | 200 | Issues the handoff. Returns `terms_check.status: "within_tolerance"` and the list of changes. The amount charged never exceeds the approved total plus the tolerance. |
| Material change | 409 | Returns `terms_changed` with the diff and the current terms. No handoff URL. |
| Quote expired | 409 | Same as a material change. The code is `terms_changed` and the diff names `valid_until`. |
| No `approved_terms` sent | 200 | The shop behaves as in 1.0.0. It must not claim the terms were checked. |

## What counts as a material change

| Term | A change is material when | Default tolerance |
|---|---|---|
| Unit price, line total, subtotal | The price goes up beyond the allowance. | Zero for increases |
| Taxes | The tax amount goes up, or `included` flips. | Inside `total_increase_max` |
| Shipping cost | The cost goes up beyond the allowance. | Zero |
| Shipping method, carrier, ETA | The method or carrier changes, or the ETA is later than allowed. | Zero days |
| Availability | An item becomes backorder, made to order, later or unavailable. | None |
| Total | The total goes up beyond `total_increase_max`. | Zero |
| Merchant, item, quantity, currency | Any change. Never tolerated. | None |
| Validity window | `valid_until` has passed. | None |

A price decrease is not material. The shop shows it as a change, and charges the lower amount.

## Tolerance policy

Tolerance is a policy field inside the snapshot, so it is covered by the hash and a shop cannot loosen it. A shop may be stricter. The default is zero for price increases.

```json
{
  "price_increase_max_percent": "0",
  "price_increase_max_amount": "0.00",
  "shipping_cost_increase_max": "0.00",
  "eta_delay_max_days": 0,
  "total_increase_max": "0.00"
}
```

A change is inside the tolerance only if every changed term is inside its own allowance and the total increase is not above `total_increase_max`. The principal sets the tolerance. An agent must not raise it on its own.

## The diff

Each entry names a `path` in the snapshot, the `approved` value, the `current` value, the kind of `change` (`increase`, `decrease`, `changed`, `unavailable`, `added`, `removed`) and whether it is `material`. The customer must be shown this diff in plain words, next to the approved and the current total.

## Customer confirmation

The confirmation screen is where the customer approves. It must show exactly the bound terms:

- Merchant, every item with quantity and unit price, taxes, shipping method, cost and ETA, total and currency.
- The validity time left, and the first 8 characters of the `terms_hash` so that the customer can compare them with what the agent reported.
- No price, discount or line that is not in the snapshot. If the live terms differ, the screen shows the diff and asks again.
- An agent's own summary never replaces this screen. If the agent shows the terms before checkout, it must render the snapshot fields, not a paraphrase.

## Validity window

A snapshot is valid between `valid_from` and `valid_until`. A shop publishes `max_validity_seconds` in discovery. The suggested value is 900. After that the shop must re-quote and the customer must approve again.

## Error bodies

Schema: [`/schemas/checkout-outcomes.schema.json`](https://agenthandelstandard.se/schemas/checkout-outcomes.schema.json). Example of a 409 after the unit price rose from 1290.00 to 1390.00:

```json
{
  "code": "terms_changed",
  "approved_terms_hash": "sha256:8042bb8bd734bf15b1437a5630335263b0f6494700f4d92ef461049c1235f1fb",
  "current_terms_hash": "sha256:04a669ab1d22ffccdd4bc5e6e2a4b997a72b38c8a7ab46b45f4ed627a435af7b",
  "within_tolerance": false,
  "reconfirm_required": true,
  "diff": [
    {
      "path": "items[0].unit_price",
      "approved": "1290.00",
      "current": "1390.00",
      "change": "increase",
      "material": true
    },
    {
      "path": "total",
      "approved": "1349.00",
      "current": "1449.00",
      "change": "increase",
      "material": true
    }
  ],
  "current_terms": "<the current terms snapshot>"
}
```

## Example snapshot

The hash below is the SHA-256 of this snapshot in canonical JSON, so an implementation can test itself against it.

```json
{
  "sacp_terms_version": "1.1",
  "quote_id": "q_8f3a2c71",
  "merchant": {
    "id": "shop.example.se",
    "name": "Example Shop AB",
    "origin": "https://shop.example.se"
  },
  "items": [
    {
      "id": "sku-1042",
      "name": "Trail running shoes, size 43",
      "qty": 1,
      "unit_price": "1290.00",
      "line_total": "1290.00",
      "availability": "in_stock"
    }
  ],
  "currency": "SEK",
  "subtotal": "1290.00",
  "taxes": [
    {
      "type": "vat",
      "rate": "0.25",
      "amount": "269.80",
      "included": true
    }
  ],
  "shipping": {
    "method": "home-delivery",
    "carrier": "Example Carrier",
    "cost": "59.00",
    "eta_date": "2026-12-09",
    "destination": {
      "country": "SE"
    }
  },
  "total": "1349.00",
  "valid_from": "2026-12-04T09:00:00Z",
  "valid_until": "2026-12-04T09:15:00Z",
  "tolerance": {
    "price_increase_max_percent": "0",
    "price_increase_max_amount": "0.00",
    "shipping_cost_increase_max": "0.00",
    "eta_delay_max_days": 0,
    "total_increase_max": "0.00"
  }
}
```

`terms_hash`: `sha256:8042bb8bd734bf15b1437a5630335263b0f6494700f4d92ef461049c1235f1fb`

Request to `POST /checkout/prepare`:

```json
{
  "items": [
    {
      "id": "sku-1042",
      "qty": 1
    }
  ],
  "payment_handoff": "swish",
  "approved_terms": {
    "snapshot": "<the terms snapshot object>",
    "terms_hash": "sha256:8042bb8bd734bf15b1437a5630335263b0f6494700f4d92ef461049c1235f1fb",
    "quote_signature": "<optional detached JWS from the shop>"
  },
  "authority": {
    "mandate": "<compact JWS of the mandate>",
    "approvals": [
      "<compact JWS of each approval>"
    ]
  }
}
```

## Conformance

- A shop that advertises `terms.binding` must re-quote, compare every material term, apply the tolerance, answer 409 `terms_changed` with a diff, and never issue a handoff for changed terms.
- It must store the approved snapshot and hash with the order.
- The confirmation screen must show the bound terms as described above.
- An agent must send the snapshot it showed the customer, unchanged, and must not retry with edited terms without a new approval.

## Questions

### What if the price changes before checkout?

The approval is void. The shop re-quotes at checkout and compares the result with the approved terms. Under the default tolerance of zero, any price increase returns 409 terms_changed with a diff and issues no handoff URL. The customer must approve the new terms.

### What are approved terms in SACP?

Approved terms are a snapshot of the exact offer the customer approved: merchant, items, quantity, unit price, taxes, shipping method, cost and ETA, total, currency and validity window. The agent hashes it with SHA-256 over canonical JSON, and the shop checks that hash again at checkout.

### How does the customer verify what they are approving?

The confirmation screen must show exactly the bound terms, plus a short form of the terms hash and the expiry time. If anything differs from what was approved, the screen shows a diff and asks again. An agent's summary never replaces that screen.

### Can a customer allow small price changes?

Yes, through the tolerance policy inside the snapshot. The default is zero for price increases. The principal may set a maximum percent, amount or total increase. A change of merchant, item, quantity or currency is never tolerated.
