feat(billing): proration, dunning, promo codes and metered pricing (#812 #813 #814 #815) - #992
Merged
github-actions[bot] merged 1 commit intoSep 28, 2026
Conversation
- Prorate mid-cycle plan changes with create_prorations, always_invoice and none behaviours, plus a change preview (Smartdevs17#812) - Dunning with merchant-configurable retry schedules, payment attempts, automated retry processing and final actions (Smartdevs17#813) - Promo codes with percent/fixed discounts, once/repeating/forever durations and redemption limits (Smartdevs17#814) - Per-metric metered pricing with sum/max/last aggregation and per-unit, package, graduated and volume models (Smartdevs17#815) Closes Smartdevs17#812, closes Smartdevs17#813, closes Smartdevs17#814, closes Smartdevs17#815
|
@olathedev is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@olathedev 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #812
Closes #813
Closes #814
Closes #815
Builds on the subscription billing service from #914 and adds four billing capabilities. The pricing logic for each lives in a small pure module under
backend/src/services/billing/.SubscriptionBillingServiceconnects them to plans, subscriptions and invoices.#815 — Usage-based billing with metered pricing
meters, one metered price per metric.sum,maxorlast.per_unit,package,graduatedandvolume. Tiers can have aflatFee, and the last tier must be open-ended.includedUnits.GET /subscriptions/:id/usagereturns a per-meter breakdown.#812 — Proration for mid-cycle plan changes
POST /subscriptions/:id/change-planandGET /subscriptions/:id/change-plan/preview.unusedCredit,remainingChargeandnet.create_prorations(default): the closing invoice carries prorated base lines for each plan.always_invoice: the old plan's elapsed time and its usage are invoiced immediately.none: the whole period is billed on the new plan.noneis rejected for interval changes.#814 — Promotional codes and discounts
/promo-codes.promoCode) or later viaPOST/DELETE /subscriptions/:id/discount.percentorfixed(currency must match the plan).once,repeatingfor N periods, orforever.subtotal,discountAmountanddiscountCode.#813 — Dunning management with configurable retry schedules
GET/PUT /dunning/config/:merchantId. The default schedule is retries at days[1, 3, 5, 7]; it is validated to be ascending, at most 10 retries and within 60 days.POST /invoices/:id/payment-attemptsrecords an attempt. The first failure starts dunning and moves the subscription topast_due.POST /dunning/processretries due invoices through a pluggable payment attempter (setPaymentAttempter). An attempter that throws counts as a failed attempt.dunning.history.recovered.stopped.uncollectibleand the final action runs:cancel_subscription(default) ormark_uncollectible.active.Behaviour changes to existing code
past_duesubscriptions can still record usage, since service continues while dunning runs. Cancelled subscriptions are still rejected.InvoiceStatusgainsuncollectible. Such an invoice can still be paid.kind,subtotal,discountAmount,discountCodeanddunning. Existing fields and line items are unchanged for plans without these features.Tests
backend/src/services/billing/__tests__/{metered-pricing,proration,discounts,dunning}.test.ts: unit tests for the pricing logic, covering success and failure cases.backend/src/services/__tests__/subscription-billing-lifecycle.test.ts: tests of the full flows through the service for all four features, covering success and failure cases.subscription-billing.test.tsis unchanged.Docs
docs/SUBSCRIPTION_USAGE_BILLING.mdnow documents all new endpoints and behaviour.🤖 Generated with Claude Code