billing:read scope.
The rest open a customer’s billing page (billing:portal) and set billing up
(billing:admin). No endpoint here charges a card. Money moves only when a
customer acts on their billing page or a quote.
customer is your app’s own customer id (the customer key picked in
Settings → Billing and payments → Quotes and invoicing) or a Custral record id (rec_…). See
Naming the customer.
Every amount is in minor units (cents), the way Stripe returns them.
Totals are per currency and never summed across currencies.
If the workspace has not connected Stripe, each response has
stripeConnected: false and empty invoice and subscription lists, rather than
an error.
A customer’s billing
GET /v1/customers/{customer}/billing
quotes are Quote objects. upcomingInstalments
are the dated parts of accepted quotes’ one-time totals that have not been
billed yet.
Invoices
GET /v1/invoices
With customer the response is {stripeConnected, invoices}:
truncated is true when the period holds more invoices than one read
returns. Narrow period to see them all. With overdue=true, invoices is
filtered but totals still covers the whole period.
usageNotBilled counts metered usage events Custral could not send to Stripe
because the customer had no Stripe customer yet, usually usage from before
they accepted a quote. It is a running count, not limited to period.
Invoice attributes
Subscriptions
GET /v1/subscriptions
Subscription attributes
name, interval, currency, discountLabel, paymentTermsDays,
trialEnd and currentPeriodEnd are what they say.
To be told when a subscription starts, changes or ends, rather than
polling, listen for subscription.started, subscription.updated,
subscription.canceled, payment.succeeded, payment.failed and
invoice.overdue webhooks.
Revenue metrics
GET /v1/revenue/metrics
The workspace’s recurring revenue, read live from Stripe. The key’s creator must
be a workspace admin, as in the app.
One entry per currency, the largest MRR first.
mrr is monthly recurring
revenue after today’s discounts (metered usage is not included); arr is
mrr × 12; activeSubscriptions counts the subscriptions that bill.Net revenue retention, trailing 12 months: what the customers who paid a year
before the last complete month paid in that month, divided by what they paid
then.
1.08 is 108%. Customers who joined since do not count; one who left
counts as zero. null when nobody paid a year ago.Invoiced per month (
YYYY-MM) for the last 12 months, the current month last.
Drafts and voided invoices are left out.truncated is true when Stripe holds more subscriptions or invoices than one
read covers, so the figures undercount.
Billing sessions
POST /v1/customers/{customer}/billing-sessions
Opens one customer’s billing page for 15 minutes. Call it from your server
each time the customer opens Billing, then redirect to url, or pass token to
CustralBilling.mount (@custral/js). The key’s creator
needs Edit on the customer.
Where the page’s Back link and Stripe’s pages return.
https only (http
for localhost), on a host in allowedReturnDomains.Cancel and resume
POST /v1/customers/{customer}/subscriptions/cancel
Sets the customer’s plan to end at the period end. Nothing is charged or
refunded. Unlike the billing page, this does not check the page’s settings:
your server is acting, not the customer.
One of
too_expensive, missing_features, switched_service, unused,
other. Recorded in Stripe’s cancellation details.POST /v1/customers/{customer}/subscriptions/resume keeps a plan that was set
to end, and returns {resumed: true}.
Billing setup
GET /v1/billing/setup says whether billing from your product works yet. It
needs billing:admin, and the key’s creator must be a workspace admin, as in
Settings → Billing and payments → Quotes and invoicing.
stripe.mode is test or live, read from the connected account. missing
lists what is left, in the order to do it.
Stripe can’t be connected through the API, because Stripe asks a person for
consent. POST /v1/billing/setup/connect-link returns the settings page an
admin opens to press Connect Stripe.
Payment settings
GET /v1/billing/settings and PATCH /v1/billing/settings read and change
what Settings → Billing and payments → Quotes and invoicing holds. Objects and properties are named by their
key (account, account_id), never by id. Omitted fields stay as they are,
and "" clears one.
Other objects a quote can start from, each
{object, link}, where link is
its relation to the customers object (a deal that bills its account).Which billing fields Custral keeps on which object, by object key:
{"account": ["billing_status", "mrr"]}.The Stripe customer metadata key that holds your customer id, for matching
existing Stripe customers to records.
customersObject.
Billing page settings
GET /v1/billing/page and PATCH /v1/billing/page read and change what a
customer’s billing page shows. Omitted fields stay as they are.
Stripe customer links
A workspace that already bills in Stripe links its existing Stripe customers to the customers its app names, so their subscriptions, invoices and card read through Custral. Custral links one on its own when the match is certain, and these endpoints let you see and fix the rest. Linking writes onlymetadata.custralRecordId on the Stripe customer. Nothing is charged.
The key’s creator needs edit access to the customer, as in the app.
A customer’s Stripe customers
GET /v1/customers/{customer}/stripe-customers (billing:read).
Link and unlink
POST /v1/customers/{customer}/stripe-customers with {"stripeCustomer": "cus_…"}
links one; DELETE /v1/customers/{customer}/stripe-customers/{stripeCustomer}
unlinks it. Both need billing:admin and return the customer’s links, as above.
An unlinked Stripe customer is set aside, so Custral doesn’t link it back on
its own. A Stripe customer one of the customer’s quotes created can’t be unlinked,
because that quote bills it.
SDK
Stripe customers nobody is linked to
GET /v1/billing/unlinked-stripe-customers (billing:read, and the key’s
creator must be a workspace admin) lists the Stripe customers no customer is
linked to yet. Pass ?status=ignored for the ones that were set aside; the
default is unmatched.
reason says why it wasn’t linked on its own: ambiguous_key, ambiguous_email,
same_domain, personal_email or no_match. suggestions are customers it might
belong to; pass a suggestion’s customer to the link endpoint.
SDK
Errors
Every code arrives in a 200 response’s
error.code. See Errors for the status the SDK maps each one to.
Related
Quotes
Naming the customer, and the quotes that start billing.
Products
The catalog customers are billed from.
Bill from your product
The end-to-end guide.
Billing webhooks
Payment, invoice and subscription events.