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

#buyerObject



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

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

#subscribed?(stripe_plan_id = nil) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
# File 'app/models/concerns/acts_as_subscribable.rb', line 35

def subscribed?(stripe_plan_id = nil)
  case stripe_plan_id
  when nil
    subscription.present?  # Subscribed to any subscription?
  when (EffectiveOrders.stripe_plans['trial'] || {})[:id]
    subscription.blank? || subscription.new_record? || subscription.stripe_plan_id == stripe_plan_id
  else
    subscription && subscription.persisted? && subscription.errors.blank? && subscription.stripe_plan_id == stripe_plan_id
  end
end

#subscripterObject



27
28
29
# File 'app/models/concerns/acts_as_subscribable.rb', line 27

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

#subscripter=(atts) ⇒ Object



31
32
33
# File 'app/models/concerns/acts_as_subscribable.rb', line 31

def subscripter=(atts)
  subscripter.assign_attributes(atts)
end

#subscription_active?Boolean

Returns:

  • (Boolean)


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

def subscription_active?
  (trialing? && !trial_expired?) || (subscribed? && subscription.active?)
end

#trial_expired?Boolean

Returns:

  • (Boolean)


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

def trial_expired?
  trialing? && Time.zone.now > trial_expires_at
end

#trial_expires_atObject



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

def trial_expires_at
  # The rake task send_trial_expiring_emails depends on this beginning_of_day
  ((created_at || Time.zone.now) + EffectiveOrders.subscription[:trial_period]).beginning_of_day
end

#trialing?Boolean

Returns:

  • (Boolean)


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

def trialing?
  !subscribed?
end