Class: AdvancedBilling::InvoiceLineItem
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- AdvancedBilling::InvoiceLineItem
- Defined in:
- lib/advanced_billing/models/invoice_line_item.rb
Overview
InvoiceLineItem Model.
Instance Attribute Summary collapse
-
#component_cost_data ⇒ InvoiceLineItemComponentCostData
The price point ID of the component being billed.
-
#component_id ⇒ Integer
The ID of the component being billed.
-
#custom_item ⇒ TrueClass | FalseClass
The price point ID of the line item’s product.
-
#description ⇒ String
Detailed description for the charge or item represented by this line.
-
#discount_amount ⇒ String
The approximate discount applied to just this line.
-
#hide ⇒ TrueClass | FalseClass
The price point ID of the component being billed.
-
#kind ⇒ String
The price point ID of the line item’s product.
-
#period_range_end ⇒ Date
End date for the period covered by this line.
-
#period_range_start ⇒ Date
Start date for the period covered by this line.
-
#price_point_id ⇒ Integer
The price point ID of the component being billed.
-
#product_id ⇒ Integer
The ID of the product subscribed when the charge was made.
-
#product_price_point_id ⇒ Integer
The price point ID of the line item’s product.
-
#product_version ⇒ Integer
The version of the product subscribed when the charge was made.
-
#quantity ⇒ String
The quantity or count of units billed by the line item.
-
#subtotal_amount ⇒ String
The line subtotal, generally calculated as ‘quantity * unit_price`.
-
#tax_amount ⇒ String
The approximate tax applied to just this line.
-
#tiered_unit_price ⇒ TrueClass | 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.
-
#title ⇒ String
A short descriptor for the charge or item represented by this line.
-
#total_amount ⇒ String
The non-canonical total amount for the line.
-
#transaction_id ⇒ Integer
End date for the period covered by this line.
-
#uid ⇒ String
Unique identifier for the line item.
-
#unit_price ⇒ String
The price per unit for the line item.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
Methods inherited from BaseModel
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, 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.
222 223 224 225 226 227 228 229 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 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 222 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, hide: SKIP, component_cost_data: SKIP, product_price_point_id: SKIP, custom_item: SKIP, kind: SKIP, additional_properties: {}) @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 @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 # Add additional model properties to the instance. additional_properties.each do |_name, _value| instance_variable_set("@#{_name}", _value) end end |
Instance Attribute Details
#component_cost_data ⇒ InvoiceLineItemComponentCostData
The price point ID of the component being billed. Will be ‘nil` for non-component charges.
140 141 142 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 140 def component_cost_data @component_cost_data end |
#component_id ⇒ Integer
The ID of the component being billed. Will be ‘nil` for non-component charges.
125 126 127 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 125 def component_id @component_id end |
#custom_item ⇒ TrueClass | FalseClass
The price point ID of the line item’s product
148 149 150 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 148 def custom_item @custom_item end |
#description ⇒ String
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.
26 27 28 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 26 def description @description end |
#discount_amount ⇒ String
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.
56 57 58 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 56 def discount_amount @discount_amount end |
#hide ⇒ TrueClass | FalseClass
The price point ID of the component being billed. Will be ‘nil` for non-component charges.
135 136 137 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 135 def hide @hide end |
#kind ⇒ String
The price point ID of the line item’s product
152 153 154 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 152 def kind @kind end |
#period_range_end ⇒ Date
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.
100 101 102 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 100 def period_range_end @period_range_end end |
#period_range_start ⇒ Date
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.
90 91 92 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 90 def period_range_start @period_range_start end |
#price_point_id ⇒ Integer
The price point ID of the component being billed. Will be ‘nil` for non-component charges.
130 131 132 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 130 def price_point_id @price_point_id end |
#product_id ⇒ Integer
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`.
116 117 118 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 116 def product_id @product_id end |
#product_price_point_id ⇒ Integer
The price point ID of the line item’s product
144 145 146 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 144 def product_price_point_id @product_price_point_id end |
#product_version ⇒ Integer
The version of the product subscribed when the charge was made.
120 121 122 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 120 def product_version @product_version end |
#quantity ⇒ String
The quantity or count of units billed by the line item. This is a decimal number represented as a string. (See “About Decimal Numbers”.)
32 33 34 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 32 def quantity @quantity end |
#subtotal_amount ⇒ String
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).
47 48 49 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 47 def subtotal_amount @subtotal_amount end |
#tax_amount ⇒ String
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.
65 66 67 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 65 def tax_amount @tax_amount end |
#tiered_unit_price ⇒ TrueClass | 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.
79 80 81 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 79 def tiered_unit_price @tiered_unit_price end |
#title ⇒ String
A short descriptor for the charge or item represented by this line.
19 20 21 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 19 def title @title end |
#total_amount ⇒ String
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`.
74 75 76 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 74 def total_amount @total_amount end |
#transaction_id ⇒ Integer
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.
110 111 112 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 110 def transaction_id @transaction_id end |
#uid ⇒ String
Unique identifier for the line item. Useful when cross-referencing the line against individual discounts in the ‘discounts` or `taxes` lists.
15 16 17 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 15 def uid @uid end |
#unit_price ⇒ String
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`.
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.
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 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 261 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 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. names.each_value { |k| hash.delete(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, hide: hide, component_cost_data: component_cost_data, product_price_point_id: product_price_point_id, custom_item: custom_item, kind: kind, additional_properties: hash) end |
.names ⇒ Object
A mapping from model property names to API property names.
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 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 155 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['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 |
.nullables ⇒ Object
An array for nullable fields
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 211 def self.nullables %w[ product_id product_version component_id price_point_id component_cost_data product_price_point_id ] end |
.optionals ⇒ Object
An array for optional fields
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 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 183 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 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.
330 331 332 333 334 335 336 |
# File 'lib/advanced_billing/models/invoice_line_item.rb', line 330 def self.validate(value) return true if value.instance_of? self return false unless value.instance_of? Hash true end |