Class: ApiReference::InvoiceLineItem

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/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(amount:, end_date:, grouping:, adjustments:, name:, quantity:, start_date:, subtotal:, adjusted_subtotal:, credits_applied:, partially_invoiced_amount:, sub_line_items:, tax_amounts:, id:, price:, usage_customer_ids:, filter:, additional_properties: nil) ⇒ InvoiceLineItem

Returns a new instance of InvoiceLineItem.



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

def initialize(amount:, end_date:, grouping:, adjustments:, name:,
               quantity:, start_date:, subtotal:, adjusted_subtotal:,
               credits_applied:, partially_invoiced_amount:,
               sub_line_items:, tax_amounts:, id:, price:,
               usage_customer_ids:, filter:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @amount = amount
  @end_date = end_date
  @grouping = grouping
  @adjustments = adjustments
  @name = name
  @quantity = quantity
  @start_date = start_date
  @subtotal = subtotal
  @adjusted_subtotal = adjusted_subtotal
  @credits_applied = credits_applied
  @partially_invoiced_amount = partially_invoiced_amount
  @sub_line_items = sub_line_items
  @tax_amounts = tax_amounts
  @id = id
  @price = price
  @usage_customer_ids = usage_customer_ids
  @filter = filter
  @additional_properties = additional_properties
end

Instance Attribute Details

#adjusted_subtotalString

The line amount after any adjustments and before overage conversion, credits and partial invoicing.

Returns:

  • (String)


53
54
55
# File 'lib/api_reference/models/invoice_line_item.rb', line 53

def adjusted_subtotal
  @adjusted_subtotal
end

#adjustmentsArray[Object]

All adjustments applied to the line item in the order they were applied based on invoice calculations (ie. usage discounts -> amount discounts -> percentage discounts -> minimums -> maximums).

Returns:

  • (Array[Object])


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

def adjustments
  @adjustments
end

#amountString

The final amount for a line item after all adjustments and pre paid credits have been applied.

Returns:

  • (String)


16
17
18
# File 'lib/api_reference/models/invoice_line_item.rb', line 16

def amount
  @amount
end

#credits_appliedString

The number of prepaid credits applied.

Returns:

  • (String)


57
58
59
# File 'lib/api_reference/models/invoice_line_item.rb', line 57

def credits_applied
  @credits_applied
end

#end_dateDateTime

The end date of the range of time applied for this line item's price.

Returns:

  • (DateTime)


20
21
22
# File 'lib/api_reference/models/invoice_line_item.rb', line 20

def end_date
  @end_date
end

#filterString

An additional filter that was used to calculate the usage for this line item.

Returns:

  • (String)


98
99
100
# File 'lib/api_reference/models/invoice_line_item.rb', line 98

def filter
  @filter
end

#groupingString

[DEPRECATED] For configured prices that are split by a grouping key, this will be populated with the key and a value. The amount and subtotal will be the values for this particular grouping.

Returns:

  • (String)


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

def grouping
  @grouping
end

#idString

A unique ID for this line item.

Returns:

  • (String)


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

def id
  @id
end

#nameString

The name of the price associated with this line item.

Returns:

  • (String)


36
37
38
# File 'lib/api_reference/models/invoice_line_item.rb', line 36

def name
  @name
end

#partially_invoiced_amountString

Any amount applied from a partial invoice

Returns:

  • (String)


61
62
63
# File 'lib/api_reference/models/invoice_line_item.rb', line 61

def partially_invoiced_amount
  @partially_invoiced_amount
end

#priceObject

The Price resource represents a price that can be billed on a subscription, resulting in a charge on an invoice in the form of an invoice line item. Prices take a quantity and determine an amount to bill. Orb supports a few different pricing models out of the box. Each of these models is serialized differently in a given Price object. The model_type field determines the key for the configuration object that is present. For more on the types of prices, see the core concepts documentation

Returns:

  • (Object)


88
89
90
# File 'lib/api_reference/models/invoice_line_item.rb', line 88

def price
  @price
end

#quantityFloat

Either the fixed fee quantity or the usage during the service period.

Returns:

  • (Float)


40
41
42
# File 'lib/api_reference/models/invoice_line_item.rb', line 40

def quantity
  @quantity
end

#start_dateDateTime

The start date of the range of time applied for this line item's price.

Returns:

  • (DateTime)


44
45
46
# File 'lib/api_reference/models/invoice_line_item.rb', line 44

def start_date
  @start_date
end

#sub_line_itemsArray[Object]

For complex pricing structures, the line item can be broken down further in sub_line_items.

Returns:

  • (Array[Object])


66
67
68
# File 'lib/api_reference/models/invoice_line_item.rb', line 66

def sub_line_items
  @sub_line_items
end

#subtotalString

The line amount before any adjustments.

Returns:

  • (String)


48
49
50
# File 'lib/api_reference/models/invoice_line_item.rb', line 48

def subtotal
  @subtotal
end

#tax_amountsArray[TaxAmount]

An array of tax rates and their incurred tax amounts. Empty if no tax integration is configured.

Returns:



71
72
73
# File 'lib/api_reference/models/invoice_line_item.rb', line 71

def tax_amounts
  @tax_amounts
end

#usage_customer_idsArray[String]

A list of customer ids that were used to calculate the usage for this line item.

Returns:

  • (Array[String])


93
94
95
# File 'lib/api_reference/models/invoice_line_item.rb', line 93

def usage_customer_ids
  @usage_customer_ids
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
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
236
237
# File 'lib/api_reference/models/invoice_line_item.rb', line 166

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  end_date = if hash.key?('end_date')
               (DateTimeHelper.from_rfc3339(hash['end_date']) if hash['end_date'])
             end
  grouping = hash.key?('grouping') ? hash['grouping'] : nil
  adjustments = hash.key?('adjustments') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:MonetaryAdjustment), hash['adjustments']
  ) : nil
  name = hash.key?('name') ? hash['name'] : nil
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  start_date = if hash.key?('start_date')
                 (DateTimeHelper.from_rfc3339(hash['start_date']) if hash['start_date'])
               end
  subtotal = hash.key?('subtotal') ? hash['subtotal'] : nil
  adjusted_subtotal =
    hash.key?('adjusted_subtotal') ? hash['adjusted_subtotal'] : nil
  credits_applied =
    hash.key?('credits_applied') ? hash['credits_applied'] : nil
  partially_invoiced_amount =
    hash.key?('partially_invoiced_amount') ? hash['partially_invoiced_amount'] : nil
  sub_line_items = hash.key?('sub_line_items') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:InvoiceSubLineItem), hash['sub_line_items']
  ) : nil
  # Parameter is an array, so we need to iterate through it
  tax_amounts = nil
  unless hash['tax_amounts'].nil?
    tax_amounts = []
    hash['tax_amounts'].each do |structure|
      tax_amounts << (TaxAmount.from_hash(structure) if structure)
    end
  end

  tax_amounts = nil unless hash.key?('tax_amounts')
  id = hash.key?('id') ? hash['id'] : nil
  price = hash.key?('price') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Price), hash['price']
  ) : nil
  usage_customer_ids =
    hash.key?('usage_customer_ids') ? hash['usage_customer_ids'] : nil
  filter = hash.key?('filter') ? hash['filter'] : nil

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  InvoiceLineItem.new(amount: amount,
                      end_date: end_date,
                      grouping: grouping,
                      adjustments: adjustments,
                      name: name,
                      quantity: quantity,
                      start_date: start_date,
                      subtotal: subtotal,
                      adjusted_subtotal: adjusted_subtotal,
                      credits_applied: credits_applied,
                      partially_invoiced_amount: partially_invoiced_amount,
                      sub_line_items: sub_line_items,
                      tax_amounts: tax_amounts,
                      id: id,
                      price: price,
                      usage_customer_ids: usage_customer_ids,
                      filter: filter,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/api_reference/models/invoice_line_item.rb', line 101

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['amount'] = 'amount'
  @_hash['end_date'] = 'end_date'
  @_hash['grouping'] = 'grouping'
  @_hash['adjustments'] = 'adjustments'
  @_hash['name'] = 'name'
  @_hash['quantity'] = 'quantity'
  @_hash['start_date'] = 'start_date'
  @_hash['subtotal'] = 'subtotal'
  @_hash['adjusted_subtotal'] = 'adjusted_subtotal'
  @_hash['credits_applied'] = 'credits_applied'
  @_hash['partially_invoiced_amount'] = 'partially_invoiced_amount'
  @_hash['sub_line_items'] = 'sub_line_items'
  @_hash['tax_amounts'] = 'tax_amounts'
  @_hash['id'] = 'id'
  @_hash['price'] = 'price'
  @_hash['usage_customer_ids'] = 'usage_customer_ids'
  @_hash['filter'] = 'filter'
  @_hash
end

.nullablesObject

An array for nullable fields



129
130
131
132
133
134
135
# File 'lib/api_reference/models/invoice_line_item.rb', line 129

def self.nullables
  %w[
    grouping
    usage_customer_ids
    filter
  ]
end

.optionalsObject

An array for optional fields



124
125
126
# File 'lib/api_reference/models/invoice_line_item.rb', line 124

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (InvoiceLineItem | Hash)

    value against the validation is performed.



249
250
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
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
# File 'lib/api_reference/models/invoice_line_item.rb', line 249

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.amount,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.end_date,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.grouping,
                              ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:MonetaryAdjustment)
                       .validate(value.adjustments) and
        APIHelper.valid_type?(value.name,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.quantity,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.start_date,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.subtotal,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.adjusted_subtotal,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.credits_applied,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.partially_invoiced_amount,
                              ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:InvoiceSubLineItem)
                       .validate(value.sub_line_items) and
        APIHelper.valid_type?(value.tax_amounts,
                              ->(val) { TaxAmount.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true) and
        APIHelper.valid_type?(value.id,
                              ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:Price)
                       .validate(value.price) and
        APIHelper.valid_type?(value.usage_customer_ids,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.filter,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['amount'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['end_date'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['grouping'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:MonetaryAdjustment)
                     .validate(value['adjustments']) and
      APIHelper.valid_type?(value['name'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['quantity'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['start_date'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['subtotal'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['adjusted_subtotal'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['credits_applied'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['partially_invoiced_amount'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:InvoiceSubLineItem)
                     .validate(value['sub_line_items']) and
      APIHelper.valid_type?(value['tax_amounts'],
                            ->(val) { TaxAmount.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true) and
      APIHelper.valid_type?(value['id'],
                            ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:Price)
                     .validate(value['price']) and
      APIHelper.valid_type?(value['usage_customer_ids'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['filter'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/api_reference/models/invoice_line_item.rb', line 346

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount.inspect}, end_date: #{@end_date.inspect}, grouping:"\
  " #{@grouping.inspect}, adjustments: #{@adjustments.inspect}, name: #{@name.inspect},"\
  " quantity: #{@quantity.inspect}, start_date: #{@start_date.inspect}, subtotal:"\
  " #{@subtotal.inspect}, adjusted_subtotal: #{@adjusted_subtotal.inspect}, credits_applied:"\
  " #{@credits_applied.inspect}, partially_invoiced_amount:"\
  " #{@partially_invoiced_amount.inspect}, sub_line_items: #{@sub_line_items.inspect},"\
  " tax_amounts: #{@tax_amounts.inspect}, id: #{@id.inspect}, price: #{@price.inspect},"\
  " usage_customer_ids: #{@usage_customer_ids.inspect}, filter: #{@filter.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_custom_end_dateObject



239
240
241
# File 'lib/api_reference/models/invoice_line_item.rb', line 239

def to_custom_end_date
  DateTimeHelper.to_rfc3339(end_date)
end

#to_custom_start_dateObject



243
244
245
# File 'lib/api_reference/models/invoice_line_item.rb', line 243

def to_custom_start_date
  DateTimeHelper.to_rfc3339(start_date)
end

#to_sObject

Provides a human-readable string representation of the object.



334
335
336
337
338
339
340
341
342
343
# File 'lib/api_reference/models/invoice_line_item.rb', line 334

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} amount: #{@amount}, end_date: #{@end_date}, grouping: #{@grouping},"\
  " adjustments: #{@adjustments}, name: #{@name}, quantity: #{@quantity}, start_date:"\
  " #{@start_date}, subtotal: #{@subtotal}, adjusted_subtotal: #{@adjusted_subtotal},"\
  " credits_applied: #{@credits_applied}, partially_invoiced_amount:"\
  " #{@partially_invoiced_amount}, sub_line_items: #{@sub_line_items}, tax_amounts:"\
  " #{@tax_amounts}, id: #{@id}, price: #{@price}, usage_customer_ids: #{@usage_customer_ids},"\
  " filter: #{@filter}, additional_properties: #{@additional_properties}>"
end