Skip to content

Billing

Every project reads its own billing state through the transactions service — subscriptions, invoices, credit balance, and usage pricing. This page covers the part developers actually need day to day: what a project is subscribed to, and which tier (option) it's on for a given integration.


Subscriptions

GET /v1/billing/subscription

Returns every subscription the project has ever had, including expired ones. There is no server-side filtering — callers are expected to check is_active themselves.

import { Platform } from '@ptkl/sdk/beta'

const platform = new Platform()

const { data: subscriptions } = await platform.transactions().getSubscriptions()
const active = subscriptions.filter((s) => s.is_active)
curl -X GET https://lemon.protokol.io/luma/transactions/v1/billing/subscription \
  -H "Authorization: Bearer $PROJECT_API_TOKEN"

transactions() and billing() are the same client — billing() is an alias that reads better at call sites that only care about billing (platform.billing().getSubscriptions()).

Each subscription carries, among other fields:

Field Type Description
product_id string The product this subscription is for. Identifies the integration, not the tier.
option_code string The tier purchased, when the integration has tiers. May be empty. Don't read this field directly to work out a project's active tier — use getActiveOption() (below), which already accounts for the cases where it's empty or stale.
is_active boolean Whether this subscription is currently in effect.
is_expired boolean Whether it has lapsed.
expires_at string \| null ISO-8601 expiry timestamp, or null for non-expiring subscriptions.

Which tier is a project on?

An integration is not always one flat product — many carry an option_set of selectable tiers (e.g. free, standard, premium), each with its own price and enforced limits. A project holds at most one active tier per tiered integration.

Integrations.getActiveOption() is the supported way to find it — one call, every tiered integration the project has installed:

import { Platform } from '@ptkl/sdk/beta'

const platform = new Platform()

const options = await platform.integrations().getActiveOption()

const mailTier = options['protokol-mail']
if (mailTier?.code === 'premium') {
    // …
}

It returns Record<string, ActiveOption | undefined>, keyed by integration id. Integrations with no option_set at all (untiered) are omitted from the result entirely — a missing key means "not tiered."

Each ActiveOption carries:

Field Type Description
code string The resolved tier's code.
option IntegrationOption \| undefined The matching entry from the integration's current option_set, when found.
source 'subscription' \| 'default' 'subscription' when an active, coded subscription resolved the tier; 'default' when there wasn't one to resolve from.

Two things worth designing around:

  • When source is 'subscription', code is reported as-is even if it no longer matches any entry in the integration's current option_set — a tier can be renamed or retired after the code was issued. option is undefined in that case; code is still trustworthy.
  • Treat source: 'default' as unconfirmed for anything billing-sensitive — it means there was no active, coded subscription to resolve from, not that the project has explicitly chosen that tier.

Satisfying requires

A Forge app manifest can declare requires.integrations[].options — the tiers it can work with, as an any-of constraint. The platform enforces that constraint at launch (preflight), but only at launch: an app can be installed on a tier that doesn't satisfy it, and it's the app's own job to explain what each tier unlocks and prompt the user toward it.

getActiveOption() above is how an app's own code answers "am I actually on a tier that satisfies my own requires declaration?" — read the manifest's declared options for an integration, resolve the project's actual code the same way, and compare.


See Also