@haatlabs-core/nest-billing
The billing every app shares: the plan in force and its period, usage counted once per key
under a per-organization lock, plan assignment and seeding, gateway prices, payment events
applied once and in order, and feature switches. An app passes its own tables (built from
@haatlabs-core/db-core's billing column sets) and its catalog: what it counts, what it caps,
and what a plan may leave out.
stores (optional): the app's stores, for Shopify billing (charging a store through Shopify).
A web app leaves it out, and the module then has no Shopify billing routes or service.
Who may change the plan: buying, changing and cancelling it (POST billing/checkout,
billing/cancel, and Shopify billing's checkout, confirm and cancel) is the whole
organization's. The staff of one store in an organization made on the dashboard (a
store-only principal, me.storeOnly) are refused with 403 FORBIDDEN and
PLAN_CHANGES_MESSAGE ("Plan changes are made by the account's owner"); they still read
GET usage and GET plans. An app's plan page hides its buttons from them.
Test charges: a Shopify charge is a test charge when SHOPIFY_BILLING_TEST is true or the
shop is a partner development store, which Shopify is asked with the store's own token at
checkout (shop { plan { partnerDevelopment } }); a real store gets a real charge. A
development store's approved test charge puts it on the plan. When Shopify does not answer
that question, nothing is charged or changed: the request fails with a transient 503.
shopifyThrottle (optional): the app's RedisShopifyThrottle, so Shopify billing paces each
shop with the app's own jobs; without it, the process throttle. billingThrottleMaxWaitMs
(default 10 s) is the longest a billing call waits there for its turn, not the throttle's
minute, since a merchant is waiting on the page; it then goes.
Install
pnpm add @haatlabs-core/nest-billing
It leaves these packages to your app, so the app holds one copy: @nestjs/common, @nestjs/core, drizzle-orm, fastify, reflect-metadata, rxjs, zod.