Class: AdvancedBilling::InvoiceLineItem

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

Overview

InvoiceLineItem Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(uid: SKIP, title: SKIP, description: SKIP, quantity: SKIP, unit_price: SKIP, subtotal_amount: SKIP, discount_amount: SKIP, tax_amount: SKIP, total_amount: SKIP, tiered_unit_price: SKIP, period_range_start: SKIP, period_range_end: SKIP, transaction_id: SKIP, product_id: SKIP, product_version: SKIP, component_id: SKIP, price_point_id: SKIP, billing_schedule_item_id: SKIP, hide: SKIP, component_cost_data: SKIP, product_price_point_id: SKIP, custom_item: SKIP, kind: SKIP, additional_properties: {}) ⇒ InvoiceLineItem

Returns a new instance of InvoiceLineItem.



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 230

def initialize(uid: SKIP, title: SKIP, description: SKIP, quantity: SKIP,
               unit_price: SKIP, subtotal_amount: SKIP,
               discount_amount: SKIP, tax_amount: SKIP, total_amount: SKIP,
               tiered_unit_price: SKIP, period_range_start: SKIP,
               period_range_end: SKIP, transaction_id: SKIP,
               product_id: SKIP, product_version: SKIP, component_id: SKIP,
               price_point_id: SKIP, billing_schedule_item_id: SKIP,
               hide: SKIP, component_cost_data: SKIP,
               product_price_point_id: SKIP, custom_item: SKIP, kind: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @uid = uid unless uid == SKIP
  @title = title unless title == SKIP
  @description = description unless description == SKIP
  @quantity = quantity unless quantity == SKIP
  @unit_price = unit_price unless unit_price == SKIP
  @subtotal_amount = subtotal_amount unless subtotal_amount == SKIP
  @discount_amount = discount_amount unless discount_amount == SKIP
  @tax_amount = tax_amount unless tax_amount == SKIP
  @total_amount = total_amount unless total_amount == SKIP
  @tiered_unit_price = tiered_unit_price unless tiered_unit_price == SKIP
  @period_range_start = period_range_start unless period_range_start == SKIP
  @period_range_end = period_range_end unless period_range_end == SKIP
  @transaction_id = transaction_id unless transaction_id == SKIP
  @product_id = product_id unless product_id == SKIP
  @product_version = product_version unless product_version == SKIP
  @component_id = component_id unless component_id == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @billing_schedule_item_id = billing_schedule_item_id unless billing_schedule_item_id == SKIP
  @hide = hide unless hide == SKIP
  @component_cost_data = component_cost_data unless component_cost_data == SKIP
  @product_price_point_id = product_price_point_id unless product_price_point_id == SKIP
  @custom_item = custom_item unless custom_item == SKIP
  @kind = kind unless kind == SKIP
end

Instance Attribute Details

#billing_schedule_item_idInteger

The price point ID of the component being billed. Will be ‘nil` for non-component charges.

Returns:

  • (Integer)


135
136
137
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 135

def billing_schedule_item_id
  @billing_schedule_item_id
end

#component_cost_dataInvoiceLineItemComponentCostData

The price point ID of the component being billed. Will be ‘nil` for non-component charges.



145
146
147
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 145

def component_cost_data
  @component_cost_data
end

#component_idInteger

The ID of the component being billed. Will be ‘nil` for non-component charges.

Returns:

  • (Integer)


125
126
127
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 125

def component_id
  @component_id
end

#custom_itemTrueClass | FalseClass

The price point ID of the line item’s product

Returns:

  • (TrueClass | FalseClass)


153
154
155
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 153

def custom_item
  @custom_item
end

#descriptionString

Detailed description for the charge or item represented by this line. May include proration details in plain text. Note: this string may contain line breaks that are hints for the best display format on the invoice.

Returns:

  • (String)


26
27
28
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 26

def description
  @description
end

#discount_amountString

The approximate discount applied to just this line. The value is approximated in cases where rounding errors make it difficult to apportion exactly a total discount among many lines. Several lines may have been summed prior to applying the discount to arrive at ‘discount_amount` for the invoice - backing that out to the discount on a single line may introduce rounding or precision errors.

Returns:

  • (String)


56
57
58
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 56

def discount_amount
  @discount_amount
end

#hideTrueClass | FalseClass

The price point ID of the component being billed. Will be ‘nil` for non-component charges.

Returns:

  • (TrueClass | FalseClass)


140
141
142
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 140

def hide
  @hide
end

#kindString

The price point ID of the line item’s product

Returns:

  • (String)


157
158
159
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 157

def kind
  @kind
end

#period_range_endDate

End date for the period covered by this line. The format is ‘“YYYY-MM-DD”`.

  • For periodic charges paid in advance, this date will match the next

(future) billing date.

  • For periodic charges paid in arrears (e.g. metered charges), this date

will be the date of the current billing date.

  • For non-periodic charges, this date and the start date will match.

Returns:

  • (Date)


100
101
102
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 100

def period_range_end
  @period_range_end
end

#period_range_startDate

Start date for the period covered by this line. The format is ‘“YYYY-MM-DD”`.

  • For periodic charges paid in advance, this date will match the billing

date, and the end date will be in the future.

  • For periodic charges paid in arrears (e.g. metered charges), this date

will be the date of the previous billing, and the end date will be the current billing date.

  • For non-periodic charges, this date and the end date will match.

Returns:

  • (Date)


90
91
92
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 90

def period_range_start
  @period_range_start
end

#price_point_idInteger

The price point ID of the component being billed. Will be ‘nil` for non-component charges.

Returns:

  • (Integer)


130
131
132
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 130

def price_point_id
  @price_point_id
end

#product_idInteger

The ID of the product subscribed when the charge was made. This may be set even for component charges, so true product-only (non-component) charges will also have a nil ‘component_id`.

Returns:

  • (Integer)


116
117
118
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 116

def product_id
  @product_id
end

#product_price_point_idInteger

The price point ID of the line item’s product

Returns:

  • (Integer)


149
150
151
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 149

def product_price_point_id
  @product_price_point_id
end

#product_versionInteger

The version of the product subscribed when the charge was made.

Returns:

  • (Integer)


120
121
122
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 120

def product_version
  @product_version
end

#quantityString

The quantity or count of units billed by the line item. This is a decimal number represented as a string. (See “About Decimal Numbers”.)

Returns:

  • (String)


32
33
34
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 32

def quantity
  @quantity
end

#subtotal_amountString

The line subtotal, generally calculated as ‘quantity * unit_price`. This is the canonical amount of record for the line - when rounding differences are in play, `subtotal_amount` takes precedence over the value derived from `quantity * unit_price` (which may not have the proper precision to exactly equal this amount).

Returns:

  • (String)


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

def subtotal_amount
  @subtotal_amount
end

#tax_amountString

The approximate tax applied to just this line. The value is approximated in cases where rounding errors make it difficult to apportion exactly a total tax among many lines. Several lines may have been summed prior to applying the tax rate to arrive at ‘tax_amount` for the invoice - backing that out to the tax on a single line may introduce rounding or precision errors.

Returns:

  • (String)


65
66
67
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 65

def tax_amount
  @tax_amount
end

#tiered_unit_priceTrueClass | FalseClass

When ‘true`, indicates that the actual pricing scheme for the line was tiered, so the `unit_price` shown is the blended average for all units.

Returns:

  • (TrueClass | FalseClass)


79
80
81
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 79

def tiered_unit_price
  @tiered_unit_price
end

#titleString

A short descriptor for the charge or item represented by this line.

Returns:

  • (String)


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

def title
  @title
end

#total_amountString

The non-canonical total amount for the line. ‘subtotal_amount` is the canonical amount for a line. The invoice `total_amount` is derived from the sum of the line `subtotal_amount`s and discounts or taxes applied thereafter. Therefore, due to rounding or precision errors, the sum of line `total_amount`s may not equal the invoice `total_amount`.

Returns:

  • (String)


74
75
76
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 74

def total_amount
  @total_amount
end

#transaction_idInteger

End date for the period covered by this line. The format is ‘“YYYY-MM-DD”`.

  • For periodic charges paid in advance, this date will match the next

(future) billing date.

  • For periodic charges paid in arrears (e.g. metered charges), this date

will be the date of the current billing date.

  • For non-periodic charges, this date and the start date will match.

Returns:

  • (Integer)


110
111
112
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 110

def transaction_id
  @transaction_id
end

#uidString

Unique identifier for the line item. Useful when cross-referencing the line against individual discounts in the ‘discounts` or `taxes` lists.

Returns:

  • (String)


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

def uid
  @uid
end

#unit_priceString

The price per unit for the line item. When tiered pricing was used (i.e. not every unit was actually priced at the same price) this will be the blended average cost per unit and the ‘tiered_unit_price` field will be set to `true`.

Returns:

  • (String)


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

def unit_price
  @unit_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 271

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  uid = hash.key?('uid') ? hash['uid'] : SKIP
  title = hash.key?('title') ? hash['title'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  quantity = hash.key?('quantity') ? hash['quantity'] : SKIP
  unit_price = hash.key?('unit_price') ? hash['unit_price'] : SKIP
  subtotal_amount =
    hash.key?('subtotal_amount') ? hash['subtotal_amount'] : SKIP
  discount_amount =
    hash.key?('discount_amount') ? hash['discount_amount'] : SKIP
  tax_amount = hash.key?('tax_amount') ? hash['tax_amount'] : SKIP
  total_amount = hash.key?('total_amount') ? hash['total_amount'] : SKIP
  tiered_unit_price =
    hash.key?('tiered_unit_price') ? hash['tiered_unit_price'] : SKIP
  period_range_start =
    hash.key?('period_range_start') ? hash['period_range_start'] : SKIP
  period_range_end =
    hash.key?('period_range_end') ? hash['period_range_end'] : SKIP
  transaction_id =
    hash.key?('transaction_id') ? hash['transaction_id'] : SKIP
  product_id = hash.key?('product_id') ? hash['product_id'] : SKIP
  product_version =
    hash.key?('product_version') ? hash['product_version'] : SKIP
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  billing_schedule_item_id =
    hash.key?('billing_schedule_item_id') ? hash['billing_schedule_item_id'] : SKIP
  hide = hash.key?('hide') ? hash['hide'] : SKIP
  if hash['component_cost_data']
    component_cost_data = InvoiceLineItemComponentCostData.from_hash(hash['component_cost_data'])
  end
  product_price_point_id =
    hash.key?('product_price_point_id') ? hash['product_price_point_id'] : SKIP
  custom_item = hash.key?('custom_item') ? hash['custom_item'] : SKIP
  kind = hash.key?('kind') ? hash['kind'] : SKIP

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  InvoiceLineItem.new(uid: uid,
                      title: title,
                      description: description,
                      quantity: quantity,
                      unit_price: unit_price,
                      subtotal_amount: subtotal_amount,
                      discount_amount: discount_amount,
                      tax_amount: tax_amount,
                      total_amount: total_amount,
                      tiered_unit_price: tiered_unit_price,
                      period_range_start: period_range_start,
                      period_range_end: period_range_end,
                      transaction_id: transaction_id,
                      product_id: product_id,
                      product_version: product_version,
                      component_id: component_id,
                      price_point_id: price_point_id,
                      billing_schedule_item_id: billing_schedule_item_id,
                      hide: hide,
                      component_cost_data: component_cost_data,
                      product_price_point_id: product_price_point_id,
                      custom_item: custom_item,
                      kind: kind,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 160

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['uid'] = 'uid'
  @_hash['title'] = 'title'
  @_hash['description'] = 'description'
  @_hash['quantity'] = 'quantity'
  @_hash['unit_price'] = 'unit_price'
  @_hash['subtotal_amount'] = 'subtotal_amount'
  @_hash['discount_amount'] = 'discount_amount'
  @_hash['tax_amount'] = 'tax_amount'
  @_hash['total_amount'] = 'total_amount'
  @_hash['tiered_unit_price'] = 'tiered_unit_price'
  @_hash['period_range_start'] = 'period_range_start'
  @_hash['period_range_end'] = 'period_range_end'
  @_hash['transaction_id'] = 'transaction_id'
  @_hash['product_id'] = 'product_id'
  @_hash['product_version'] = 'product_version'
  @_hash['component_id'] = 'component_id'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['billing_schedule_item_id'] = 'billing_schedule_item_id'
  @_hash['hide'] = 'hide'
  @_hash['component_cost_data'] = 'component_cost_data'
  @_hash['product_price_point_id'] = 'product_price_point_id'
  @_hash['custom_item'] = 'custom_item'
  @_hash['kind'] = 'kind'
  @_hash
end

.nullablesObject

An array for nullable fields



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 218

def self.nullables
  %w[
    product_id
    product_version
    component_id
    price_point_id
    billing_schedule_item_id
    component_cost_data
    product_price_point_id
  ]
end

.optionalsObject

An array for optional fields



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 189

def self.optionals
  %w[
    uid
    title
    description
    quantity
    unit_price
    subtotal_amount
    discount_amount
    tax_amount
    total_amount
    tiered_unit_price
    period_range_start
    period_range_end
    transaction_id
    product_id
    product_version
    component_id
    price_point_id
    billing_schedule_item_id
    hide
    component_cost_data
    product_price_point_id
    custom_item
    kind
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (InvoiceLineItem | Hash)

    value against the validation is performed.



343
344
345
346
347
348
349
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 343

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end