Module: Billing
Composable usage metering, invoice generation, and payment processing with Stripe. Records usage events with per-metric tracking, aggregates by customer and billing period with per-unit, tiered, and flat pricing, generates invoices, charges them with idempotent Stripe writes, and verifies and dispatches Stripe webhooks through a pluggable provider registry. Ships with a Stripe provider and an in-memory mock for testing that starts only when named.
| Name | module-billing-ts |
| Version | 0.1.0 |
| Category | composable-modules |
| License | Apache-2.0 |
| Persona | engineering |
| Tags | billing, payments, stripe, metering, invoicing, typescript |
| Source | templates/module-billing-ts |
Render it
Three front doors, one catalog. Pick whichever suits the caller.
# CLI
npx @nanohype/sdk render module-billing-ts --out ./my-app
# SDK
import { LocalSource, renderTemplate } from "@nanohype/sdk";
const result = await renderTemplate(source, "module-billing-ts", variables);
# MCP — from an agent
get_template({ name: "module-billing-ts" })Prerequisites
| Tool | Version | Why |
|---|---|---|
node | >=26 | Node.js runtime for the billing module |
Variables
Required
ProjectNamestring- Kebab-case project name, used as package name and directory Must be lowercase kebab-case starting with a letter.
Optional
Descriptionstring — defaults toUsage metering and billing with Stripe- Short project description for package.json and README
PaymentProviderstring — defaults tostripe- Payment provider used when the config names none (stripe, mock, or a custom name); the mock still starts only when named
What it produces
42 files. Placeholder names such as __APP_NAME__ are what the renderer substitutes into.
.env.example
.gitignore
biome.json
package.json
README.md
src/billing/__tests__/billing-service.test.ts
src/billing/__tests__/circuit-breaker.test.ts
src/billing/__tests__/default-provider.test.ts
src/billing/__tests__/fake-stripe.ts
src/billing/__tests__/invoicing.test.ts
src/billing/__tests__/metering.test.ts
src/billing/__tests__/readme-custom-provider.ts
src/billing/__tests__/readme.test.ts
src/billing/__tests__/registry.test.ts
src/billing/__tests__/stripe.test.ts
src/billing/__tests__/webhook.test.ts
src/billing/bootstrap.ts
src/billing/config.ts
src/billing/index.ts
src/billing/invoicing/content.ts
src/billing/invoicing/formatter.ts
src/billing/invoicing/generator.ts
src/billing/invoicing/types.ts
src/billing/logger.ts
src/billing/metering/aggregator.ts
src/billing/metering/tracker.ts
src/billing/metering/types.ts
src/billing/metrics.ts
src/billing/providers/errors.ts
src/billing/providers/index.ts
src/billing/providers/mock.ts
src/billing/providers/registry.ts
src/billing/providers/stripe-config.ts
src/billing/providers/stripe.ts
src/billing/providers/types.ts
src/billing/resilience/circuit-breaker.ts
src/billing/subscriptions.ts
src/billing/types.ts
src/billing/webhooks/handler.ts
tsconfig.build.json
tsconfig.json
vitest.config.tsComposes with
- Pairs with
ts-service - Pairs with
module-webhook-ts - Pairs with
module-queue-ts - Nests inside
monorepo
Composites that use it
- AI Platform — Full AI platform with HTTP service, LLM gateway, vector store, data pipeline, auth, billing, monitoring, and a Platform tenant chart whose ModelGateway serves the gateway's and the pipeline's model routes.