# Billing tools

[All tool areas](/docs/tools.md). Each tool acts within your access.

## Billing

### accept_operator_terms

Accept Lokl's operator terms for the organization, recorded with who and when. Only the current version is accepted (get_billing's operatorTerms.currentVersion). Needs billing:write across the organization: the owner who just created it holds that.

Changes · Members of an organization · Needs billing:write

#### Input

- `version` — string; required.  minLength: 1; maxLength: 40

#### Output

- `version` — string; required. 
- `acceptedAt` — string; required.  format: "date-time"
- `by` — object; required. 
  - `by.id` — string; required. 
  - `by.name` — string or null; required. 

### buy_ai_credits

Buy an AI credit top-up pack (1,000, 2,750, or 6,000 AI credits: US$10, US$25, US$50, or CA$12, CA$30, CA$60 for an organization billed in CAD; get_billing's packs are its own prices), plus tax. Applying makes a one-off invoice paid with the card in the dashboard (the output's clientSecret is for Stripe's Payment Element); the AI credits are added once it's paid, and never expire. Refused while online booking is paused (pay the overdue invoice, or choose a plan, first). Needs a billing address (given here or on file), and billing:write across the organization.

Changes · Members of an organization · Needs billing:write

#### Input

- `pack` — string; required. The top-up pack to buy (get_ai_credits lists the packs) Allowed: "ai\_credits\_1000", "ai\_credits\_2750", "ai\_credits\_6000"
- `billingAddress` — object; optional. The billing address (Stripe's Address Element), saved for tax: Stripe Tax works the tax out from it. Needed the first time; later it replaces the one on file
  - `billingAddress.line1` — string; required.  minLength: 1; maxLength: 200
  - `billingAddress.line2` — string; optional.  maxLength: 200
  - `billingAddress.city` — string; required.  minLength: 1; maxLength: 100
  - `billingAddress.state` — string; optional.  maxLength: 100
  - `billingAddress.postalCode` — string; required.  minLength: 1; maxLength: 20
  - `billingAddress.country` — string; required.  pattern: "^\[A-Z\]\{2\}$"

#### Output

- `clientSecret` — string; required. For the Payment Element to pay the invoice
- `publishableKey` — string; required. Lokl's own Stripe publishable key, to load Stripe's Payment Element and Address Element on Lokl's account

### choose_plan

Choose the organization's Lokl plan (starter, growth, or scale), billed per active location per month plus tax. A first plan starts now and is active once its first invoice is paid with the card in the dashboard (the output's clientSecret is for Stripe's Payment Element); chosen during the trial, it keeps the trial: the card is saved now (clientSecretKind setup) and the first charge is when the trial ends. A change of tier takes effect at the next period, with no proration. Cancelling is in Stripe's portal (get_billing_portal_link). Needs the operator terms accepted, a billing address (given here or on file), and billing:write across the organization.

Changes · Members of an organization · Needs billing:write

#### Input

- `tier` — string; required. The plan: starter, growth, or scale (get_billing lists them) Allowed: "starter", "growth", "scale"
- `billingAddress` — object; optional. The billing address (Stripe's Address Element), saved for tax: Stripe Tax works the tax out from it. Needed the first time; later it replaces the one on file
  - `billingAddress.line1` — string; required.  minLength: 1; maxLength: 200
  - `billingAddress.line2` — string; optional.  maxLength: 200
  - `billingAddress.city` — string; required.  minLength: 1; maxLength: 100
  - `billingAddress.state` — string; optional.  maxLength: 100
  - `billingAddress.postalCode` — string; required.  minLength: 1; maxLength: 20
  - `billingAddress.country` — string; required.  pattern: "^\[A-Z\]\{2\}$"

#### Output

- `status` — string; required. The billing status now: unchanged until the first invoice is paid Allowed: "trialing", "active", "past\_due", "limited", "canceled"
- `clientSecret` — string or null; required. For the Payment Element: the first invoice's payment (confirmPayment), or the card for after the trial (confirmSetup); null when there's nothing to give now (a change at the next period)
- `clientSecretKind` — string or null; required. payment: call confirmPayment; setup: confirmSetup (the plan starts when the trial ends); null with no clientSecret Allowed: "payment", "setup"
- `effectiveAt` — string; required.  format: "date-time"
- `publishableKey` — string; required. Lokl's own Stripe publishable key, to load Stripe's Payment Element and Address Element on Lokl's account

### get_billing

Get what the organization pays Lokl: its billing status (trial, active, past due with the grace's end, limited, canceled), plan, trial end, current period, whether it cancels at the period's end, active locations billed, the price per location, the next invoice (before tax, tax, total), the card and billing address on file, the plans and AI credit top-up packs, the operator terms accepted, and what each location uses of the plan's limits (bookings this period and staff logins, with each limit; null is unlimited). Needs billing:read across the organization (owner and finance).

Reads · Members of an organization · Needs billing:read

No input.

#### Output

- `currency` — string; optional. What Lokl bills this organization in: CAD when its billing address is in Canada, else USD, fixed for good by its first plan or AI credit purchase. Until then it follows the billing address on file, or without one, CAD when every entity is CAD. Every price here (plans, packs, pricePerLocation, nextInvoice) is in it. Always sent pattern: "^\[A-Z\]\{3\}$"
- `status` — string; required. trialing: the 30-day trial, no card. active: paid. past_due: a payment failed; everything works until graceEndsAt. limited: the trial ended with no plan, or the grace ran out: online sales and in-app AI stop, everything else works; paying restores it at once. canceled: the plan ended after cancelling (online sales and in-app AI stop, as limited) Allowed: "trialing", "active", "past\_due", "limited", "canceled"
- `tier` — string or null; required. The plan being paid for; comped is Lokl's own (no invoices). Null until a plan's first invoice is paid Allowed: "starter", "growth", "scale", "comped"
- `pendingTier` — string or null; required. A plan chosen whose first invoice isn't paid yet, or that starts when the trial ends (choose_plan again with it to pay or save the card); null otherwise Allowed: "starter", "growth", "scale"
- `scheduledTier` — string or null; required. The plan from the next period on, when a change was chosen; null otherwise Allowed: "starter", "growth", "scale"
- `trialEndsAt` — string or null; required.  format: "date-time"
- `currentPeriod` — object or null; required. The paid period now; null before the first
  - `currentPeriod.start` — string; required.  format: "date-time"
  - `currentPeriod.end` — string; required.  format: "date-time"
- `cancelAtPeriodEnd` — boolean; required. Cancelled in Stripe's portal: the plan ends at currentPeriod.end. Also true while pendingCurrencySwitch waits, when the plan carries on in the new currency instead
- `pendingCurrencySwitch` — object or null; optional. A move to another billing currency Lokl set up (its own operator script): the plan carries on in `to` from `at` (the current period's end), same plan and locations, charged to the card on file; nothing is refunded or charged twice. Null when there's none. Always sent
  - `pendingCurrencySwitch.to` — string; required. ISO 4217: the billing account's currency (USD or CAD), fixed by the billing address's country at the first purchase and never changed pattern: "^\[A-Z\]\{3\}$"
  - `pendingCurrencySwitch.at` — string; required.  format: "date-time"
- `hasSubscription` — boolean; optional. Whether a subscription is billing the plan now; false after an unpaid currency switch or before a first plan: paying means choosing the plan
- `graceEndsAt` — string or null; required. While past_due: when online sales and in-app AI stop unless the invoice is paid format: "date-time"
- `locationsBilled` — integer; required. Active locations: the plan's quantity. A change shows on the next invoice (no proration) minimum: 0; maximum: 9007199254740991
- `pricePerLocation` — object or null; required. The tier's price per location per month, before tax; null without a paid tier, and for comped
  - `pricePerLocation.amount` — integer; required. Minor units (cents) of `currency` minimum: 0; maximum: 9007199254740991
  - `pricePerLocation.currency` — string; required. ISO 4217: the billing account's currency (USD or CAD), fixed by the billing address's country at the first purchase and never changed pattern: "^\[A-Z\]\{3\}$"
- `nextInvoice` — object or null; required. The next invoice as Stripe previews it (tax by Stripe Tax); null with no subscription, when it ends at the period's end, or when Stripe couldn't be reached (providerReached false)
  - `nextInvoice.date` — string; required.  format: "date-time"
  - `nextInvoice.subtotal` — integer; required. Before tax minimum: 0; maximum: 9007199254740991
  - `nextInvoice.tax` — integer; required. Minor units (cents) of `currency` minimum: 0; maximum: 9007199254740991
  - `nextInvoice.total` — integer; required. Minor units (cents) of `currency` minimum: 0; maximum: 9007199254740991
  - `nextInvoice.currency` — string; required. ISO 4217: the billing account's currency (USD or CAD), fixed by the billing address's country at the first purchase and never changed pattern: "^\[A-Z\]\{3\}$"
- `card` — object or null; required. The card Lokl bills; null when none is on file
  - `card.brand` — string; required. 
  - `card.last4` — string; required. 
  - `card.expMonth` — integer; required.  minimum: -9007199254740991; maximum: 9007199254740991
  - `card.expYear` — integer; required.  minimum: -9007199254740991; maximum: 9007199254740991
- `billingAddress` — object or null; required. The billing address on file, for tax; null when there's none (choose_plan and buy_ai_credits then need one)
  - `billingAddress.line1` — string; required.  minLength: 1; maxLength: 200
  - `billingAddress.line2` — string; optional.  maxLength: 200
  - `billingAddress.city` — string; required.  minLength: 1; maxLength: 100
  - `billingAddress.state` — string; optional.  maxLength: 100
  - `billingAddress.postalCode` — string; required.  minLength: 1; maxLength: 20
  - `billingAddress.country` — string; required.  pattern: "^\[A-Z\]\{2\}$"
- `providerReached` — boolean; required. False when Stripe couldn't be reached for the card, the address, and the next invoice, which are then null though they may exist
- `plans` — array; required. 
  - `plans[]` — object; optional. 
    - `plans[].tier` — string; required. The plan: starter, growth, or scale (get_billing lists them) Allowed: "starter", "growth", "scale"
    - `plans[].name` — string; required. 
    - `plans[].pricePerLocation` — integer; required. Per active location per month, before tax minimum: 0; maximum: 9007199254740991
    - `plans[].aiCreditsPerLocation` — integer; required. AI credits per location per month, pooled across locations; what's left expires at the period's end minimum: -9007199254740991; maximum: 9007199254740991
    - `plans[].currency` — string; required. ISO 4217: the billing account's currency (USD or CAD), fixed by the billing address's country at the first purchase and never changed pattern: "^\[A-Z\]\{3\}$"
- `packs` — array; required. AI credit top-ups; bought AI credits never expire
  - `packs[]` — object; optional. 
    - `packs[].pack` — string; required. The top-up pack to buy (get_ai_credits lists the packs) Allowed: "ai\_credits\_1000", "ai\_credits\_2750", "ai\_credits\_6000"
    - `packs[].credits` — integer; required.  minimum: -9007199254740991; maximum: 9007199254740991
    - `packs[].price` — integer; required. Before tax minimum: 0; maximum: 9007199254740991
    - `packs[].currency` — string; required. ISO 4217: the billing account's currency (USD or CAD), fixed by the billing address's country at the first purchase and never changed pattern: "^\[A-Z\]\{3\}$"
- `catalogVersion` — integer; required.  minimum: -9007199254740991; maximum: 9007199254740991
- `operatorTerms` — object; required. 
  - `operatorTerms.currentVersion` — string; required. 
  - `operatorTerms.currentUpdated` — string; required. The date the terms in force were last updated: what people are shown, never currentVersion format: "date"
  - `operatorTerms.current` — boolean; optional. Whether the latest acceptance is of currentVersion: false when nobody has accepted, or the latest acceptance is of an older version (the dashboard then asks a member who may accept to accept the new one). Always sent
  - `operatorTerms.accepted` — object or null; required. The latest acceptance (of any version); null when nobody has accepted them
    - `operatorTerms.accepted.version` — string; required. 
    - `operatorTerms.accepted.acceptedAt` — string; required.  format: "date-time"
    - `operatorTerms.accepted.by` — object; required. 
      - `operatorTerms.accepted.by.id` — string; required. 
      - `operatorTerms.accepted.by.name` — string or null; required. 
- `publishableKey` — string; required. Lokl's own Stripe publishable key, for the Address Element before any write
- `timeZone` — string; required. The organization's time zone, to show billing dates in
- `usage` — object; required. What each location uses of the plan's limits on bookings and staff logins
  - `usage.periodStart` — string; required. When the bookings counted start: the paid period, the trial, or else the calendar month (UTC) format: "date-time"
  - `usage.periodEnd` — string; required. When the count starts again format: "date-time"
  - `usage.locations` — array; required. Every location, including those with none yet
    - `usage.locations[]` — object; optional. 
      - `usage.locations[].locationId` — string; required. 
      - `usage.locations[].name` — string; required. 
      - `usage.locations[].bookings` — object; required. Bookings taken this period: each confirmed order counts once, from when it was confirmed, even if it was canceled later. Going over never stops bookings; Lokl emails the owners at 80% and 100%
        - `usage.locations[].bookings.count` — integer; required.  minimum: 0; maximum: 9007199254740991
        - `usage.locations[].bookings.limit` — integer or null; required. What the plan includes at each location; null is unlimited maximum: 9007199254740991; exclusiveMinimum: 0
      - `usage.locations[].staffLogins` — object; required. People who can sign in to the dashboard here: members whose access reaches this location, plus invitations still open. Past the limit, nobody new can be given access here; nobody already here loses it
        - `usage.locations[].staffLogins.count` — integer; required.  minimum: 0; maximum: 9007199254740991
        - `usage.locations[].staffLogins.limit` — integer or null; required. What the plan includes at each location; null is unlimited maximum: 9007199254740991; exclusiveMinimum: 0

### get_billing_portal_link

Get a link to Stripe's billing portal for the organization: the card Lokl bills, past invoices and receipts, and cancelling the plan at the period's end. The link works once, for a few minutes. Needs billing:write across the organization.

Reads · Members of an organization · Needs billing:write

No input.

#### Output

- `url` — string; required.  format: "uri"

### start_billing_trial

Start Lokl's 30-day free trial for an organization made before billing, which has no billing yet (get_billing answers not_found). No card is needed; the trial's 100 AI credits arrive at once. Refused when the organization already has billing. Needs billing:write across the organization (owner and finance).

Changes · Members of an organization · Needs billing:write

No input.

#### Output

- `status` — string; required.  Value: "trialing"
- `trialEndsAt` — string; required.  format: "date-time"
