Skip to content

Refactor subscription billing engine to strategy pattern for pluggable pricing #574

Description

@Smartdevs17

Context

The billing engine uses a large switch-case for pricing model selection, making it difficult to extend or test individual pricing strategies.

Current Limitation/Problem

Adding a new pricing model (tiered usage, hybrid, custom) requires modifying the core billing engine file, risking regressions across all pricing models.

Expected Outcome

Strategy pattern: each pricing model is a separate class implementing a common PricingStrategy interface, registered in a dynamic strategy registry.

Acceptance Criteria

  • PricingStrategy interface: calculate(usage, plan, subscriber) -> Amount
  • Extract FlatPricingStrategy, PerSeatPricingStrategy, UsageBasedPricingStrategy, TieredPricingStrategy
  • Strategy registry with dynamic lookup by plan type code
  • All existing billing tests pass without modification
  • New strategy can be added as a single file without touching existing code
  • Performance: no regression in billing calculation time (measured <5ms per invoice)
  • Edge case: fallback strategy for unknown/unsupported plan types

Technical Scope

  • backend/billing/domain/strategies/ - individual strategy class files
  • backend/billing/domain/ - BillingEngine refactored to delegate to strategy
  • backend/billing/domain/ - PricingStrategy interface and StrategyRegistry
  • backend/billing/tests/ - strategy-specific test files with >90% coverage

Metadata

Metadata

Assignees

Labels

200-points200 point issueStellar WaveIssues in the Stellar wave programdrips-waveIssues in the Drips Wave programhighHigh complexity issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions