Class: Braintree::Subscription

Inherits:
Object
  • Object
show all
Includes:
BaseModule
Defined in:
lib/braintree/subscription.rb

Overview

Defined Under Namespace

Modules: Status, TrialDurationUnit

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseModule

included

Methods included from BaseModule::Methods

#copy_instance_variables_from_object, #return_object_or_raise, #set_instance_variables_from_hash, #singleton_class

Constructor Details

#initialize(gateway, attributes) ⇒ Subscription

:nodoc:



70
71
72
73
74
75
76
77
78
79
# File 'lib/braintree/subscription.rb', line 70

def initialize(gateway, attributes) # :nodoc:
  @gateway = gateway
  set_instance_variables_from_hash(attributes)
  @balance = Util.to_big_decimal(balance)
  @price = Util.to_big_decimal(price)
  @descriptor = Descriptor.new(@descriptor)
  transactions.map! { |attrs| Transaction._new(gateway, attrs) }
  add_ons.map! { |attrs| AddOn._new(attrs) }
  discounts.map! { |attrs| Discount._new(attrs) }
end

Instance Attribute Details

#add_onsObject (readonly)

Returns the value of attribute add_ons



29
30
31
# File 'lib/braintree/subscription.rb', line 29

def add_ons
  @add_ons
end

#balanceObject (readonly)

Returns the value of attribute balance



23
24
25
# File 'lib/braintree/subscription.rb', line 23

def balance
  @balance
end

#billing_day_of_monthObject (readonly)

Returns the value of attribute billing_day_of_month



28
29
30
# File 'lib/braintree/subscription.rb', line 28

def billing_day_of_month
  @billing_day_of_month
end

#billing_period_end_dateObject (readonly)

Returns the value of attribute billing_period_end_date



22
23
24
# File 'lib/braintree/subscription.rb', line 22

def billing_period_end_date
  @billing_period_end_date
end

#billing_period_start_dateObject (readonly)

Returns the value of attribute billing_period_start_date



22
23
24
# File 'lib/braintree/subscription.rb', line 22

def billing_period_start_date
  @billing_period_start_date
end

#current_billing_cycleObject (readonly)

Returns the value of attribute current_billing_cycle



31
32
33
# File 'lib/braintree/subscription.rb', line 31

def current_billing_cycle
  @current_billing_cycle
end

#days_past_dueObject (readonly)

Returns the value of attribute days_past_due



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def days_past_due
  @days_past_due
end

#descriptorObject (readonly)

Returns the value of attribute descriptor



30
31
32
# File 'lib/braintree/subscription.rb', line 30

def descriptor
  @descriptor
end

#discountsObject (readonly)

Returns the value of attribute discounts



29
30
31
# File 'lib/braintree/subscription.rb', line 29

def discounts
  @discounts
end

#failure_countObject (readonly)

Returns the value of attribute failure_count



25
26
27
# File 'lib/braintree/subscription.rb', line 25

def failure_count
  @failure_count
end

#first_billing_dateObject (readonly)

Returns the value of attribute first_billing_date



22
23
24
# File 'lib/braintree/subscription.rb', line 22

def first_billing_date
  @first_billing_date
end

#idObject (readonly)

Returns the value of attribute id



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def id
  @id
end

#merchant_account_idObject (readonly)

Returns the value of attribute merchant_account_id



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def 
  @merchant_account_id
end

#next_billing_dateObject (readonly)

Returns the value of attribute next_billing_date



22
23
24
# File 'lib/braintree/subscription.rb', line 22

def next_billing_date
  @next_billing_date
end

#next_billing_period_amountObject (readonly)

Returns the value of attribute next_billing_period_amount



27
28
29
# File 'lib/braintree/subscription.rb', line 27

def next_billing_period_amount
  @next_billing_period_amount
end

#number_of_billing_cyclesObject (readonly)

Returns the value of attribute number_of_billing_cycles



28
29
30
# File 'lib/braintree/subscription.rb', line 28

def number_of_billing_cycles
  @number_of_billing_cycles
