Billing API
This page documents the 17 gateway endpoints tagged billing in the gateway's OpenAPI document. Every example targets a gateway on http://localhost:4000 and authenticates with the SPANWAY_API_KEY environment variable, which holds the master key or a virtual key that has access to the route. Request and response fields are taken from the schema the running gateway publishes at /openapi.json, and the same document is bundled with this site as openapi.json.
| Method | Path | Summary |
|---|---|---|
| POST | /billing/account/new | Create a billing account |
| POST | /billing/account/update | Change a billing account |
| DELETE | /billing/account/delete | Delete a billing account |
| GET | /billing/account/info | Show one billing account |
| GET | /billing/account/list | List billing accounts |
| POST | /billing/account/suspend | Suspend a billing account |
| POST | /billing/account/reinstate | Reinstate a billing account |
| GET | /billing/usage | Preview what an invoice would contain |
| POST | /billing/invoice/generate | Generate a draft invoice |
| POST | /billing/invoice/generate_all | Generate draft invoices for every account |
| POST | /billing/invoice/issue | Issue a draft invoice |
| POST | /billing/invoice/mark_paid | Mark an invoice paid |
| POST | /billing/invoice/void | Void an unpaid invoice |
| GET | /billing/invoice/info | Show one invoice |
| GET | /billing/invoice/list | List invoices |
| GET | /billing/invoice/export | Download an invoice as CSV |
| POST | /billing/webhook/stripe | Receive Stripe webhook events |
Endpoints
POST /billing/account/new
Create a billing account
Create the billing account for a team, an organization or an end user, so its spend can be invoiced.
Each scope has at most one account, and the team, organization or end user must already exist (a 404
otherwise, a 409 when it already has an account). markup_percent is added on top of provider spend,
tax_percent after markup, and grace_period_days says how long an issued invoice has before it is due.
Proxy admins only, needs a license that includes billing.
Request body (application/json, schema NewBillingAccount):
| Field | Type | Required | Description |
|---|---|---|---|
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | No | Currency |
markup_percent | number | No | Markup Percent |
tax_percent | number | No | Tax Percent |
payment_provider | enum: "manual", "stripe" | No | Payment Provider |
grace_period_days | integer | No | Grace Period Days |
auto_suspend | boolean | No | Auto Suspend |
metadata | object | No | Metadata |
Example request:
curl -X POST "http://localhost:4000/billing/account/new" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"scope_type": "team",
"scope_id": "team-nlp",
"display_name": "NLP team",
"billing_email": "nlp-finance@example.com",
"markup_percent": 10,
"payment_provider": "stripe",
"auto_suspend": true
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_BillingAccountTable |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 409 | Conflict | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | Yes | Currency |
markup_percent | number | Yes | Markup Percent |
tax_percent | number | Yes | Tax Percent |
status | enum: "active", "past_due", "suspended" | Yes | Status |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_customer_id | string or null | No | Stripe Customer Id |
grace_period_days | integer | Yes | Grace Period Days |
auto_suspend | boolean | Yes | Auto Suspend |
metadata | object | Yes | Metadata |
created_by | string | Yes | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
POST /billing/account/update
Change a billing account
Change the pricing, payment provider or suspension terms of an account. Only the fields you send change.
The scope an account bills cannot change, so delete the account and create a new one for a different team,
organization or end user. A body with nothing but account_id is a 400. Proxy admins only.
Request body (application/json, schema UpdateBillingAccount):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
display_name | string or null | No | Display Name |
billing_email | string or null | No | Billing Email |
currency | string or null | No | Currency |
markup_percent | number or null | No | Markup Percent |
tax_percent | number or null | No | Tax Percent |
payment_provider | enum: "manual", "stripe" or null | No | Payment Provider |
grace_period_days | integer or null | No | Grace Period Days |
auto_suspend | boolean or null | No | Auto Suspend |
metadata | object or null | No | Metadata |
Example request:
curl -X POST "http://localhost:4000/billing/account/update" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f",
"markup_percent": 12.5,
"grace_period_days": 14
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_BillingAccountTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | Yes | Currency |
markup_percent | number | Yes | Markup Percent |
tax_percent | number | Yes | Tax Percent |
status | enum: "active", "past_due", "suspended" | Yes | Status |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_customer_id | string or null | No | Stripe Customer Id |
grace_period_days | integer | Yes | Grace Period Days |
auto_suspend | boolean | Yes | Auto Suspend |
metadata | object | Yes | Metadata |
created_by | string | Yes | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
DELETE /billing/account/delete
Delete a billing account
Delete an account that has no draft or open invoice, and return the account that was removed.
Settled invoices are kept for the books. An account with a draft or open invoice is a 400, so void or settle those first. Proxy admins only.
Request body (application/json, schema BillingAccountRef):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
Example request:
curl -X DELETE "http://localhost:4000/billing/account/delete" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_BillingAccountTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | Yes | Currency |
markup_percent | number | Yes | Markup Percent |
tax_percent | number | Yes | Tax Percent |
status | enum: "active", "past_due", "suspended" | Yes | Status |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_customer_id | string or null | No | Stripe Customer Id |
grace_period_days | integer | Yes | Grace Period Days |
auto_suspend | boolean | Yes | Auto Suspend |
metadata | object | Yes | Metadata |
created_by | string | Yes | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
GET /billing/account/info
Show one billing account
Return the account with account_id, or a 404 when there is none. Proxy admins and admin viewers only. Docs
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
account_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/billing/account/info?account_id=account_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_BillingAccountTable |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | Yes | Currency |
markup_percent | number | Yes | Markup Percent |
tax_percent | number | Yes | Tax Percent |
status | enum: "active", "past_due", "suspended" | Yes | Status |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_customer_id | string or null | No | Stripe Customer Id |
grace_period_days | integer | Yes | Grace Period Days |
auto_suspend | boolean | Yes | Auto Suspend |
metadata | object | Yes | Metadata |
created_by | string | Yes | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
GET /billing/account/list
List billing accounts
Page through the billing accounts, newest first, optionally only one scope_type (team, organization, end_user) or one status (active, past_due, suspended). page_size goes up to 100. Proxy admins and admin viewers only. Docs
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
scope_type | query | enum: "team", "organization", "end_user" or null | No | |
status | query | enum: "active", "past_due", "suspended" or null | No | |
page | query | integer | No | |
page_size | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/billing/account/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json BillingAccountListResponse |
| 403 | Forbidden | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
accounts | array of Spanway_BillingAccountTable | Yes | Accounts |
total | integer | Yes | Total |
page | integer | Yes | Page |
page_size | integer | Yes | Page Size |
POST /billing/account/suspend
Suspend a billing account
Block the billed team, organization or end user and mark the account suspended.
Every request from that scope is refused until /billing/account/reinstate is called. Open invoices stay
open. An account that is already suspended is a 400. Proxy admins only.
Request body (application/json, schema BillingAccountRef):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
Example request:
curl -X POST "http://localhost:4000/billing/account/suspend" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_BillingAccountTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | Yes | Currency |
markup_percent | number | Yes | Markup Percent |
tax_percent | number | Yes | Tax Percent |
status | enum: "active", "past_due", "suspended" | Yes | Status |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_customer_id | string or null | No | Stripe Customer Id |
grace_period_days | integer | Yes | Grace Period Days |
auto_suspend | boolean | Yes | Auto Suspend |
metadata | object | Yes | Metadata |
created_by | string | Yes | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
POST /billing/account/reinstate
Reinstate a billing account
Unblock the billed scope and mark the account active, whatever invoices remain open.
This is the only way back from suspended, a payment alone never reinstates a suspended account. An account
that is already active is a 400. Proxy admins only.
Request body (application/json, schema BillingAccountRef):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
Example request:
curl -X POST "http://localhost:4000/billing/account/reinstate" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_BillingAccountTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
scope_type | enum: "team", "organization", "end_user" | Yes | Scope Type |
scope_id | string | Yes | Scope Id |
display_name | string | Yes | Display Name |
billing_email | string or null | No | Billing Email |
currency | string | Yes | Currency |
markup_percent | number | Yes | Markup Percent |
tax_percent | number | Yes | Tax Percent |
status | enum: "active", "past_due", "suspended" | Yes | Status |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_customer_id | string or null | No | Stripe Customer Id |
grace_period_days | integer | Yes | Grace Period Days |
auto_suspend | boolean | Yes | Auto Suspend |
metadata | object | Yes | Metadata |
created_by | string | Yes | Created By |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
GET /billing/usage
Preview what an invoice would contain
Show the line items and totals an invoice for the period would have, without writing anything.
The period runs from period_start (billed) to period_end (the first day not billed), so a calendar month
is 2026-09-01 to 2026-10-01. Proxy admins and admin viewers only.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
account_id | query | string | Yes | |
period_start | query | string | Yes | |
period_end | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/billing/usage?account_id=account_id-123&period_start=string&period_end=string" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json UsagePreview |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Unprocessable Content | application/json ErrorDetail |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Account Id |
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
currency | string | Yes | Currency |
line_items | array of InvoiceLineItem | Yes | Line Items |
subtotal | number | Yes | Subtotal |
markup_amount | number | Yes | Markup Amount |
tax_amount | number | Yes | Tax Amount |
total | number | Yes | Total |
POST /billing/invoice/generate
Generate a draft invoice
Build a draft invoice for one account from its daily spend in the period. Nothing is sent until it is issued.
A non-void invoice of the account that already covers any day of the period is a 409. Proxy admins only. The new draft is written to the audit log.
Request body (application/json, schema GenerateInvoiceRequest):
| Field | Type | Required | Description |
|---|---|---|---|
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
account_id | string | Yes | Account Id |
Example request:
curl -X POST "http://localhost:4000/billing/invoice/generate" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"account_id": "3f2a9c10-7b1e-4c2d-9e8f-0a1b2c3d4e5f",
"period_start": "2026-09-01",
"period_end": "2026-10-01"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_InvoiceTable |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 409 | Conflict | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
account_id | string | Yes | Account Id |
invoice_number | string | Yes | Invoice Number |
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
status | enum: "draft", "open", "paid", "void", "uncollectible" | Yes | Status |
currency | string | Yes | Currency |
subtotal | number | Yes | Subtotal |
markup_amount | number | Yes | Markup Amount |
tax_amount | number | Yes | Tax Amount |
total | number | Yes | Total |
line_items | array of InvoiceLineItem | Yes | Line Items |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_invoice_id | string or null | No | Stripe Invoice Id |
hosted_invoice_url | string or null | No | Hosted Invoice Url |
issued_at | string or null | No | Issued At |
due_at | string or null | No | Due At |
paid_at | string or null | No | Paid At |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
POST /billing/invoice/generate_all
Generate draft invoices for every account
Do what the monthly job does, for any period: a draft for every active account with usage that is not yet invoiced for it.
Accounts without usage, or with an invoice already covering the period, are listed in skipped_account_ids.
Proxy admins only.
Request body (application/json, schema PeriodRequest):
| Field | Type | Required | Description |
|---|---|---|---|
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
Example request:
curl -X POST "http://localhost:4000/billing/invoice/generate_all" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"period_start": "2026-09-01",
"period_end": "2026-10-01"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json GenerateAllResponse |
| 403 | Forbidden | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
generated | array of Spanway_InvoiceTable | Yes | Generated |
skipped_account_ids | array of string | Yes | Skipped Account Ids |
POST /billing/invoice/issue
Issue a draft invoice
Move a draft to open, due after the account's grace period, and for a Stripe account create and finalize
the Stripe invoice so Stripe collects payment.
The Stripe customer is created first when the account has none. An invoice that is not a draft is a 400 and a Stripe failure is a 502. Proxy admins only.
Request body (application/json, schema InvoiceRef):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
Example request:
curl -X POST "http://localhost:4000/billing/invoice/issue" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invoice_id": "9c0d1e2f-3a4b-4c5d-8e9f-a0b1c2d3e4f5"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_InvoiceTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
| 502 | Bad Gateway | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
account_id | string | Yes | Account Id |
invoice_number | string | Yes | Invoice Number |
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
status | enum: "draft", "open", "paid", "void", "uncollectible" | Yes | Status |
currency | string | Yes | Currency |
subtotal | number | Yes | Subtotal |
markup_amount | number | Yes | Markup Amount |
tax_amount | number | Yes | Tax Amount |
total | number | Yes | Total |
line_items | array of InvoiceLineItem | Yes | Line Items |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_invoice_id | string or null | No | Stripe Invoice Id |
hosted_invoice_url | string or null | No | Hosted Invoice Url |
issued_at | string or null | No | Issued At |
due_at | string or null | No | Due At |
paid_at | string or null | No | Paid At |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
POST /billing/invoice/mark_paid
Mark an invoice paid
Record a payment taken outside Stripe and settle the invoice.
A past_due account returns to active once none of its other open invoices is overdue. A draft, void or
already paid invoice is a 400. Proxy admins only.
Request body (application/json, schema InvoiceRef):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
Example request:
curl -X POST "http://localhost:4000/billing/invoice/mark_paid" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invoice_id": "9c0d1e2f-3a4b-4c5d-8e9f-a0b1c2d3e4f5"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_InvoiceTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
account_id | string | Yes | Account Id |
invoice_number | string | Yes | Invoice Number |
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
status | enum: "draft", "open", "paid", "void", "uncollectible" | Yes | Status |
currency | string | Yes | Currency |
subtotal | number | Yes | Subtotal |
markup_amount | number | Yes | Markup Amount |
tax_amount | number | Yes | Tax Amount |
total | number | Yes | Total |
line_items | array of InvoiceLineItem | Yes | Line Items |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_invoice_id | string or null | No | Stripe Invoice Id |
hosted_invoice_url | string or null | No | Hosted Invoice Url |
issued_at | string or null | No | Issued At |
due_at | string or null | No | Due At |
paid_at | string or null | No | Paid At |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
POST /billing/invoice/void
Void an unpaid invoice
Cancel an unpaid invoice, in Stripe too when it was issued there, and free its period to be invoiced again.
A paid invoice is a 400 and a Stripe failure is a 502. Proxy admins only.
Request body (application/json, schema InvoiceRef):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
Example request:
curl -X POST "http://localhost:4000/billing/invoice/void" \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"invoice_id": "9c0d1e2f-3a4b-4c5d-8e9f-a0b1c2d3e4f5"
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_InvoiceTable |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
| 502 | Bad Gateway | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
account_id | string | Yes | Account Id |
invoice_number | string | Yes | Invoice Number |
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
status | enum: "draft", "open", "paid", "void", "uncollectible" | Yes | Status |
currency | string | Yes | Currency |
subtotal | number | Yes | Subtotal |
markup_amount | number | Yes | Markup Amount |
tax_amount | number | Yes | Tax Amount |
total | number | Yes | Total |
line_items | array of InvoiceLineItem | Yes | Line Items |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_invoice_id | string or null | No | Stripe Invoice Id |
hosted_invoice_url | string or null | No | Hosted Invoice Url |
issued_at | string or null | No | Issued At |
due_at | string or null | No | Due At |
paid_at | string or null | No | Paid At |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
GET /billing/invoice/info
Show one invoice
Return the invoice with invoice_id, line items included, or a 404 when there is none. Proxy admins and admin viewers only. Docs
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
invoice_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/billing/invoice/info?invoice_id=invoice_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json Spanway_InvoiceTable |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
invoice_id | string | Yes | Invoice Id |
account_id | string | Yes | Account Id |
invoice_number | string | Yes | Invoice Number |
period_start | string | Yes | Period Start |
period_end | string | Yes | Period End |
status | enum: "draft", "open", "paid", "void", "uncollectible" | Yes | Status |
currency | string | Yes | Currency |
subtotal | number | Yes | Subtotal |
markup_amount | number | Yes | Markup Amount |
tax_amount | number | Yes | Tax Amount |
total | number | Yes | Total |
line_items | array of InvoiceLineItem | Yes | Line Items |
payment_provider | enum: "manual", "stripe" | Yes | Payment Provider |
stripe_invoice_id | string or null | No | Stripe Invoice Id |
hosted_invoice_url | string or null | No | Hosted Invoice Url |
issued_at | string or null | No | Issued At |
due_at | string or null | No | Due At |
paid_at | string or null | No | Paid At |
created_at | string or null | No | Created At |
updated_at | string or null | No | Updated At |
GET /billing/invoice/list
List invoices
Page through the invoices, newest first, optionally only one account_id or one status (draft, open, paid, void, uncollectible). page_size goes up to 100. Proxy admins and admin viewers only. Docs
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
account_id | query | string or null | No | |
status | query | enum: "draft", "open", "paid", "void", "uncollectible" or null | No | |
page | query | integer | No | |
page_size | query | integer | No |
Example request:
curl -X GET "http://localhost:4000/billing/invoice/list" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json InvoiceListResponse |
| 403 | Forbidden | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
invoices | array of Spanway_InvoiceTable | Yes | Invoices |
total | integer | Yes | Total |
page | integer | Yes | Page |
page_size | integer | Yes | Page Size |
GET /billing/invoice/export
Download an invoice as CSV
Download the line items of an invoice as a CSV file named after the invoice number.
Proxy admins and admin viewers only, and an unknown invoice_id is a 404.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
invoice_id | query | string | Yes |
Example request:
curl -X GET "http://localhost:4000/billing/invoice/export?invoice_id=invoice_id-123" \
-H "Authorization: Bearer $SPANWAY_API_KEY"
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | The invoice line items as CSV | text/csv string |
| 403 | Forbidden | application/json ErrorDetail |
| 404 | Not Found | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
| 500 | Internal Server Error | application/json ErrorDetail |
POST /billing/webhook/stripe
Receive Stripe webhook events
Stripe calls this without a Spanway key. The signature over the raw body is the only authentication, so an unsigned or badly signed request is a 400. Invoice events need the billing feature and Cloud checkout, subscription, top-up and customer events need the cloud feature. A signed event whose feature is not licensed is a 403 so Stripe retries it once the license allows it. Events for invoices Stripe did not learn from us are acknowledged and ignored so Stripe stops retrying them.
Parameters:
| Name | In | Type | Required | Description |
|---|---|---|---|---|
stripe-signature | header | string or null | No |
Request body (application/json, object):
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Id |
type | string | Yes | Type |
data | object | Yes | Data |
Example request:
curl -X POST "http://localhost:4000/billing/webhook/stripe" \
-H "Content-Type: application/json" \
-d '{
"id": "evt_1",
"type": "checkout.session.completed",
"data": {
"object": {
"id": "cs_1",
"customer": "cus_1"
}
}
}'
Responses:
| Status | Description | Body |
|---|---|---|
| 200 | Successful Response | application/json WebhookResponse |
| 400 | Bad Request | application/json ErrorDetail |
| 403 | Forbidden | application/json ErrorDetail |
| 422 | Validation Error | application/json HTTPValidationError |
Response fields (200):
| Field | Type | Required | Description |
|---|---|---|---|
received | true | No | Received |
handled | boolean | Yes | Handled |
event | string or null | No | Event |