Class: AdvancedBilling::AllocationPreview

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/allocation_preview.rb

Overview

AllocationPreview Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(start_date: SKIP, end_date: SKIP, subtotal_in_cents: SKIP, total_tax_in_cents: SKIP, total_discount_in_cents: SKIP, total_in_cents: SKIP, direction: SKIP, proration_scheme: SKIP, line_items: SKIP, accrue_charge: SKIP, allocations: SKIP, period_type: SKIP, existing_balance_in_cents: SKIP, additional_properties: {}) ⇒ AllocationPreview

Returns a new instance of AllocationPreview.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/advanced_billing/models/allocation_preview.rb', line 108

def initialize(start_date: SKIP, end_date: SKIP, subtotal_in_cents: SKIP,
               total_tax_in_cents: SKIP, total_discount_in_cents: SKIP,
               total_in_cents: SKIP, direction: SKIP,
               proration_scheme: SKIP, line_items: SKIP,
               accrue_charge: SKIP, allocations: SKIP, period_type: SKIP,
               existing_balance_in_cents: SKIP, additional_properties: {})
  @start_date = start_date unless start_date == SKIP
  @end_date = end_date unless end_date == SKIP
  @subtotal_in_cents = subtotal_in_cents unless subtotal_in_cents == SKIP
  @total_tax_in_cents = total_tax_in_cents unless total_tax_in_cents == SKIP
  @total_discount_in_cents = total_discount_in_cents unless total_discount_in_cents == SKIP
  @total_in_cents = total_in_cents unless total_in_cents == SKIP
  @direction = direction unless direction == SKIP
  @proration_scheme = proration_scheme unless proration_scheme == SKIP
  @line_items = line_items unless line_items == SKIP
  @accrue_charge = accrue_charge unless accrue_charge == SKIP
  @allocations = allocations unless allocations == SKIP
  @period_type = period_type unless period_type == SKIP
  unless existing_balance_in_cents == SKIP
    @existing_balance_in_cents =
      existing_balance_in_cents
  end

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#accrue_chargeTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


51
52
53
# File 'lib/advanced_billing/models/allocation_preview.rb', line 51

def accrue_charge
  @accrue_charge
end

#allocationsArray[AllocationPreviewItem]

TODO: Write general description for this method

Returns:



55
56
57
# File 'lib/advanced_billing/models/allocation_preview.rb', line 55

def allocations
  @allocations
end

#directionAllocationPreviewDirection

TODO: Write general description for this method



39
40
41
# File 'lib/advanced_billing/models/allocation_preview.rb', line 39

def direction
  @direction
end

#end_dateDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


19
20
21
# File 'lib/advanced_billing/models/allocation_preview.rb', line 19

def end_date
  @end_date
end

#existing_balance_in_centsInteger

An integer representing the amount of the subscription’s current balance

Returns:

  • (Integer)


63
64
65
# File 'lib/advanced_billing/models/allocation_preview.rb', line 63

def existing_balance_in_cents
  @existing_balance_in_cents
end

#line_itemsArray[AllocationPreviewLineItem]

TODO: Write general description for this method

Returns:



47
48
49
# File 'lib/advanced_billing/models/allocation_preview.rb', line 47

def line_items
  @line_items
end

#period_typeString

TODO: Write general description for this method

Returns:

  • (String)


59
60
61
# File 'lib/advanced_billing/models/allocation_preview.rb', line 59

def period_type
  @period_type
end

#proration_schemeString

TODO: Write general description for this method

Returns:

  • (String)


43
44
45
# File 'lib/advanced_billing/models/allocation_preview.rb', line 43

def proration_scheme
  @proration_scheme
end

#start_dateDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


15
16
17
# File 'lib/advanced_billing/models/allocation_preview.rb', line 15

def start_date
  @start_date
end

#subtotal_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


23
24
25
# File 'lib/advanced_billing/models/allocation_preview.rb', line 23

def subtotal_in_cents
  @subtotal_in_cents
end

#total_discount_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


31
32
33
# File 'lib/advanced_billing/models/allocation_preview.rb', line 31

def total_discount_in_cents
  @total_discount_in_cents
end

#total_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


35
36
37
# File 'lib/advanced_billing/models/allocation_preview.rb', line 35

def total_in_cents
  @total_in_cents
end

#total_tax_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


27
28
29
# File 'lib/advanced_billing/models/allocation_preview.rb', line 27