end

Returns the value of attribute paid_through_date



23
24
25
# File 'lib/braintree/subscription.rb', line 23

def paid_through_date
  @paid_through_date
end

#payment_method_tokenObject (readonly)

Returns the value of attribute payment_method_token



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def payment_method_token
  @payment_method_token
end

#plan_idObject (readonly)

Returns the value of attribute plan_id



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def plan_id
  @plan_id
end

#priceObject (readonly)

Returns the value of attribute price



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def price
  @price
end

#statusObject (readonly)

Returns the value of attribute status



21
22
23
# File 'lib/braintree/subscription.rb', line 21

def status
  @status
end

#transactionsObject (readonly)

Returns the value of attribute transactions



26
27
28
# File 'lib/braintree/subscription.rb', line 26

def transactions
  @transactions
end

#trial_durationObject (readonly)

Returns the value of attribute trial_duration



24
25
26
# File 'lib/braintree/subscription.rb', line 24

def trial_duration
  @trial_duration
end

#trial_duration_unitObject (readonly)

Returns the value of attribute trial_duration_unit



24
25
26
# File 'lib/braintree/subscription.rb', line 24

def trial_duration_unit
  @trial_duration_unit
end

#trial_periodObject (readonly)

Returns the value of attribute trial_period



24
25
26
# File 'lib/braintree/subscription.rb', line 24

def trial_period
  @trial_period
end

Class Method Details

._new(*args) ⇒ Object

:nodoc:



98
99
100
# File 'lib/braintree/subscription.rb', line 98

def _new(*args) # :nodoc:
  self.new *args
end

.cancel(subscription_id) ⇒ Object



34
35
36
# File 'lib/braintree/subscription.rb', line 34

def self.cancel(subscription_id)
  Configuration.gateway.subscription.cancel(subscription_id)
end

.create(attributes) ⇒ Object



39
40
41
# File 'lib/braintree/subscription.rb', line 39

def self.create(attributes)
  Configuration.gateway.subscription.create(attributes)
end

.create!(attributes) ⇒ Object



43
44
45
# File 'lib/braintree/subscription.rb', line 43

def self.create!(attributes)
  return_object_or_raise(:subscription) { create(attributes) }
end

.find(id) ⇒ Object



48
49
50
# File 'lib/braintree/subscription.rb', line 48

def self.find(id)
  Configuration.gateway.subscription.find(id)
end

.retry_charge(subscription_id, amount = nil) ⇒ Object



52
53
54
# File 'lib/braintree/subscription.rb', line 52

def self.retry_charge(subscription_id, amount=nil)
  Configuration.gateway.transaction.retry_subscription_charge(subscription_id, amount)
end

.search(&block) ⇒ Object



57
58
59
# File 'lib/braintree/subscription.rb', line 57

def self.search(&block)
  Configuration.gateway.subscription.search(&block)
end

.update(subscription_id, attributes) ⇒ Object



62
63
64
# File 'lib/braintree/subscription.rb', line 62

def self.update(subscription_id, attributes)
  Configuration.gateway.subscription.update(subscription_id, attributes)
end

.update!(subscription_id, attributes) ⇒ Object



66
67
68
# File 'lib/braintree/subscription.rb', line 66

def self.update!(subscription_id, attributes)
  return_object_or_raise(:subscription) { update(subscription_id, attributes) }
end

Instance Method Details

#==(other) ⇒ Object

True if other has the same id.



91
92
93
94
# File 'lib/braintree/subscription.rb', line 91

def ==(other)
  return false unless other.is_a?(Subscription)
  id == other.id
end

#never_expires?Boolean



86
87
88
# File 'lib/braintree/subscription.rb', line 86

def never_expires?
  @never_expires
end

#next_bill_amountObject



81
82
83
84
# File 'lib/braintree/subscription.rb', line 81

def next_bill_amount
  warn "[DEPRECATED] Subscription.next_bill_amount is deprecated. Please use Subscription.next_billing_period_amount"
  @next_bill_amount
end