Module: ActsAsSubscribable

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/acts_as_subscribable.rb

Defined Under Namespace

Modules: ActiveRecord, ClassMethods

Instance Method Summary collapse

Instance Method Details

#subscribable_buyer ⇒ Object



75
76
77
# File 'app/models/concerns/acts_as_subscribable.rb', line 75

def subscribable_buyer
  raise 'acts_as_subscribable object requires the subscribable_buyer method be defined to return the User buying this item.'
end

#subscribed?(stripe_plan_id = nil) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'app/models/concerns/acts_as_subscribable.rb', line 50

def subscribed?(stripe_plan_id = nil)
  return false if subscription_status.blank?
  stripe_plan_id ? (subscription&.stripe_plan_id == stripe_plan_id) : true
end

#subscripter ⇒ Object



46
47
48
# File 'app/models/concerns/acts_as_subscribable.rb', line 46

def subscripter
  @_effective_subscripter ||= Effective::Subscripter.new(subscribable: self, user: subscribable_buyer)
end

#subscription_active? ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/concerns/acts_as_subscribable.rb', line 55

def subscription_active?
  subscribed? && subscription_status == EffectiveOrders::ACTIVE
end

#subscription_past_due? ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/concerns/acts_as_subscribable.rb', line 59

def subscription_past_due?
  subscribed? && subscription_status == EffectiveOrders::PAST_DUE
end

#trial_active? ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/concerns/acts_as_subscribable.rb', line 67

def trial_active?
  trialing? && trialing_until > Time.zone.now
end

#trial_past_due? ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/concerns/acts_as_subscribable.rb', line 71

def trial_past_due?
  trialing? && trialing_until < Time.zone.now
end

#trialing? ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/concerns/acts_as_subscribable.rb', line 63

def trialing?
  subscription_status.blank?
end