Module: Susply::Prorate

Defined in:
app/services/susply/prorate.rb

Class Method Summary collapse

Class Method Details

.calculate_used_amount(plan, used_days) ⇒ Object



14
15
16
17
18
19
20
# File 'app/services/susply/prorate.rb', line 14

def self.calculate_used_amount(plan, used_days)
  if plan.interval == "yearly"
    (plan.price * 1.2 * used_days / 365).ceil
  else
    (plan.price * used_days / 30.0).ceil
  end
end

.call(subscription) ⇒ Object



3
4
5
6
7
8
# File 'app/services/susply/prorate.rb', line 3

def self.call(subscription)
  return 0 unless subscription.active?
  plan = subscription.plan
  days = used_days(subscription)
  calculate_used_amount(plan, days)
end

.used_days(subscription) ⇒ Object



10
11
12
# File 'app/services/susply/prorate.rb', line 10

def self.used_days(subscription)
  (Time.zone.today.to_date - subscription.current_period_start.to_date).to_i
end