Module: Pay::Billable

Extended by:
ActiveSupport::Concern
Defined in:
lib/pay/billable.rb,
lib/pay/billable/stripe.rb,
lib/pay/billable/braintree.rb

Defined Under Namespace

Modules: Braintree, Stripe

Instance Method Summary collapse

Instance Method Details

#customer(token = nil) ⇒ Object



19
20
21
22
# File 'lib/pay/billable.rb', line 19

def customer(token = nil)
  check_for_processor
  send("#{processor}_customer", token)
end

#processor_subscription(subscription_id) ⇒ Object



34
35
36
37
# File 'lib/pay/billable.rb', line 34

def processor_subscription(subscription_id)
  check_for_processor
  send("#{processor}_subscription", subscription_id)
end

#subscribe(name = 'default', plan = 'default', processor = 'stripe') ⇒ Object



24
25
26
27
# File 'lib/pay/billable.rb', line 24

def subscribe(name = 'default', plan = 'default', processor = 'stripe')
  self.processor = processor
  send("create_#{processor}_subscription", name, plan)
end

#subscribed?(name = 'default', plan = nil) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/pay/billable.rb', line 39

def subscribed?(name = 'default', plan = nil)
  subscription = subscription(name)

  return false if subscription.nil?
  return subscription.active? if plan.nil?

  subscription.active? && subscription.plan == plan
end

#subscription(name = 'default') ⇒ Object



48
49
50
# File 'lib/pay/billable.rb', line 48

def subscription(name = 'default')
  subscriptions.for_name(name).last
end

#update_card(token) ⇒ Object



29
30
31
32
# File 'lib/pay/billable.rb', line 29

def update_card(token)
  check_for_processor
  send("update_#{processor}_card", token)
end