Topolo Docs Topolo Platform
Open workspace

Record a payment

Record money received against an invoice. Any open online checkout is expired before the balance changes, and the document becomes paid once its receipts cover it.

Outcome

Record money received against an invoice. Any open online checkout is expired before the balance changes, and the document becomes paid once its receipts cover it.

Before you start

  • Verify the intended environment, authenticated identity and specifically approved organization context.
  • The published application permission is invoices:write. Discover the exact granted canonical Books workspace and bind it separately from action input.
  • Approve the actual mutation, accounting inputs and any provider/recipient effects before CLI --confirm or MCP confirm:true. Fixture identifiers and simulated provider responses authorize no live operation.

Discover the target

topolo whoami --json
topolo actions get app_topolo_books.invoices.payments.record --detail --json
topolo resources topolo-books --json
topolo workspaces list topolo-books --json
  • Set BOOKS_WORKSPACE_ID to the exact granted workspace returned by discovery.
  • documentId: Exact document.id from invoices.list/get or bills.list/get, as appropriate to this action; the displayed invoice number is distinct.
  • bankLineId: Exact bank line.id from bank.lines.list in this workspace and bank account.

Request

POST /api/invoices/{documentId}/payments

Inspect and test this action. Save the reviewed input as payload.json; supply credential/resource context separately.

Input fields

FieldRequiredMeaningSchema and constraints
documentIdRequiredExact document.id from invoices.list/get or bills.list/get, as appropriate to this action; the displayed invoice number is distinct.{"type":"string","minLength":1}
paidOnRequiredpaid On{"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"}
amountMinorRequiredCurrency minor units as a safe integer, not a decimal money string. Follow this action’s sign and minimum constraints.{"type":"integer","exclusiveMinimum":0,"maximum":9007199254740991}
referenceOptionalreference{"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]}
bankLineIdOptionalExact bank line.id from bank.lines.list in this workspace and bank account.{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]}

Inspect nested fields and the complete input schema.

Effects

  • Validates the receipt, expires every open provider checkout, then records money received up to the outstanding balance. The invoice becomes paid once receipts cover it.

Interpret the response

Read $.document.id for the returned invoice identifier. Empty collections and nullable fields do not discover a target.

Call app_topolo_books.invoices.get and check paid_minor and status, then list payment sessions and confirm no open checkout remains.

Inspect the success schema. CLI/MCP add their own transport envelope; CLI --detail requests the full result.

Worked examples

Actual Books route handlers and the exported Worker were exercised against five local SQLite D1 concern databases with all committed migrations, the real posting Durable Object and local R2. Route captures use synthetic verified Auth; Worker captures use synthetic Auth transports. Nexus, Brand, Notify, Pay, Mercury and Xero responses are explicitly simulated at the provider transport boundary. Captures prove local request/response behavior and canonical SDK projection, not live bank access, payment movement, email delivery, provider eligibility, tax compliance, encrypted custody, scheduled execution, deployment or production completion. Fixture identities, credentials, addresses and records authorize no live operation.

Run a reviewed request

Save the input from the selected worked example as payload.json. Validate and inspect the plan before calling the action; refused examples demonstrate errors and are not instructions to execute.

CLI:

topolo actions validate app_topolo_books.invoices.payments.record --data @payload.json --json
topolo actions plan app_topolo_books.invoices.payments.record --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.invoices.payments.record --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --confirm --detail --json

MCP tool and arguments for the first successful example:

{
  "tool": "topolo_call_action",
  "arguments": {
    "actionId": "app_topolo_books.invoices.payments.record",
    "input": {
      "documentId": "doc_4e67b9476d1b417ba15e145cb845be2c",
      "paidOn": "2026-02-01",
      "amountMinor": 20000
    },
    "resourceType": "workspace",
    "resourceId": "<exact granted workspace id>",
    "confirm": true,
    "detail": true
  }
}

Refused response · auth_error

