Module: ActsAsSubscribable

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

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#subscribable_buyer ⇒ Object



88
89
90
# File 'app/models/concerns/acts_as_subscribable.rb', line 88

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

#subscribable_quantity_used ⇒ Object



92
93
94
# File 'app/models/concerns/acts_as_subscribable.rb', line 92

def subscribable_quantity_used
  raise 'acts_as_subscribable object requires the subscribable_quantity_used method be defined to determine how many are in use.'
end

#subscribed?(stripe_plan_id = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

def subscripter
  @_effective_subscripter ||= begin
    Effective::Subscripter.new(subscribable: self, user: subscribable_buyer, quantity: subscription&.quantity, stripe_plan_id: subscription&.stripe_plan_id)
  end
end

#subscription_active? ⇒ Boolean

Returns:

  • (Boolean)


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

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

#subscription_past_due? ⇒ Boolean

Returns:

  • (Boolean)


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

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

#subscription_trialing? ⇒ Boolean

If we do use stripe

Returns:

  • (Boolean)


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

def subscription_trialing?
  subscribed? && subscription_status == EffectiveOrders::TRIALING
end

#trial_active? ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/concerns/acts_as_subscribable.rb', line 80

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

#trial_past_due? ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/models/concerns/acts_as_subscribable.rb', line 84

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

#trialing? ⇒ Boolean

If we don't use stripe

Returns:

  • (Boolean)


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

def trialing?
  subscription_status.blank?
end