Class: BraintreeRails::Subscriptions

Inherits:
SimpleDelegator
  • Object
show all
Includes:
CollectionAssociation
Defined in:
lib/braintree_rails/subscriptions.rb

Instance Method Summary collapse

Methods included from CollectionAssociation

included

Constructor Details

#initialize(belongs_to) ⇒ Subscriptions

Returns a new instance of Subscriptions.



5
6
7
8
9
10
11
12
13
# File 'lib/braintree_rails/subscriptions.rb', line 5

def initialize(belongs_to)
  case belongs_to
  when BraintreeRails::CreditCard
    @credit_card = belongs_to
  when BraintreeRails::Plan
    @plan = belongs_to
  end
  super([])
end

Instance Method Details

#default_optionsObject



15
16
17
18
19
20
21
22
23
# File 'lib/braintree_rails/subscriptions.rb', line 15

def default_options
  if @credit_card.present?
    {:payment_method_token => @credit_card.token}
  elsif @plan.present?
    {:plan_id => @plan.id}
  else
    {}
  end
end