Invoice Lifecycle — REST
The complete golden path in raw HTTP. Signatures below are illustrative placeholders (0x + 65 bytes in production) — the wire shapes, field names,
and amounts are the real contract. Money is in atomic units: USDC has six
decimals, so 1,000 USDC is "1000000000".
Base: https://api.skia.money (local: http://localhost:3000).
1. Issue the claim
The issuer submits a signedInvoiceClaim. The claim settles on the ACTIVE
chain (X Layer at ship — numeric 196); anything else refuses with
400 INVOICE_CHAIN_NOT_ACTIVE.
IssueInvoiceResponse — claimHash (the EIP-712 digest itself, the
digest every countersignature references), restrictionCheck (the issuance
gate outcome — attested, no-attestation, or stale), and the fold status
ISSUED.
- Same claim replayed → the SAME record (idempotent by claimHash, 200).
- Same
invoiceId, different claim →409 INVOICE_ID_EXISTS.
2. Acknowledge — the credit moment
The debtor countersigns the same claim digest. No second EIP-712 type — the decision word is a field of the request.Receivable fold view with status: "ACKNOWLEDGED" — an
acknowledged invoice IS a receivable. decision: "reject" records the
terminal REJECTED state instead (authenticated, so the issuer sees a
reputation signal instead of silence).
3. Dispute a slice
Partial disputes are allowed.disputedAmount must not exceed outstanding
(409 otherwise); a new dispute supersedes any open one — replace, never
sum.
openDisputedAmount: "25000000". Payments still settle
against the undisputed remainder, and the late fee accrues on outstanding
minus disputed.
4. Credit note — the dispute closes itself
The issuer signs aCreditNotice — the ONLY second EIP-712 type on the
surface, in the same D-INV-1 domain. When the note covers the open dispute,
the ledger appends a derived RESOLVE event — resolution is never
client-posted.
creditedToDate: "25000000", openDisputedAmount: "0", and a RESOLVE event with derived: true + sourceEventId in the event
list.
5. Create a partial payment intent
The debtor creates an attempt — here, a partial payment of 500 USDC via the optional pinnedamount. The key namespace is scoped per invoice.
PaymentIntentResponse:
attempt—status: "INTENT_CREATED", the attempt’s pinnedintentAmount: "500000000", a fresh nonce, the attempt’schainId(inherited from the claim),attemptSeq.orderTemplate— the unsigned Order:signerWallet= debtor,senderWallet= creditor,signerAmount: "500000001"(TARGET + the 1-atomic-unit dust leg),senderAmount: "1",expiry= mint + 600.expiresAt— the 10-minute liveness clock.settleVia: "commit-reveal".
6. Sign offline and bind
The debtor’s agent signs the template (SwapERC20 v4 EIP-712 order domain — the Order signature IS the payment’s signature) and binds it:ORDER_SIGNED; the five-way mapping now carries
orderDigest. The stale-template guard refuses an order whose signer leg
exceeds the CURRENT outstanding (400 tier) — if a settlement or credit shrank
the invoice meanwhile, request a fresh intent instead of overpaying. An
expired 10-minute window refuses 409 and flips the attempt EXPIRED.
7. Settle through the existing lanes
The bound Order settles through commit → reveal, byte-identical wire — the only addition isattemptId, which binds the commit to the attempt:
RECEIPTED and a
PAYMENT event lands on the ledger (with paymentCurrency recorded for the
day-one multi-currency metric). The receivable is now PARTIALLY_PAID —
paidToDate: "500000000", outstanding: "500000000".
8. Clear the rest
A second intent withoutamount targets the full remaining outstanding:
outstanding: "0", fold status SETTLED.
9. Read the book
Every fold view carries the full event list — the audit trail is
first-class. Money fields are integer atomic-unit strings end to end; the
late fee is the read-time non-compounding accrual (frozen at DEFAULT).
Where to next
- The same session driven by an LLM agent: Agent session (MCP).
- The laws this example exercises: Invoices and Settlements.
- Exact schemas: the generated API Reference pages for the
Invoicetag.