def total_tax_in_cents
  @total_tax_in_cents
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/advanced_billing/models/allocation_preview.rb', line 138

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  start_date = if hash.key?('start_date')
                 (DateTimeHelper.from_rfc3339(hash['start_date']) if hash['start_date'])
               else
                 SKIP
               end
  end_date = if hash.key?('end_date')
               (DateTimeHelper.from_rfc3339(hash['end_date']) if hash['end_date'])
             else
               SKIP
             end
  subtotal_in_cents =
    hash.key?('subtotal_in_cents') ? hash['subtotal_in_cents'] : SKIP
  total_tax_in_cents =
    hash.key?('total_tax_in_cents') ? hash['total_tax_in_cents'] : SKIP
  total_discount_in_cents =
    hash.key?('total_discount_in_cents') ? hash['total_discount_in_cents'] : SKIP
  total_in_cents =
    hash.key?('total_in_cents') ? hash['total_in_cents'] : SKIP
  direction = hash.key?('direction') ? hash['direction'] : SKIP
  proration_scheme =
    hash.key?('proration_scheme') ? hash['proration_scheme'] : SKIP
  # Parameter is an array, so we need to iterate through it
  line_items = nil
  unless hash['line_items'].nil?
    line_items = []
    hash['line_items'].each do |structure|
      line_items << (AllocationPreviewLineItem.from_hash(structure) if structure)
    end
  end

  line_items = SKIP unless hash.key?('line_items')
  accrue_charge = hash.key?('accrue_charge') ? hash['accrue_charge'] : SKIP
  # Parameter is an array, so we need to iterate through it
  allocations = nil
  unless hash['allocations'].nil?
    allocations = []
    hash['allocations'].each do |structure|
      allocations << (AllocationPreviewItem.from_hash(structure) if structure)
    end
  end

  allocations = SKIP unless hash.key?('allocations')
  period_type = hash.key?('period_type') ? hash['period_type'] : SKIP
  existing_balance_in_cents =
    hash.key?('existing_balance_in_cents') ? hash['existing_balance_in_cents'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  AllocationPreview.new(start_date: start_date,
                        end_date: end_date,
                        subtotal_in_cents: subtotal_in_cents,
                        total_tax_in_cents: total_tax_in_cents,
                        total_discount_in_cents: total_discount_in_cents,
                        total_in_cents: total_in_cents,
                        direction: direction,
                        proration_scheme: proration_scheme,
                        line_items: line_items,
                        accrue_charge: accrue_charge,
                        allocations: allocations,
                        period_type: period_type,
                        existing_balance_in_cents: existing_balance_in_cents,
                        additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/advanced_billing/models/allocation_preview.rb', line 66

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['start_date'] = 'start_date'
  @_hash['end_date'] = 'end_date'
  @_hash['subtotal_in_cents'] = 'subtotal_in_cents'
  @_hash['total_tax_in_cents'] = 'total_tax_in_cents'
  @_hash['total_discount_in_cents'] = 'total_discount_in_cents'
  @_hash['total_in_cents'] = 'total_in_cents'
  @_hash['direction'] = 'direction'
  @_hash['proration_scheme'] = 'proration_scheme'
  @_hash['line_items'] = 'line_items'
  @_hash['accrue_charge'] = 'accrue_charge'
  @_hash['allocations'] = 'allocations'
  @_hash['period_type'] = 'period_type'
  @_hash['existing_balance_in_cents'] = 'existing_balance_in_cents'
  @_hash
end

.nullablesObject

An array for nullable fields



104
105
106
# File 'lib/advanced_billing/models/allocation_preview.rb', line 104

def self.nullables
  []
end

.optionalsObject

An array for optional fields



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/advanced_billing/models/allocation_preview.rb', line 85

def self.optionals
  %w[
    start_date
    end_date
    subtotal_in_cents
    total_tax_in_cents
    total_discount_in_cents
    total_in_cents
    direction
    proration_scheme
    line_items
    accrue_charge
    allocations
    period_type
    existing_balance_in_cents
  ]
end

Instance Method Details

#to_custom_end_dateObject



212
213
214
# File 'lib/advanced_billing/models/allocation_preview.rb', line 212

def to_custom_end_date
  DateTimeHelper.to_rfc3339(end_date)
end

#to_custom_start_dateObject



208
209
210
# File 'lib/advanced_billing/models/allocation_preview.rb', line 208

def to_custom_start_date
  DateTimeHelper.to_rfc3339(start_date)
end