Skip to content

feat(billing): requireQuota middleware for plan-based limits #3270

@PierreBrisorgueil

Description

@PierreBrisorgueil

Context

Downstream projects need to enforce per-plan limits (e.g. max scraps, executions/month).

Spec

  • New middleware: requireQuota(resource, action)
  • Reads quota config from config.billing.quotas[plan][resource][action]
  • Checks current usage via BillingUsage service
  • Returns 429 { type: 'QUOTA_EXCEEDED', resource, action, limit, current, upgradeUrl } if over limit
  • Org without subscription → treated as free
  • Subscription past_due → treated as free

Config format (each project provides its own)

quotas: {
  free: { scraps: { create: 3, execute: 100 } },
  starter: { scraps: { create: 20, execute: 2000 } },
  pro: { scraps: { create: Infinity, execute: Infinity } }
}

Acceptance

  • Middleware + tests
  • Works with any project's quota config
  • Depends on: BillingUsage model

Metadata

Metadata

Assignees

No one assigned

    Labels

    billingPhase 3 — Stripe billing integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions