Class: NewStoreApi::LineItemPrice
- Defined in:
- lib/new_store_api/models/line_item_price.rb
Overview
The required price points for a line item, in the currency's minor unit.
Instance Attribute Summary collapse
-
#default_list_price ⇒ Integer
The price of the product in the default pricebook, in the currency's minor unit.
-
#discounts ⇒ Array[Object]
Discounts applied to this item, item-level or order-level prorated onto it (see
scope). -
#list_price ⇒ Integer
The price of the product in the chosen pricebook, in the currency's minor unit.
-
#price ⇒ Integer
The price of the item after its discounts have been applied, in the currency's minor unit.
-
#price_override ⇒ PriceOverride
Details of a manual price override applied to this item; null when none was applied.
-
#price_tax ⇒ Integer
Total tax amount for the item, in the currency's minor unit.
-
#pricebook ⇒ String
A reference to the pricebook used to lookup list_price.
-
#tax_lines ⇒ Array[TaxLine]
Optional breakdown of the taxes that make up
price_tax.
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
-
#initialize(list_price = nil, price = nil, default_list_price = SKIP, discounts = SKIP, price_override = SKIP, price_tax = 0, pricebook = 'default', tax_lines = SKIP) ⇒ LineItemPrice
constructor
A new instance of LineItemPrice.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(list_price = nil, price = nil, default_list_price = SKIP, discounts = SKIP, price_override = SKIP, price_tax = 0, pricebook = 'default', tax_lines = SKIP) ⇒ LineItemPrice
Returns a new instance of LineItemPrice.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/new_store_api/models/line_item_price.rb', line 91 def initialize(list_price = nil, price = nil, default_list_price = SKIP, discounts = SKIP, price_override = SKIP, price_tax = 0, pricebook = 'default', tax_lines = SKIP) @default_list_price = default_list_price unless default_list_price == SKIP @discounts = discounts unless discounts == SKIP @list_price = list_price @price = price @price_override = price_override unless price_override == SKIP @price_tax = price_tax unless price_tax == SKIP @pricebook = pricebook unless pricebook == SKIP @tax_lines = tax_lines unless tax_lines == SKIP end |
Instance Attribute Details
#default_list_price ⇒ Integer
The price of the product in the default pricebook, in the currency's minor
unit. Differs from list_price when the item was priced from another
pricebook. Null when not supplied.
16 17 18 |
# File 'lib/new_store_api/models/line_item_price.rb', line 16 def default_list_price @default_list_price end |
#discounts ⇒ Array[Object]
Discounts applied to this item, item-level or order-level prorated onto it
(see scope). Their applied_amount is already deducted from price, so
they describe how list_price became price rather than a further
reduction to apply.
23 24 25 |
# File 'lib/new_store_api/models/line_item_price.rb', line 23 def discounts @discounts end |
#list_price ⇒ Integer
The price of the product in the chosen pricebook, in the currency's minor unit. This is the price the item's discounts are applied to.
28 29 30 |
# File 'lib/new_store_api/models/line_item_price.rb', line 28 def list_price @list_price end |
#price ⇒ Integer
The price of the item after its discounts have been applied, in the
currency's minor unit. It must equal list_price minus the sum of
discounts[].applied_amount, or, when a price_override is supplied, the
overridden price.
35 36 37 |
# File 'lib/new_store_api/models/line_item_price.rb', line 35 def price @price end |
#price_override ⇒ PriceOverride
Details of a manual price override applied to this item; null when none was applied.
40 41 42 |
# File 'lib/new_store_api/models/line_item_price.rb', line 40 def price_override @price_override end |
#price_tax ⇒ Integer
Total tax amount for the item, in the currency's minor unit. With
tax_excluded pricing the customer pays price plus this tax; with
tax_included pricing this is the tax already contained in price.
Defaults to 0.
47 48 49 |
# File 'lib/new_store_api/models/line_item_price.rb', line 47 def price_tax @price_tax end |
#pricebook ⇒ String
A reference to the pricebook used to lookup list_price
51 52 53 |
# File 'lib/new_store_api/models/line_item_price.rb', line 51 def pricebook @pricebook end |
#tax_lines ⇒ Array[TaxLine]
Optional breakdown of the taxes that make up price_tax.
55 56 57 |
# File 'lib/new_store_api/models/line_item_price.rb', line 55 def tax_lines @tax_lines end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/new_store_api/models/line_item_price.rb', line 105 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. list_price = hash.key?('list_price') ? hash['list_price'] : nil price = hash.key?('price') ? hash['price'] : nil default_list_price = hash.key?('default_list_price') ? hash['default_list_price'] : SKIP discounts = hash.key?('discounts') ? APIHelper.deserialize_union_type( UnionTypeLookUp.get(:LineItemPriceDiscounts), hash['discounts'] ) : SKIP price_override = PriceOverride.from_hash(hash['price_override']) if hash['price_override'] price_tax = hash['price_tax'] ||= 0 pricebook = hash['pricebook'] ||= 'default' # Parameter is an array, so we need to iterate through it tax_lines = nil unless hash['tax_lines'].nil? tax_lines = [] hash['tax_lines'].each do |structure| tax_lines << (TaxLine.from_hash(structure) if structure) end end tax_lines = SKIP unless hash.key?('tax_lines') # Create object from extracted values. LineItemPrice.new(list_price, price, default_list_price, discounts, price_override, price_tax, pricebook, tax_lines) end |
.names ⇒ Object
A mapping from model property names to API property names.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/new_store_api/models/line_item_price.rb', line 58 def self.names @_hash = {} if @_hash.nil? @_hash['default_list_price'] = 'default_list_price' @_hash['discounts'] = 'discounts' @_hash['list_price'] = 'list_price' @_hash['price'] = 'price' @_hash['price_override'] = 'price_override' @_hash['price_tax'] = 'price_tax' @_hash['pricebook'] = 'pricebook' @_hash['tax_lines'] = 'tax_lines' @_hash end |
.nullables ⇒ Object
An array for nullable fields
84 85 86 87 88 89 |
# File 'lib/new_store_api/models/line_item_price.rb', line 84 def self.nullables %w[ default_list_price price_override ] end |
.optionals ⇒ Object
An array for optional fields
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/new_store_api/models/line_item_price.rb', line 72 def self.optionals %w[ default_list_price discounts price_override price_tax pricebook tax_lines ] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/new_store_api/models/line_item_price.rb', line 143 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value.list_price, ->(val) { val.instance_of? Integer }) and APIHelper.valid_type?(value.price, ->(val) { val.instance_of? Integer }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['list_price'], ->(val) { val.instance_of? Integer }) and APIHelper.valid_type?(value['price'], ->(val) { val.instance_of? Integer }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
172 173 174 175 176 177 178 |
# File 'lib/new_store_api/models/line_item_price.rb', line 172 def inspect class_name = self.class.name.split('::').last "<#{class_name} default_list_price: #{@default_list_price.inspect}, discounts:"\ " #{@discounts.inspect}, list_price: #{@list_price.inspect}, price: #{@price.inspect},"\ " price_override: #{@price_override.inspect}, price_tax: #{@price_tax.inspect}, pricebook:"\ " #{@pricebook.inspect}, tax_lines: #{@tax_lines.inspect}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
164 165 166 167 168 169 |
# File 'lib/new_store_api/models/line_item_price.rb', line 164 def to_s class_name = self.class.name.split('::').last "<#{class_name} default_list_price: #{@default_list_price}, discounts: #{@discounts},"\ " list_price: #{@list_price}, price: #{@price}, price_override: #{@price_override},"\ " price_tax: #{@price_tax}, pricebook: #{@pricebook}, tax_lines: #{@tax_lines}>" end |