Module: SubscriptionFu::Models::InstanceMethods

Defined in:
lib/subscription_fu/models.rb

Instance Method Summary collapse

Instance Method Details

#active_subscriptionObject



21
22
23
# File 'lib/subscription_fu/models.rb', line 21

def active_subscription
  @active_subscription ||= subscriptions.current(Time.now).last
end

#active_subscription?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/subscription_fu/models.rb', line 25

def active_subscription?
  !active_subscription.nil?
end

#build_next_subscription(plan_key) ⇒ Object



43
44
45
# File 'lib/subscription_fu/models.rb', line 43

def build_next_subscription(plan_key)
  subscriptions.build_for_initializing(plan_key, active_subscription)
end

#human_description_for_subscriptionObject



17
18
19
# File 'lib/subscription_fu/models.rb', line 17

def human_description_for_subscription
  self.class.model_name.human
end

#pending_transaction(identifier) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/subscription_fu/models.rb', line 33

def pending_transaction(identifier)
  sub = subscriptions.last
  if sub.activated?
    logger.info("Latest subscription is already activated")
    nil
  else
    sub.transactions.initiated.find_by_identifier(identifier)
  end
end

#upcoming_subscriptionObject



29
30
31
# File 'lib/subscription_fu/models.rb', line 29

def upcoming_subscription
  active_subscription ? active_subscription.next_subscriptions.activated.last : nil
end