Input · payload.json:

{
  "documentId": "doc_9f2a",
  "paidOn": "2026-02-10",
  "amountMinor": 112300,
  "reference": "FPS 20260210"
}

Captured response · HTTP 401

{
  "error": "API key validation failed"
}

HTTP 401. SDK error code auth_error. Authenticate in the intended organization again. Verify whoami and the exact Books application/workspace binding before retrying; do not switch identity to work around a refusal.

Successful response · HTTP 201

Input · payload.json:

{
  "documentId": "doc_4e67b9476d1b417ba15e145cb845be2c",
  "paidOn": "2026-02-01",
  "amountMinor": 20000
}

Captured response · HTTP 201

{
  "document": {
    "id": "doc_4e67b9476d1b417ba15e145cb845be2c",
    "organization_id": "org_doc-route_muvnp44o11",
    "workspace_id": "ws_doc-route_muvnp44o11",
    "kind": "invoice",
    "contact_id": "con_452f75f9a2f3466fbfbb09d23fbde2aa",
    "number": "INV-000001",
    "reference": "PO-1",
    "issue_date": "2026-01-15",
    "due_date": null,
    "period_key": "2026-01",
    "currency": "USD",
    "exchange_rate": null,
    "subtotal_minor": 20000,
    "tax_minor": 0,
    "total_minor": 20000,
    "base_total_minor": 20000,
    "paid_minor": 20000,
    "status": "paid",
    "notes": null,
    "posted_event_id": null,
    "source": "manual",
    "source_document_id": null,
    "created_at": "2026-10-05T19:42:14.579Z",
    "updated_at": "2026-10-05T19:42:14.608Z",
    "sequence_no": 1,
    "approved_at": "2026-10-05T19:42:14.600Z",
    "sent_at": null,
    "amounts_include_tax": 0,
    "design_project_id": null,
    "design_export_id": null,
    "design_rendered_at": null,
    "brand_kit_id": null,
    "brand_version_id": null,
    "written_off_minor": 0
  },
  "payments": [
    {
      "id": "pay_9a94b9a2a58c4008bb3bb0659865b8ce",
      "organization_id": "org_doc-route_muvnp44o11",
      "workspace_id": "ws_doc-route_muvnp44o11",
      "document_id": "doc_4e67b9476d1b417ba15e145cb845be2c",
      "paid_on": "2026-02-01",
      "amount_minor": 20000,
      "currency": "USD",
      "reference": null,
      "bank_line_id": null,
      "source": "manual",
      "source_payment_id": null,
      "created_at": "2026-10-05T19:42:14.606Z",
      "updated_at": "2026-10-05T19:42:14.606Z",
      "ledger_account_id": null,
      "settlement_gross_minor": null,
      "settlement_fee_minor": null,
      "settlement_net_minor": null,
      "settlement_currency": null,
      "settlement_exchange_rate": null,
      "settlement_reference": null,
      "settlement_fee_details": null
    }
  ]
}

HTTP 201. Call app_topolo_books.invoices.get and check paid_minor and status, then list payment sessions and confirm no open checkout remains.

Refused response · document_draft

Input · payload.json:

{
  "documentId": "doc_84c6e8cdae9c4f1c8df757d41576e61d",
  "paidOn": "2026-03-01",
  "amountMinor": 2500
}

Captured response · HTTP 409

{
  "error": "document_draft",
  "message": "Approve the document before recording a payment"
}

HTTP 409. SDK error code document_draft. Approve the exact draft through invoices.approve or bills.approve, verify its ledger posting, then record the specifically authorized payment.

Successful response · HTTP 201

Input · payload.json:

{
  "documentId": "doc_562eb12102304e78b63cb490e9f2d5dd",
  "paidOn": "2026-09-09",
  "amountMinor": 12000,
  "reference": "Bank transfer"
}

Captured response · HTTP 201

