> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skia.money/llms.txt
> Use this file to discover all available pages before exploring further.

# Invoice Lifecycle

> The full obligation lifecycle in raw REST: issue, acknowledge, dispute, credit note, partial payment intent, bind, commit, reveal, and the fold reads.

# 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 signed `InvoiceClaim`. The claim settles on the ACTIVE
chain (X Layer at ship — numeric `196`); anything else refuses with
`400 INVOICE_CHAIN_NOT_ACTIVE`.

```bash theme={null}
curl -s -X POST https://api.skia.money/v1/invoices \
  -H 'Authorization: Bearer 0x<issuer-address>' \
  -H 'Content-Type: application/json' \
  -d '{
    "claim": {
      "invoiceId": "INV-2026-001",
      "issuer": "0x<issuer-address>",
      "debtor": "0x<debtor-address>",
      "amount": "1000000000",
      "currency": "USDC",
      "settleChainId": 196,
      "issuedAt": 1793500000,
      "dueAt": 1794796000,
      "gracePeriodSeconds": 604800,
      "lateFeeBpsPerDay": 30,
      "feeBearer": "debtor",
      "memo": "Net-15 services, PO-8841",
      "externalRef": "PO-8841"
    },
    "issuerSignature": "0x<65-byte EIP-712 signature over the claim digest>"
  }'
```

Response `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.

```bash theme={null}
curl -s -X POST https://api.skia.money/v1/invoices/INV-2026-001/ack \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Content-Type: application/json' \
  -d '{
    "decision": "acknowledge",
    "debtorSignature": "0x<65-byte countersignature over the same claim digest>"
  }'
```

Returns the `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.

```bash theme={null}
curl -s -X POST https://api.skia.money/v1/invoices/INV-2026-001/dispute \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Content-Type: application/json' \
  -d '{
    "disputedAmount": "25000000",
    "reason": "Rate discrepancy on line 3",
    "debtorSignature": "0x<65-byte countersignature over the claim digest>"
  }'
```

The fold now carries `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 a `CreditNotice` — 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.

```bash theme={null}
curl -s -X POST https://api.skia.money/v1/invoices/INV-2026-001/credit-notes \
  -H 'Authorization: Bearer 0x<issuer-address>' \
  -H 'Content-Type: application/json' \
  -d '{
    "creditNotice": {
      "claimHash": "0x<the issued claim digest>",
      "creditId": "CN-001",
      "amount": "25000000",
      "issuedAt": 1793700000,
      "memo": "Rate correction for line 3"
    },
    "issuerSignature": "0x<65-byte EIP-712 CreditNotice signature>"
  }'
```

The fold view now shows `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 pinned `amount`. The key namespace is scoped per invoice.

```bash theme={null}
curl -s -X POST https://api.skia.money/v1/invoices/INV-2026-001/payments \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Idempotency-Key: pay-INV-2026-001-a1' \
  -H 'Content-Type: application/json' \
  -d '{
    "templateId": "swap-direct",
    "amount": "500000000"
  }'
```

Response `PaymentIntentResponse`:

* `attempt` — `status: "INTENT_CREATED"`, the attempt's pinned
  `intentAmount: "500000000"`, a **fresh nonce**, the attempt's
  `chainId` (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"`.

Replaying with the same key returns the SAME attempt. A key on a terminal
attempt replays that terminal record — the next attempt mints a NEW key.

## 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:

```bash theme={null}
curl -s -X POST \
  https://api.skia.money/v1/invoices/INV-2026-001/payments/<attemptId>/order \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Content-Type: application/json' \
  -d '{
    "nonce": "<the attempt fresh nonce>",
    "expiry": "<template expiry>",
    "signerWallet": "0x<debtor-address>",
    "signerToken": "0x<USDC on the settle chain>",
    "signerAmount": "500000001",
    "protocolFee": "<order-struct bps>",
    "senderWallet": "0x<issuer-address>",
    "senderToken": "0x<USDC on the settle chain>",
    "senderAmount": "1",
    "signature": "0x<65-byte debtor signature over the exact fields>",
    "signatureType": 0
  }'
```

Attempt moves to `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 is `attemptId`, which binds the commit to the attempt:

```bash theme={null}
curl -s -X POST https://api.skia.money/api/commit \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Idempotency-Key: commit-INV-2026-001-a1' \
  -H 'Content-Type: application/json' \
  -d '{ ...the bound Order preimage fields..., "attemptId": "<attemptId>" }'
```

then

```bash theme={null}
curl -s -X POST https://api.skia.money/api/reveal \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Content-Type: application/json' \
  -d '{ ...the full signed Order..., "attemptId": "<attemptId>" }'
```

The reveal's Swap event is the receipt; the attempt becomes `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 **without** `amount` targets the full remaining outstanding:

```bash theme={null}
curl -s -X POST https://api.skia.money/v1/invoices/INV-2026-001/payments \
  -H 'Authorization: Bearer 0x<debtor-address>' \
  -H 'Idempotency-Key: pay-INV-2026-001-a2' \
  -H 'Content-Type: application/json' \
  -d '{ "templateId": "swap-direct" }'
```

Bind + commit + reveal again → `outstanding: "0"`, fold status **SETTLED**.

## 9. Read the book

```bash theme={null}
# One invoice — the pure fold view (issuer or debtor only)
curl -s https://api.skia.money/v1/invoices/INV-2026-001/receivable \
  -H 'Authorization: Bearer 0x<issuer-address>'

# The calling party's book, cursor-paginated
curl -s 'https://api.skia.money/v1/receivables?role=issuer&limit=50' \
  -H 'Authorization: Bearer 0x<issuer-address>'
```

> [!NOTE]
>
> 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)](https://docs.skia.money/examples/agent-session.md).
* The laws this example exercises: [Invoices](https://docs.skia.money/concepts/invoices.md) and
  [Settlements](https://docs.skia.money/concepts/settlements.md).
* Exact schemas: the generated API Reference pages for the `Invoice` tag.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.