main
rb 31 lines 1.09 KB
Raw
1 # frozen_string_literal: true
2
3 # Business rollups over local Subscription state for the admin console. Stripe is
4 # the source of truth for money; these are directional in-app estimates so the
5 # operator can see recurring revenue without a Stripe round-trip.
6 #
7 # MONTHLY_PRICE_USD mirrors the published list price (siGit Code Pro is $20/mo).
8 # Trials are excluded from MRR since they aren't billing yet. Update these knobs
9 # if list pricing changes.
10 module BillingMetrics
11 MONTHLY_PRICE_USD = { "pro" => 20, "team" => 40 }.freeze
12
13 module_function
14
15 # Directional monthly recurring revenue: sum of list prices over paid plans in
16 # good standing (active only — trials aren't paying yet).
17 def estimated_mrr
18 # group(:plan) returns the enum's string labels ("pro", "team") as keys.
19 counts = Subscription
20 .where(status: :active)
21 .where.not(plan: :free)
22 .group(:plan).count
23
24 counts.sum { |plan, n| (MONTHLY_PRICE_USD[plan] || 0) * n }
25 end
26
27 # Monthly price for a plan name, 0 when unpriced (e.g. free).
28 def price_for(plan)
29 MONTHLY_PRICE_USD.fetch(plan.to_s, 0)
30 end
31 end