{
  "document": {
    "id": "doc_562eb12102304e78b63cb490e9f2d5dd",
    "organization_id": "org_invoice-pay-manual_muvnpf3o16",
    "workspace_id": "ws_invoice-pay-manual_muvnpf3o16",
    "kind": "invoice",
    "contact_id": "con_3c8a518431684708b33706616c80e3ae",
    "number": "INV-000001",
    "reference": null,
    "issue_date": "2026-09-08",
    "due_date": "2026-09-22",
    "period_key": "2026-09",
    "currency": "GBP",
    "exchange_rate": null,
    "subtotal_minor": 12000,
    "tax_minor": 0,
    "total_minor": 12000,
    "base_total_minor": 12000,
    "paid_minor": 12000,
    "status": "paid",
    "notes": null,
    "posted_event_id": null,
    "source": "manual",
    "source_document_id": null,
    "created_at": "2026-10-05T19:42:28.800Z",
    "updated_at": "2026-10-05T19:42:28.810Z",
    "sequence_no": 1,
    "approved_at": "2026-10-05T19:42:28.802Z",
    "sent_at": null,
    "amounts_include_tax": 0,
    "design_project_id": null,
    "design_export_id": null,
    "design_rendered_at": null,
    "brand_kit_id": null,
    "brand_version_id": null,
    "written_off_minor": 0
  },
  "payments": [
    {
      "id": "pay_734567dcd2a64f328f55e20070b2b630",
      "organization_id": "org_invoice-pay-manual_muvnpf3o16",
      "workspace_id": "ws_invoice-pay-manual_muvnpf3o16",
      "document_id": "doc_562eb12102304e78b63cb490e9f2d5dd",
      "paid_on": "2026-09-09",
      "amount_minor": 12000,
      "currency": "GBP",
      "reference": "Bank transfer",
      "bank_line_id": null,
      "source": "manual",
      "source_payment_id": null,
      "created_at": "2026-10-05T19:42:28.809Z",
      "updated_at": "2026-10-05T19:42:28.809Z",
      "ledger_account_id": null,
      "settlement_gross_minor": null,
      "settlement_fee_minor": null,
      "settlement_net_minor": null,
      "settlement_currency": null,
      "settlement_exchange_rate": null,
      "settlement_reference": null,
      "settlement_fee_details": null
    }
  ]
}

HTTP 201. Call app_topolo_books.invoices.get and check paid_minor and status, then list payment sessions and confirm no open checkout remains.

Verify the result

  • Call app_topolo_books.invoices.get and check paid_minor and status, then list payment sessions and confirm no open checkout remains.

Errors and recovery

  • auth_error (HTTP 401): Authenticate in the intended organization again. Verify whoami and the exact Books application/workspace binding before retrying; do not switch identity to work around a refusal.
  • document_draft (HTTP 409): Approve the exact draft through invoices.approve or bills.approve, verify its ledger posting, then record the specifically authorized payment.

These are observed local refusals. Shared authentication, schema validation and resource authorization can also refuse before the route. Preserve the actual error, details and request id.

Recovery boundary

A recorded payment cannot be removed through the API yet. Check the amount before sending.

  • List invoices: List invoices newest first. Filter by status, contact or issue date, search the number, reference and notes, and sort by issue date, due date, number, total or status. The response carries the outstanding total for the filtered set.

Evidence

Actual Books route handlers and the exported Worker were exercised against five local SQLite D1 concern databases with all committed migrations, the real posting Durable Object and local R2. Route captures use synthetic verified Auth; Worker captures use synthetic Auth transports. Nexus, Brand, Notify, Pay, Mercury and Xero responses are explicitly simulated at the provider transport boundary. Captures prove local request/response behavior and canonical SDK projection, not live bank access, payment movement, email delivery, provider eligibility, tax compliance, encrypted custody, scheduled execution, deployment or production completion. Fixture identities, credentials, addresses and records authorize no live operation.