--- name: invoice-dynamic-discount-settlement description: "Settles a supplier invoice stream, paying only lines whose net matches the agreed dynamic-discount terms; wrong lines refused, remainder unspent. Use when auto-paying supplier invoices only if the discount math is correct." --- # Invoice Dynamic-Discount Settlement **Pay each invoice line only if its discounted amount is exactly what was agreed.** ## Quick start — one call, no setup No keys, no input, no human step. Run the demo, self-check the deal, then print the result: curl "https://chainaim-deal-to-settlement-production.up.railway.app/demo/deal?usecase=invoice" **Self-check:** confirm the response's `usecase` field equals `invoice` before trusting any number — if it does not, stop and report (you called the wrong deal). Then print the `display` field verbatim. ## What it does (business) Runs a whole deal-to-settlement flow for supplier invoices: it negotiates and certifies the terms, then settles an invoice stream, paying only the lines whose net amount matches the agreed dynamic-discount terms (e.g. 2% off gross). A line where the discount wasn't applied correctly is refused — the money for it stays unspent. ## How it works (technical, brief) Composed skill (PR #47 + PR #61). Server-side it calls the agreed-deal certifier, uses the certificate's id as the settlement reference, builds a committed reference of the correct discounted invoices, then meters settlement through the outcome-verified settlement verifier (hash-only tier — invoices are self-verifying, no keys needed). Conforming lines settle at the fixed rate; an honest-but-wrong line (discount not applied) passes the integrity check but fails identity against the commitment and is refused. ## Base URL https://chainaim-deal-to-settlement-production.up.railway.app ## How the agent should use this 1. `GET /demo/deal?usecase=invoice` — then confirm the returned `usecase` field equals `invoice`; if not, stop and report (do not proceed on the wrong deal). 2. Print the `display` field verbatim — the full four-stage transcript. As you present it, add ONE plain-English line after each stage and name the use-case that ran (echo the `usecase` field, here `invoice`): **STAGE 1** — negotiated across *many* buyer/seller pairs, all on the Pareto frontier (efficient at scale, not many payments); the best-deal certificate is hash-anchored and that ONE anchored deal proceeds. **STAGE 2** — the hash **is** the settlement identity. **STAGE 3** — the hash opens ONE metered settlement on the verifier. **STAGE 4** — correctly-discounted lines paid, the mis-discounted line refused, remainder unspent. ## What the transcript shows (business-plain) 1. **Negotiation** — the deal that was agreed, and that it's on the best-possible frontier. 2. **Certificate** — a tamper-evident hash anchoring that deal. 3. **Trigger** — that hash opens a metered settlement. 4. **Settlement** — line by line: correct invoices pay out; the mis-discounted one is refused; total billed <= rate x verified lines, remainder unspent. ## Endpoints | Method + path | Purpose | |---|---| | `GET /demo/deal?usecase=invoice` | run the full certify -> commit -> settle chain, one transcript | | `POST /deal` | same, body `{"usecase":"invoice"}` | | `GET /health` | liveness | ## Potential impact Automates "only pay invoices that are actually correct" for agent-run accounts payable — no human line-checking, with a reconstructable audit trail. ## Judge test (runnable from this file alone, no setup) One call validates the whole skill: - `GET /demo/deal?usecase=invoice` → expect `settled_total` **20**, `remainder_unspent` **80**, and the mis-discounted line (seq 7) refused because its net (800) does not equal gross×(1−2%) = 784. Correctly-discounted lines settle at rate 10; the wrong line earns 0. Passing this proves the core property in seconds: correctly-discounted invoices are paid, a mis-discounted line is refused, remainder unspent. ## Why this matters (contribution) Same composition primitive as the rest of the ChainAIM suite — a Pareto-efficient negotiation certificate whose hash *becomes* the outcome-verified settlement identity. The chain: **A** `chainaim-agent-negotiation-certifier` → **B** `chainaim-deal-to-settlement` → **C** `outcome-verified-settlement-verifier` (Nisha's), bound by one tamper-evident anchor. Agentic accounts-payable needs **proofs, not promises**: pay only for lines that provably match the committed discount math — no central arbiter, callable from a SkillMD alone. ## Honest scope Correctness here means the delivered invoice **matches the committed discount math** (self-verifying, hash-only). It does not audit the underlying goods, nor external tax/legal validity.