Module: RedLine::Subscription::InstanceMethods
- Defined in:
- lib/redline/subscription/instance.rb
Instance Method Summary collapse
- #next_due ⇒ Object
- #paid_plan? ⇒ Boolean
- #past_due ⇒ Object
- #past_grace? ⇒ Boolean
- #pay ⇒ Object
- #plan ⇒ Object
- #plan=(plan) ⇒ Object
- #set_plan ⇒ Object
- #trial? ⇒ Boolean
Instance Method Details
#next_due ⇒ Object
32 33 34 |
# File 'lib/redline/subscription/instance.rb', line 32 def next_due paid_plan? && [trial? && trial_until || nil, paid_until, Date.today].compact.max end |
#paid_plan? ⇒ Boolean
26 27 28 |
# File 'lib/redline/subscription/instance.rb', line 26 def paid_plan? plan[:price] > 0 end |
#past_due ⇒ Object
35 36 37 38 39 |
# File 'lib/redline/subscription/instance.rb', line 35 def past_due due_date = [trial? && trial_until || nil, paid_until].compact.max amount = (due_date && (Date.today - due_date) || 0).days paid_plan? && amount > 0 && amount end |
#past_grace? ⇒ Boolean
23 24 25 |
# File 'lib/redline/subscription/instance.rb', line 23 def past_grace? past_due && past_due >= self.class.billing_settings[:grace_period] end |
#pay ⇒ Object
19 20 21 22 |
# File 'lib/redline/subscription/instance.rb', line 19 def pay self.customer.sale!(:amount => ("%0.2f" % plan[:price]), :options => {:submit_for_settlement => true}) self.paid_until = Date.today + self.class.billing_settings[:period] - (past_due || 0) end |
#plan ⇒ Object
4 5 6 |
# File 'lib/redline/subscription/instance.rb', line 4 def plan self.class.subscription_plans[(subscription_key || self.class.default_subscription_plan).to_sym] end |
#plan=(plan) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/redline/subscription/instance.rb', line 7 def plan=(plan) if (plan.is_a?(String) || plan.is_a?(Symbol)) && self.class.subscription_plans.keys.include?(plan.to_sym) self.subscription_key = plan elsif plan.is_a?(Hash) self.subscription_key = self.class.subscription_plans.index(plan) end self.paid_until = Date.today self.trial_until ||= Date.today + self.class.trial_settings[:period] if trial? end |
#set_plan ⇒ Object
16 17 18 |
# File 'lib/redline/subscription/instance.rb', line 16 def set_plan self.subscription_key ||= self.class.default_subscription_plan end |
#trial? ⇒ Boolean
29 30 31 |
# File 'lib/redline/subscription/instance.rb', line 29 def trial? self.class.trial_settings[:period] > 0.days end |