Skip to content

feat(#906): implement usage-based billing with metered pricing and tiered overages - #1067

Open
Prozaks wants to merge 2 commits into
Smartdevs17:mainfrom
Prozaks:feat/issue-906-usage-based-billing-metered-pricing
Open

feat(#906): implement usage-based billing with metered pricing and tiered overages#1067
Prozaks wants to merge 2 commits into
Smartdevs17:mainfrom
Prozaks:feat/issue-906-usage-based-billing-metered-pricing

Conversation

@Prozaks

@Prozaks Prozaks commented Aug 28, 2026

Copy link
Copy Markdown

Summary

Implements usage-based billing with metered pricing and tiered overage rating.

Closes #906

Changes

backend/services/billing/metering.ts (new)

Pure off-chain rating engine supporting four pricing models:

  • Flat — fixed rate per unit
  • Graduated — each tier priced independently (customer climbs the ladder)
  • Volume — all units priced at the tier the total usage falls into
  • Package — charged in discrete bundles

Features: included-unit proration, minimum charges, spend caps, per-tier charge breakdowns.

contracts/metering/src/ (updated)

  • register_tiered_meter(): on-chain tiered meter registration
  • quote_usage(): on-chain usage quote returning per-tier breakdown
  • PricingModel / PriceTier types in the contract
  • Existing register_meter() unchanged — now registers a flat meter
  • Off-chain and on-chain arithmetic is identical to ensure client estimates match on-chain settlement

Tests

  • backend/services/billing/__tests__/metering.test.ts: 391 lines covering all pricing model paths, edge cases, and spend cap enforcement
  • contracts/metering/src/test.rs: extended test suite for tiered contract functions

Documentation

  • docs/USAGE_BASED_BILLING.md: full API reference, pricing model examples, migration guide

Acceptance Criteria

  • Feature implemented with full functionality
  • Unit tests added with >80% coverage
  • Integration tests for critical paths
  • No regression introduced
  • Documentation updated
  • Performance benchmarks met

Technical Scope

Covers: contracts/metering/src/, backend/services/billing/metering.ts

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Prozaks 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

…cing and tiered overages

- backend/services/billing/metering.ts: pure rating engine supporting flat,
  graduated, volume, and package pricing with included-unit proration,
  minimum charges, and spend caps
- contracts/metering/src: add register_tiered_meter(), quote_usage(),
  PricingModel/PriceTier ladder with per-tier charge breakdowns
- Existing register_meter() unchanged (registers a flat meter)
- Off-chain and on-chain rating implement identical arithmetic for
  consistency between client estimates and on-chain settlement
- 391 lines of tests covering all pricing model paths
- docs/USAGE_BASED_BILLING.md with API reference and examples

Closes Smartdevs17#906
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 usage-based billing with metered pricing and tiered overages

1 participant