Class: Profitable::Processors::PaddleBillingProcessor
- Defined in:
- lib/profitable/processors/paddle_billing_processor.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#initialize, subscription_data
Constructor Details
This class inherits a constructor from Profitable::Processors::Base
Instance Method Details
#calculate_mrr ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/profitable/processors/paddle_billing_processor.rb', line 4 def calculate_mrr data = subscription_data return 0 if data.nil? items = data['items'] return 0 if items.nil? || items.empty? # Sum MRR from ALL subscription items total_mrr = 0 items.each do |item| price_data = item['price'] next if price_data.nil? amount = price_data.dig('unit_price', 'amount') next if amount.nil? # Paddle can also serialize amounts as strings; coerce before applying quantity. item_quantity = item['quantity'] || 1 interval = price_data.dig('billing_cycle', 'interval') interval_count = price_data.dig('billing_cycle', 'frequency') total_mrr += normalize_to_monthly(amount.to_f * item_quantity, interval, interval_count) end total_mrr end |