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, #get_additional_properties, #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, tax_included: 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, prepaid_allocation_expires_at: SKIP, additional_properties: {}) ⇒ InvoiceLineItem

Returns a new instance of InvoiceLineItem.



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
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
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 251

def initialize(uid: SKIP, title: SKIP, description: SKIP, quantity: SKIP,
               unit_price: SKIP, subtotal_amount: SKIP,
               discount_amount: SKIP, tax_amount: SKIP, tax_included: 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,
               prepaid_allocation_expires_at: 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
  @tax_included = tax_included unless tax_included == 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
  unless prepaid_allocation_expires_at == SKIP
    @prepaid_allocation_expires_at =
      prepaid_allocation_expires_at
  end
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)


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

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.



155
156
157
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 155

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)


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

def component_id
  @component_id
end

#custom_itemTrueClass | FalseClass

The price point ID of the line item’s product

Returns:

  • (TrueClass | FalseClass)


163
164
165
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 163

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)


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

def hide
  @hide
end

#kindString

The price point ID of the line item’s product

Returns:

  • (String)


167
168
169
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 167

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)


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

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)


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

def period_range_start
  @period_range_start
end

#prepaid_allocation_expires_atDate

The date a prepaid allocation is set to expire. Only present on line items representing prepaid component allocations. The format is ‘“YYYY-MM-DD”`.

Returns:

  • (Date)


172
173
174
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 172

def prepaid_allocation_expires_at
  @prepaid_allocation_expires_at
end

#price_point_idInteger

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

Returns:

  • (Integer)


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

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)


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

def product_id
  @product_id
end

#product_price_point_idInteger

The price point ID of the line item’s product

Returns:

  • (Integer)


159
160
161
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 159

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)


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

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

#tax_includedTrueClass | FalseClass

Whether the unit price for this line item is tax-inclusive. When ‘true`, `unit_price` already includes tax and `tax_amount` represents the portion of the price attributable to tax. When `false`, any applicable tax is added on top of the price. The value is inherited from the source price point’s ‘tax_included` setting. Custom or ad-hoc line items (which have no associated price point) always return `false`.

Returns:

  • (TrueClass | FalseClass)


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

def tax_included
  @tax_included
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)


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

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)


84
85
86
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 84

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)


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

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.



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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 299

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
  tax_included = hash.key?('tax_included') ? hash['tax_included'] : 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
  prepaid_allocation_expires_at =
    hash.key?('prepaid_allocation_expires_at') ? hash['prepaid_allocation_expires_at'] : 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,
                      tax_included: tax_included,
                      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,
                      prepaid_allocation_expires_at: prepaid_allocation_expires_at,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

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['tax_included'] = 'tax_included'
  @_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['prepaid_allocation_expires_at'] =
    'prepaid_allocation_expires_at'
  @_hash
end

.nullablesObject

An array for nullable fields



238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 238

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

.optionalsObject

An array for optional fields



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 207

def self.optionals
  %w[
    uid
    title
    description
    quantity
    unit_price
    subtotal_amount
    discount_amount
    tax_amount
    tax_included
    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
    prepaid_allocation_expires_at
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (InvoiceLineItem | Hash)

    value against the validation is performed.



376
377
378
379
380
381
382
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 376

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

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 402

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} uid: #{@uid.inspect}, title: #{@title.inspect}, description:"\
  " #{@description.inspect}, quantity: #{@quantity.inspect}, unit_price:"\
  " #{@unit_price.inspect}, subtotal_amount: #{@subtotal_amount.inspect}, discount_amount:"\
  " #{@discount_amount.inspect}, tax_amount: #{@tax_amount.inspect}, tax_included:"\
  " #{@tax_included.inspect}, total_amount: #{@total_amount.inspect}, tiered_unit_price:"\
  " #{@tiered_unit_price.inspect}, period_range_start: #{@period_range_start.inspect},"\
  " period_range_end: #{@period_range_end.inspect}, transaction_id:"\
  " #{@transaction_id.inspect}, product_id: #{@product_id.inspect}, product_version:"\
  " #{@product_version.inspect}, component_id: #{@component_id.inspect}, price_point_id:"\
  " #{@price_point_id.inspect}, billing_schedule_item_id:"\
  " #{@billing_schedule_item_id.inspect}, hide: #{@hide.inspect}, component_cost_data:"\
  " #{@component_cost_data.inspect}, product_price_point_id:"\
  " #{@product_price_point_id.inspect}, custom_item: #{@custom_item.inspect}, kind:"\
  " #{@kind.inspect}, prepaid_allocation_expires_at:"\
  " #{@prepaid_allocation_expires_at.inspect}, additional_properties:"\
  " #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 385

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} uid: #{@uid}, title: #{@title}, description: #{@description}, quantity:"\
  " #{@quantity}, unit_price: #{@unit_price}, subtotal_amount: #{@subtotal_amount},"\
  " discount_amount: #{@discount_amount}, tax_amount: #{@tax_amount}, tax_included:"\
  " #{@tax_included}, 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},"\
  " prepaid_allocation_expires_at: #{@prepaid_allocation_expires_at}, additional_properties:"\
  " #{get_additional_properties}>"
end