Outcome
Create one hosted Topolo Pay checkout through the selected provider account for the invoice outstanding balance and return the stable Books customer-page URL. Repeating the same request returns the existing open session instead of creating another charge path.
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.payment_sessions.create --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.
- merchantId: Exact Pay merchant id from the workspace-authorized payment choices.
- providerAccountId: Exact provider account id paired with that authorized Pay merchant.
Request
POST /api/invoices/{documentId}/payment-sessions
Inspect and test this action. Save the reviewed input as payload.json; supply credential/resource context separately.
Input fields
| Field | Required | Meaning | Schema and constraints |
|---|---|---|---|
documentId | Required | Exact 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} |
merchantId | Required | Exact Pay merchant id from the workspace-authorized payment choices. | {"type":"string","minLength":1} |
providerAccountId | Required | Exact provider account id paired with that authorized Pay merchant. | {"anyOf":[{"type":"string","minLength":1},{"type":"null"}]} |
Inspect nested fields and the complete input schema.
Effects
- Creates or reuses the opaque Books customer page and creates a Pay checkout for exactly the current outstanding balance. The returned payment_url opens Books; the provider checkout is exposed only from that page while eligible.
Interpret the response
Read $.session.id for the returned invoice_payment_session identifier. Empty collections and nullable fields do not discover a target.
Call app_topolo_books.invoices.payment_sessions.list and confirm the returned session id, merchant, amount, open state and payment_url.
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.payment_sessions.create --data @payload.json --json
topolo actions plan app_topolo_books.invoices.payment_sessions.create --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.invoices.payment_sessions.create --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.payment_sessions.create",
"input": {
"documentId": "doc_562eb12102304e78b63cb490e9f2d5dd",
"merchantId": "mrc_books",
"providerAccountId": "mpa_checkout_books"
},
"resourceType": "workspace",
"resourceId": "<exact granted workspace id>",
"confirm": true,
"detail": true
}
}
Refused response · auth_error
Input · payload.json:
{
"documentId": "doc_9f2a",
"merchantId": "mrc_books",
"providerAccountId": "mpa_checkout_books"
}
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_562eb12102304e78b63cb490e9f2d5dd",
"merchantId": "mrc_books",
"providerAccountId": "mpa_checkout_books"
}
Captured response · HTTP 201
{
"session": {
"id": "ips_ab6b074850a94a23912b8ce5988ec2e1",
"organization_id": "org_invoice-pay-manual_muvnpf3o16",
"workspace_id": "ws_invoice-pay-manual_muvnpf3o16",
"document_id": "doc_562eb12102304e78b63cb490e9f2d5dd",
"merchant_id": "mrc_books",
"order_id": "books-doc_562eb12102304e78b63cb490e9f2d5dd-0-mrc_books-mpa_checkout_books-0",
"session_id": "cs_invoice",
"amount_minor": 12000,
"currency": "GBP",
"status": "open",
"provider_status": "open",
"payment_id": null,
"created_at": "2026-10-05T19:42:28.806Z",
"updated_at": "2026-10-05T19:42:28.806Z",
"completed_at": null,
"provider_account_id": "mpa_checkout_books",
"payment_url": "https://books.test/invoice/ish_5cf9b3e5c9ad42a0a38d8ffeba7109d2"
},
"reused": false
}
HTTP 201. Call app_topolo_books.invoices.payment_sessions.list and confirm the returned session id, merchant, amount, open state and payment_url.
Successful response · HTTP 201
Input · payload.json:
{
"documentId": "doc_f8852615bef8424d9e4d87f8fb6b2592",
"merchantId": "mrc_books",
"providerAccountId": "mpa_checkout_books"
}
Captured response · HTTP 201
{
"session": {
"id": "ips_b81e20e56bf84c6ca2e3c05a7061dabc",
"organization_id": "org_invoice-pay-route_muvnpf1314",
"workspace_id": "ws_invoice-pay-route_muvnpf1314",
"document_id": "doc_f8852615bef8424d9e4d87f8fb6b2592",
"merchant_id": "mrc_books",
"order_id": "books-doc_f8852615bef8424d9e4d87f8fb6b2592-0-mrc_books-mpa_checkout_books-0",
"session_id": "cs_invoice",
"amount_minor": 12000,
"currency": "GBP",
"status": "open",
"provider_status": "open",
"payment_id": null,
"created_at": "2026-10-05T19:42:28.717Z",
"updated_at": "2026-10-05T19:42:28.717Z",
"completed_at": null,
"provider_account_id": "mpa_checkout_books",
"payment_url": "https://books.test/invoice/ish_a86b94eb205442da85b4c30848fbfca2"
},
"reused": false
}
HTTP 201. Call app_topolo_books.invoices.payment_sessions.list and confirm the returned session id, merchant, amount, open state and payment_url.
Successful response · HTTP 201
Input · payload.json:
{
"documentId": "doc_f8852615bef8424d9e4d87f8fb6b2592",
"merchantId": "mrc_books",
"providerAccountId": "mpa_checkout_books"
}
Captured response · HTTP 201
{
"session": {
"id": "ips_796bc693e691492581967e05e947bad6",
"organization_id": "org_invoice-pay-route_muvnpf1314",
"workspace_id": "ws_invoice-pay-route_muvnpf1314",
"document_id": "doc_f8852615bef8424d9e4d87f8fb6b2592",
"merchant_id": "mrc_books",
"order_id": "books-doc_f8852615bef8424d9e4d87f8fb6b2592-0-mrc_books-mpa_checkout_books-1",
"session_id": "cs_invoice_replacement",
"amount_minor": 12000,
"currency": "GBP",
"status": "open",
"provider_status": "open",
"payment_id": null,
"created_at": "2026-10-05T19:42:28.729Z",
"updated_at": "2026-10-05T19:42:28.729Z",
"completed_at": null,
"provider_account_id": "mpa_checkout_books",
"payment_url": "https://books.test/invoice/ish_a86b94eb205442da85b4c30848fbfca2"
},
"reused": false
}
HTTP 201. Call app_topolo_books.invoices.payment_sessions.list and confirm the returned session id, merchant, amount, open state and payment_url.
Verify the result
- Call app_topolo_books.invoices.payment_sessions.list and confirm the returned session id, merchant, amount, open state and payment_url.
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.
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
Recording money received expires the unused checkout before changing the invoice balance.
Related actions
- Check invoice payment: Verify a hosted checkout directly with Topolo Pay. A completed payment is recorded once against the invoice and posted through undeposited funds for later payout reconciliation.
- 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.
- 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.
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.