Class: Braintree::Subscription

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

Defined Under Namespace

Modules: Source, Status, TrialDurationUnit Classes: StatusDetails

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::IdEquality

#==

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:


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/braintree/subscription.rb', line 94

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) }
  @status_history = attributes[:status_history] ? attributes[:status_history].map { |s| StatusDetails.new(s) } : []
  @first_billing_date = Date.parse(first_billing_date) unless first_billing_date.nil?
  @next_billing_date = Date.parse(next_billing_date) unless next_billing_date.nil?
  @billing_period_start_date = Date.parse(billing_period_start_date) unless billing_period_start_date.nil?
  @billing_period_end_date = Date.parse(billing_period_end_date) unless billing_period_end_date.nil?
  @paid_through_date = Date.parse(paid_through_date) unless paid_through_date.nil?
end

Instance Attribute Details

#add_onsObject (readonly)

Returns the value of attribute add_ons.


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

def add_ons
  @add_ons
end

#balanceObject (readonly)

Returns the value of attribute balance.


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

def balance
  @balance
end

#billing_day_of_monthObject (readonly)

Returns the value of attribute billing_day_of_month.


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

def billing_day_of_month
  @billing_day_of_month
end

#billing_period_end_dateObject (readonly)

Returns the value of attribute billing_period_end_date.


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

def billing_period_end_date
  @billing_period_end_date
end

#billing_period_start_dateObject (readonly)

Returns the value of attribute billing_period_start_date.


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

def billing_period_start_date
  @billing_period_start_date
end

#created_atObject (readonly)

Returns the value of attribute created_at.


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

def created_at
  @created_at
end

#current_billing_cycleObject (readonly)

Returns the value of attribute current_billing_cycle.


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

def current_billing_cycle
  @current_billing_cycle
end

#days_past_dueObject (readonly)

Returns the value of attribute days_past_due.


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

def days_past_due
  @days_past_due
end

#descriptionObject (readonly)

Returns the value of attribute description.


36
37
38
# File 'lib/braintree/subscription.rb', line 36

def description
  @description
end

#descriptorObject (readonly)

Returns the value of attribute descriptor.


37
38
39
# File 'lib/braintree/subscription.rb', line 37

def descriptor
  @descriptor
end

#discountsObject (readonly)

Returns the value of attribute discounts.


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

def discounts
  @discounts
end

#failure_countObject (readonly)

Returns the value of attribute failure_count.


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

def failure_count
  @failure_count
end

#first_billing_dateObject (readonly)

Returns the value of attribute first_billing_date.


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

def first_billing_date
  @first_billing_date
end

#idObject (readonly)

Returns the value of attribute id.


41
42
43
# File 'lib/braintree/subscription.rb', line 41

def id
  @id
end

#merchant_account_idObject (readonly)

Returns the value of attribute merchant_account_id.


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

def 
  @merchant_account_id
end

#next_billing_dateObject (readonly)

Returns the value of attribute next_billing_date.


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

def next_billing_date
  @next_billing_date
end

#next_billing_period_amountObject (readonly)

Returns the value of attribute next_billing_period_amount.


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

def next_billing_period_amount
  @next_billing_period_amount
end

#number_of_billing_cyclesObject (readonly)

Returns the value of attribute number_of_billing_cycles.


45
46
47
# File 'lib/braintree/subscription.rb', line 45

def number_of_billing_cycles
  @number_of_billing_cycles
end

Returns the value of attribute paid_through_date.


46
47
48
# File 'lib/braintree/subscription.rb', line 46

def paid_through_date
  @paid_through_date
end

#payment_method_tokenObject (readonly)

Returns the value of attribute payment_method_token.


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

def payment_method_token
  @payment_method_token
end

#plan_idObject (readonly)

Returns the value of attribute plan_id.


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

def plan_id
  @plan_id
end

#priceObject (readonly)

Returns the value of attribute price.


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

def price
  @price
end

#statusObject (readonly)

Returns the value of attribute status.


50
51
52
# File 'lib/braintree/subscription.rb', line 50

def status
  @status
end

#status_historyObject (readonly)

Returns the value of attribute status_history.


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

def status_history
  @status_history
end

#transactionsObject (readonly)

Returns the value of attribute transactions.


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

def transactions
  @transactions
end

#trial_durationObject (readonly)

Returns the value of attribute trial_duration.


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

def trial_duration
  @trial_duration
end

#trial_duration_unitObject (readonly)

Returns the value of attribute trial_duration_unit.


54
55
56
# File 'lib/braintree/subscription.rb', line 54

def trial_duration_unit
  @trial_duration_unit
end

#trial_periodObject (readonly)

Returns the value of attribute trial_period.


55
56
57
# File 'lib/braintree/subscription.rb', line 55

def trial_period
  @trial_period
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.


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

def updated_at
  @updated_at
end

Class Method Details

._new(*args) ⇒ Object

:nodoc:


117
118
119
# File 'lib/braintree/subscription.rb', line 117

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

.cancel(*args) ⇒ Object


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

def self.cancel(*args)
  Configuration.gateway.subscription.cancel(*args)
end

.cancel!(*args) ⇒ Object


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

def self.cancel!(*args)
  Configuration.gateway.subscription.cancel!(*args)
end

.create(*args) ⇒ Object


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

def self.create(*args)
  Configuration.gateway.subscription.create(*args)
end

.create!(*args) ⇒ Object


70
71
72
# File 'lib/braintree/subscription.rb', line 70

def self.create!(*args)
  Configuration.gateway.subscription.create!(*args)
end

.find(*args) ⇒ Object


74
75
76
# File 'lib/braintree/subscription.rb', line 74

def self.find(*args)
  Configuration.gateway.subscription.find(*args)
end

.retry_charge(*args) ⇒ Object


78
79
80
# File 'lib/braintree/subscription.rb', line 78

def self.retry_charge(*args)
  Configuration.gateway.subscription.retry_charge(*args)
end

.search(&block) ⇒ Object


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

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

.update(*args) ⇒ Object


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

def self.update(*args)
  Configuration.gateway.subscription.update(*args)
end

.update!(*args) ⇒ Object


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

def self.update!(*args)
  Configuration.gateway.subscription.update!(*args)
end

Instance Method Details

#never_expires?Boolean

Returns:

  • (Boolean)

111
112
113
# File 'lib/braintree/subscription.rb', line 111

def never_expires?
  @never_expires
end