# Quotes and signup

> Quote a plan, submit an order once, and follow the contract events using the original order reference.


A shop needs the price to show before the customer signs, one safe way to hand the
sale over, and a way to recognise what happens to it afterwards: `GET /quote`,
`POST /signups` and the `orderref` on every event.

## 1. Quote: the price is the bill

```sh
curl -sS "https://billd.example/quote?plan=example-fibre@2026-11/glasfaser-1000&start=2026-12-05" \
  -H "Authorization: Bearer $SHOP_KEY"
```

```json
{
  "plan": "example-fibre@2026-11/glasfaser-1000",
  "name": "Glasfaser 1000",
  "start": "2026-12-05",
  "first": { "period": "2026-12", "gross": "96.10", "lines": [
    { "label": "Bereitstellung", "amount": "69.99", "why": ["Einmalig „Bereitstellung“ zum Vertragsbeginn am 05.12.2026. Preisbuch 2026-11."] }, "…"
  ] },
  "next": { "period": "2027-01", "gross": "29.97", "lines": ["…"] },
  "steps": [ { "from": "2027-01", "gross": "29.97" }, { "from": "2027-03", "gross": "59.97" } ],
  "sentence": "Erste Rechnung 96,10 €, danach 29,97 € im Monat, ab März 2027 59,97 €."
}
```

- **A plan has an address:** `book@version/plan`. The version is pinned, so the quote
  you show today is the price the contract is billed at, even after the book gets a later version.
- **The same function that bills.** The quote composes the first bill — the month service
  begins, from the start day, with one-off charges — and every month after it, each
  corrected against the one before, exactly as the seals will. `steps` follows the
  monthly price until it settles (36 months at most), so a promotion that ends is named,
  not hidden. The start must leave room for a following calendar month.
- **Show `sentence` verbatim.** It is German and complete. Every line also carries its
  „Warum?" sentences, for a price breakdown.
- Usage (calls outside the flat rate) is not included. Any key may quote, a `read` key
  too. Nothing is stored.

The same answer comes from the terminal and from agents:

```sh
telco price quote pricebooks/example-fibre --plan glasfaser-1000 --start 2026-12-05
```

and from billd's MCP tool `quote_plan`.

## 2. Sign up: one call per order

```sh
curl -sS https://contractd.example/signups -H "Authorization: Bearer $SHOP_KEY" \
  -H "Content-Type: application/json" -d @order.json
```

```json
{
  "order_reference": "SHOP-2026-0042",
  "concluded_on": "2026-11-20",
  "withdrawal_deadline": "2026-12-04",
  "evidence_digest": "sha256:9f2c…",
  "customer": { "name": "Erika Mustermann", "street": "Hauptstr. 1", "postcode": "12345",
                "city": "Musterstadt", "consumer": true, "salutation": "sie" },
  "account": { "invoice_email": "erika@example.org" },
  "contract": { "start": "2026-12-01", "initial_months": 24, "notice_months": 1, "renews": true,
                "summary_before_conclusion": false, "approved_on": "2026-11-20" },
  "subscriptions": [ { "product": "Glasfaser 1000", "plan": "example-fibre@2026-11/glasfaser-1000" } ]
}
```

`201` answers what was made:

```json
{
  "order_reference": "SHOP-2026-0042",
  "probe": false,
  "customer": { "id": "…" },
  "billing_account": { "id": "…", "number": "KD-000042" },
  "contract": { "id": "…", "state": "effective", "start": "2026-12-01",
                "initial_term_end": "2028-11-30", "last_day_to_cancel": "2028-10-31",
                "withdrawal_deadline": "2026-12-04" },
  "subscriptions": [ { "id": "…", "plan": "example-fibre@2026-11/glasfaser-1000", "state": "ordered" } ],
  "request_digest": "sha256:…"
}
```

- **All or nothing.** Customer, billing account, contract and subscriptions are made in
  one transaction. When any part is refused, nothing is kept.
- **Safe to retry.** The same `order_reference` with the same request answers the first
  answer again (`200`, `Idempotent-Replayed: true`). The same reference with another
  request is `409 signup.conflict`, and nothing of the first sale is revealed. Two
  identical requests at once: one is taken, the other answers it.
- **A refusal names the field.** The problem carries a JSON `pointer` into your request
  (`/account`, `/subscriptions/0/plan`, `/order_reference`) beside its `code`,
  `detail` and `fix`. For a wrong JSON type the pointer identifies its location. An empty pointer identifies the request body as a whole.
- **What the seller knows, carried.** `concluded_on`, `withdrawal_deadline` (§ 356 BGB, as
  you computed it — never recomputed) and `evidence_digest` stay on the contract.
  `approved_on` records the § 54 Abs. 3 TKG approval of the contract summary when you
  already have it; without it the contract waits for it.
- **A probe.** `"probe": true` is answered exactly as a real signup and leaves nothing
  behind — no row, no event, no letter. Use it to test your mapping against production.
- The order reference is 1–64 characters of `A–Z a–z 0–9 . _ : / -`. It travels on
  every event, so it must not be personal data: no e-mail address, no name.

## 3. Recognise what happens

Every event of a contract that came through the signup — the customer's and the
account's included — carries the order as the CloudEvents extension `orderref`:

```json
{ "type": "de.telco.subscription.activated", "subject": "subscription/…",
  "orderref": "SHOP-2026-0042", "data": { "id": "…", "state": "active" }, "…": "…" }
```

Register a [webhook](../docs/webhooks/) for `contract,subscription` and match on
`orderref` — no lookup, no mapping table.

The signup records the plan reference. billd calculates charges from that version of the price book.
