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_buyerObject



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

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_usedObject



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

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)


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

#subscripterObject



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

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)


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

#subscription_trialing?Boolean

If we do use stripe

Returns:

  • (Boolean)


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

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

#trial_active?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/concerns/acts_as_subscribable.rb', line 73

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

#trial_past_due?Boolean

Returns:

  • (Boolean)


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

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

#trialing?Boolean

If we don’t use stripe

Returns:

  • (Boolean)


69
70
71
# File 'app/models/concerns/acts_as_subscribable.rb', line 69

def trialing?
  subscription_status.blank?
end