Skip to content

credits

Credits: what an org has to spend, and the check that stops it at its limit.

On this page 7
TypeScript
import { credits } from "@copilotz/billing";

What it keeps

It keeps 4 collections, 1 of them on the record.

CollectionKept asFields
billingPlandocumentsname, terms, seats, since, counting, anchor, channel, seller, customer, subscription, status, statusAt, ended, sandbox, budget, waived, at
billingRoomin memory, gone on restartcredits, budget, limit, lowCredits, lowBudget, until
creditrecords, appended and never changedkind, amount, at, expires, note, reason, by, takes, sandbox
paymentrecords, appended and never changedchannel, seller, ref, amount, currency, rate, fee, purpose, credits, note, by, sandbox, at

What it lets callers do

Of its 16 Actions, people may call 8; agents may call 2; contacts and someone signed out may call none.

ActionPersonAgentContactAnyoneKeyRoutineWhat it does
billing.budgetyesnononononoSets the org's limit for a month, or removes it.
billing.grantyesnononononoGives the org credits, or takes some away.
billing.noticeyesyesnonoyesyesWhat to say above the composer about what the org can spend, if anything.
billing.payyesnononononoKeeps money that came in by hand, and the credits it bought.
billing.redeemyesnononononoAdds a gift code's credits to the org.
billing.setPlanyesnononononoPuts the org on a plan, or a contract of its own terms.
billing.stateyesyesnonoyesyesWhere the org stands: whether it can spend; its plan and credits for who runs it.
billing.waiveyesnononononoWaives the org's usage or seats, or lifts that.

An agent works for a person, and calls what both may. A key calls only what its scope names. A routine is work done for a person, which they set going.

Only the app's own code calls billing.apply, billing.check, billing.may, billing.plan, billing.priceList, billing.settle, billing.spent and billing.tier: its plugins, its schedules and the system.

Where it shows

It has no Views of its own: its front ends show it, credits-web.

  • What it adds to resources: planTier (action), spending (check, may), usage (priceList, spent).

What it needs

You set it in resources.billing: 8 settings are required.

SettingTypeRequiredWhat it is
billing.enforcebooleanyesWhether limits apply.
billing.plansRecord<string, PlanTerms>yesThe plans there are, and the one an org starts on.
billing.startstringyesThe plans there are, and the one an org starts on.
billing.budgetnumbernoThe month's limit an org starts with (USD); none: no limit.
billing.warnAtnumberyesThe share of a budget or of its credits used when it's said to be running low.
billing.freestring[]yesWhat's never stopped, by a call's purpose: the app's own upkeep, which follows turns.
billing.topUpsnumber[]yesAmounts offered for buying credits (USD), and the least and most.
billing.topUpMinnumberyesAmounts offered for buying credits (USD), and the least and most.
billing.topUpMaxnumberyesAmounts offered for buying credits (USD), and the least and most.
billing.payobjectnoHow an org pays, when something lets it (the Actions stripe names): checking out, managing what it pays, and which plans can be sold to it now (sellable: {} → plan names; none: every plan with a seat price).
billing.livebooleannoReal money: what came from a test mode stops counting.

It also reads directory and org, resource kinds the app and other plugins fill.

What it requires

The runtime doesn't start without usage: add it too.

It ships in a package of its own, @copilotz/billing@1.0.0-rc.34, for copilotz 1.0.0-rc.34: install it beside copilotz.

What it does on its own

Some of its work starts without a caller: an event, or the time.

  • billing.settle calls billing.settle, cron 20 0 * (UTC). Writes what's come due: the trial, this period's credits, a waiver that ended.

Listing

It keeps every listing rule.