Class: AdvancedBilling::UpdateInvoiceItem

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

Overview

A line item change for a draft ad hoc invoice. Supports the same attributes as line items on invoice creation, plus uid and _destroy for updating or removing existing line items.

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(title: SKIP, quantity: SKIP, unit_price: SKIP, taxable: SKIP, tax_code: SKIP, period_range_start: SKIP, period_range_end: SKIP, product_id: SKIP, component_id: SKIP, price_point_id: SKIP, product_price_point_id: SKIP, description: SKIP, uid: SKIP, destroy: SKIP, additional_properties: {}) ⇒ UpdateInvoiceItem

Returns a new instance of UpdateInvoiceItem.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 126

def initialize(title: SKIP, quantity: SKIP, unit_price: SKIP, taxable: SKIP,
               tax_code: SKIP, period_range_start: SKIP,
               period_range_end: SKIP, product_id: SKIP, component_id: SKIP,
               price_point_id: SKIP, product_price_point_id: SKIP,
               description: SKIP, uid: SKIP, destroy: SKIP,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @title = title unless title == SKIP
  @quantity = quantity unless quantity == SKIP
  @unit_price = unit_price unless unit_price == SKIP
  @taxable = taxable unless taxable == SKIP
  @tax_code = tax_code unless tax_code == SKIP
  @period_range_start = period_range_start unless period_range_start == SKIP
  @period_range_end = period_range_end unless period_range_end == SKIP
  @product_id = product_id unless product_id == SKIP
  @component_id = component_id unless component_id == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @product_price_point_id = product_price_point_id unless product_price_point_id == SKIP
  @description = description unless description == SKIP
  @uid = uid unless uid == SKIP
  @destroy = destroy unless destroy == SKIP
end

Instance Attribute Details

#component_idObject

Component handle or component id.

Returns:

  • (Object)


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

def component_id
  @component_id
end

#descriptionString

Price point handle or id. For component.

Returns:

  • (String)


68
69
70
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 68

def description
  @description
end

#destroyTrueClass | FalseClass

Set to true together with uid to remove the matching line item from the invoice. Line items not referenced in the request remain unchanged.

Returns:

  • (TrueClass | FalseClass)


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

def destroy
  @destroy
end

#period_range_endString

YYYY-MM-DD

Returns:

  • (String)


48
49
50
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 48

def period_range_end
  @period_range_end
end

#period_range_startString

YYYY-MM-DD

Returns:

  • (String)


44
45
46
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 44

def period_range_start
  @period_range_start
end

#price_point_idObject

Price point handle or id. For component.

Returns:

  • (Object)


60
61
62
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 60

def price_point_id
  @price_point_id
end

#product_idObject

Product handle or product id.

Returns:

  • (Object)


52
53
54
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 52

def product_id
  @product_id
end

#product_price_point_idObject

Price point handle or id. For component.

Returns:

  • (Object)


64
65
66
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 64

def product_price_point_id
  @product_price_point_id
end

#quantityObject

The quantity can contain up to 8 decimal places. e.g., 1.00 or 0.0012 or 0.00000065. If you submit a value with more than 8 decimal places, we will round it down to the 8th decimal place.

Returns:

  • (Object)


22
23
24
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 22

def quantity
  @quantity
end

#tax_codeString

A string representing the tax code related to the product type. This is especially important when using AvaTax to tax based on locale. This attribute has a max length of 25 characters.

Returns:

  • (String)


40
41
42
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 40

def tax_code
  @tax_code
end

#taxableTrueClass | FalseClass

Set to true to automatically calculate taxes. Site must be configured to use and calculate taxes. If using AvaTax, a tax_code parameter must also be sent.

Returns:

  • (TrueClass | FalseClass)


34
35
36
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 34

def taxable
  @taxable
end

#titleString

TODO: Write general description for this method

Returns:

  • (String)


16
17
18
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 16

def title
  @title
end

#uidString

Unique identifier of an existing line item on the invoice. When provided, the matching line item is updated with the submitted attributes. When omitted, a new line item is added to the invoice.

Returns:

  • (String)


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

def uid
  @uid
end

#unit_priceObject

The unit_price can contain up to 8 decimal places. e.g., 1.00 or 0.0012 or 0.00000065. If you submit a value with more than 8 decimal places, we will round it down to the 8th decimal place.

Returns:

  • (Object)


28
29
30
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 28

def unit_price
  @unit_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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/update_invoice_item.rb', line 154

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  title = hash.key?('title') ? hash['title'] : SKIP
  quantity = hash.key?('quantity') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateInvoiceItemQuantity), hash['quantity']
  ) : SKIP
  unit_price = hash.key?('unit_price') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateInvoiceItemUnitPrice), hash['unit_price']
  ) : SKIP
  taxable = hash.key?('taxable') ? hash['taxable'] : SKIP
  tax_code = hash.key?('tax_code') ? hash['tax_code'] : 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
  product_id = hash.key?('product_id') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateInvoiceItemProductId), hash['product_id']
  ) : SKIP
  component_id = hash.key?('component_id') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateInvoiceItemComponentId), hash['component_id']
  ) : SKIP
  price_point_id = hash.key?('price_point_id') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateInvoiceItemPricePointId), hash['price_point_id']
  ) : SKIP
  product_price_point_id = hash.key?('product_price_point_id') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:UpdateInvoiceItemProductPricePointId), hash['product_price_point_id']
  ) : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  uid = hash.key?('uid') ? hash['uid'] : SKIP
  destroy = hash.key?('_destroy') ? hash['_destroy'] : SKIP

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

  # Create object from extracted values.
  UpdateInvoiceItem.new(title: title,
                        quantity: quantity,
                        unit_price: unit_price,
                        taxable: taxable,
                        tax_code: tax_code,
                        period_range_start: period_range_start,
                        period_range_end: period_range_end,
                        product_id: product_id,
                        component_id: component_id,
                        price_point_id: price_point_id,
                        product_price_point_id: product_price_point_id,
                        description: description,
                        uid: uid,
                        destroy: destroy,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 82

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['title'] = 'title'
  @_hash['quantity'] = 'quantity'
  @_hash['unit_price'] = 'unit_price'
  @_hash['taxable'] = 'taxable'
  @_hash['tax_code'] = 'tax_code'
  @_hash['period_range_start'] = 'period_range_start'
  @_hash['period_range_end'] = 'period_range_end'
  @_hash['product_id'] = 'product_id'
  @_hash['component_id'] = 'component_id'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['product_price_point_id'] = 'product_price_point_id'
  @_hash['description'] = 'description'
  @_hash['uid'] = 'uid'
  @_hash['destroy'] = '_destroy'
  @_hash
end

.nullablesObject

An array for nullable fields



122
123
124
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 122

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    title
    quantity
    unit_price
    taxable
    tax_code
    period_range_start
    period_range_end
    product_id
    component_id
    price_point_id
    product_price_point_id
    description
    uid
    destroy
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



210
211
212
213
214
215
216
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 210

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.



230
231
232
233
234
235
236
237
238
239
240
# File 'lib/advanced_billing/models/update_invoice_item.rb', line 230

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} title: #{@title.inspect}, quantity: #{@quantity.inspect}, unit_price:"\
  " #{@unit_price.inspect}, taxable: #{@taxable.inspect}, tax_code: #{@tax_code.inspect},"\
  " period_range_start: #{@period_range_start.inspect}, period_range_end:"\
  " #{@period_range_end.inspect}, product_id: #{@product_id.inspect}, component_id:"\
  " #{@component_id.inspect}, price_point_id: #{@price_point_id.inspect},"\
  " product_price_point_id: #{@product_price_point_id.inspect}, description:"\
  " #{@description.inspect}, uid: #{@uid.inspect}, destroy: #{@destroy.inspect},"\
  " additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} title: #{@title}, quantity: #{@quantity}, unit_price: #{@unit_price},"\
  " taxable: #{@taxable}, tax_code: #{@tax_code}, period_range_start: #{@period_range_start},"\
  " period_range_end: #{@period_range_end}, product_id: #{@product_id}, component_id:"\
  " #{@component_id}, price_point_id: #{@price_point_id}, product_price_point_id:"\
  " #{@product_price_point_id}, description: #{@description}, uid: #{@uid}, destroy:"\
  " #{@destroy}, additional_properties: #{get_additional_properties}>"
end