Skip to content

feat(billing): subscription billing with usage metering - #989

Merged
github-actions[bot] merged 2 commits into
Smartdevs17:mainfrom
davidsoniaudin2-oss:feat/914-subscription-usage-metering
Sep 28, 2026
Merged

github-actions[bot] merged 2 commits into
Smartdevs17:mainfrom
davidsoniaudin2-oss:feat/914-subscription-usage-metering

Conversation

@davidsoniaudin2-oss

Copy link
Copy Markdown
Contributor

Summary

Closes #914.

Adds subscription plans with a recurring base price and included usage allowance, plus metered overage billed per billing period.

What changed

  • backend/src/services/subscription-billing.ts — SubscriptionBillingService: plans (flat or graduated tiers), subscriptions with optional trials, idempotent usage events, usage summaries, invoice generation with itemized base + metered lines, period rollover that resets counters, and cancel-at-period-end.
  • backend/src/routes/subscription-billing.ts — REST API mounted at /api/v1/billing (plans, subscriptions, usage, invoices).
  • backend/src/index.ts — router registration.
  • docs/SUBSCRIPTION_USAGE_BILLING.md — feature documentation including pricing rules.

Behaviour notes

  • Included units are free; overage is charged at overageUnitPrice or progressively through tiers, with usage past the last tier falling back to the flat rate.
  • Recording usage with the same idempotencyKey returns the original event instead of double-counting.
  • close-period invoices the period, rolls the subscription forward and clears usage.

Tests

backend/src/services/__tests__/subscription-billing.test.ts — 24 tests covering plan validation, subscription/trial creation, aggregation, idempotency, flat and graduated overage math, invoices, period rollover, and transitions. All passing; typecheck and lint clean for the new files.

Verification

cd backend && npx vitest run src/services/__tests__/subscription-billing.test.ts

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

@davidsoniaudin2-oss is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@davidsoniaudin2-oss Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

davidsoniaudin2-oss and others added 2 commits September 28, 2026 03:46
)

Adds plans with recurring base fees and included usage allowances,
idempotent usage-event ingestion, graduated/flat overage pricing,
invoice generation with itemized base and metered lines, period rollover
that resets counters, and cancel-at-period-end handling.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@davidsoniaudin2-oss
davidsoniaudin2-oss force-pushed the feat/914-subscription-usage-metering branch from 55da1a8 to 70befd5 Compare September 28, 2026 03:46
@github-actions
github-actions Bot merged commit 39c4d6c into Smartdevs17:main Sep 28, 2026
14 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement subscription billing with usage metering

1 participant