module Reji::ManagesSubscriptions
Public Instance Methods
incomplete_payment?(name = 'default')
click to toggle source
Determine if the customer's subscription has an incomplete payment.
# File lib/reji/concerns/manages_subscriptions.rb, line 50 def incomplete_payment?(name = 'default') subscription = self.subscription(name) subscription ? subscription.incomplete_payment? : false end
new_subscription(name, plans)
click to toggle source
Begin creating a new subscription.
# File lib/reji/concerns/manages_subscriptions.rb, line 12 def new_subscription(name, plans) SubscriptionBuilder.new(self, name, plans) end
on_generic_trial()
click to toggle source
Determine if the Stripe model is on a “generic” trial at the model level.
# File lib/reji/concerns/manages_subscriptions.rb, line 28 def on_generic_trial !!trial_ends_at && trial_ends_at.future? end
on_plan(plan)
click to toggle source
Determine if the entity has a valid subscription on the given plan.
# File lib/reji/concerns/manages_subscriptions.rb, line 72 def on_plan(plan) subscriptions.any? { |subscription| subscription.valid && subscription.plan?(plan) } end
on_trial(name = 'default', plan = nil)
click to toggle source
Determine if the Stripe model is on trial.
# File lib/reji/concerns/manages_subscriptions.rb, line 17 def on_trial(name = 'default', plan = nil) return true if name == 'default' && plan.nil? && on_generic_trial subscription = self.subscription(name) return false unless subscription&.on_trial plan ? subscription.plan?(plan) : true end
plan_tax_rates()
click to toggle source
Get the tax rates to apply to individual subscription items.
# File lib/reji/concerns/manages_subscriptions.rb, line 87 def plan_tax_rates {} end
subscribed(name = 'default', plan = nil)
click to toggle source
Determine if the Stripe model has a given subscription.
# File lib/reji/concerns/manages_subscriptions.rb, line 33 def subscribed(name = 'default', plan = nil) subscription = self.subscription(name) return false unless subscription&.valid? plan ? subscription.plan?(plan) : true end
subscribed_to_plan(plans, name = 'default')
click to toggle source
Determine if the Stripe model is actively subscribed to one of the given plans.
# File lib/reji/concerns/manages_subscriptions.rb, line 57 def subscribed_to_plan(plans, name = 'default') subscription = self.subscription(name) return false unless subscription&.valid? plans = [plans] unless plans.instance_of? Array plans.each do |plan| return true if subscription.plan?(plan) end false end
subscription(name = 'default')
click to toggle source
Get a subscription instance by name.
# File lib/reji/concerns/manages_subscriptions.rb, line 42 def subscription(name = 'default') subscriptions .sort_by { |subscription| subscription.created_at.to_i } .reverse .find { |subscription| subscription.name == name } end
tax_percentage()
click to toggle source
Get the tax percentage to apply to the subscription.
# File lib/reji/concerns/manages_subscriptions.rb, line 77 def tax_percentage 0 end
tax_rates()
click to toggle source
Get the tax rates to apply to the subscription.
# File lib/reji/concerns/manages_subscriptions.rb, line 82 def tax_rates [] end