Class: Io::Flow::V0::Models::Order
- Inherits:
-
Object
- Object
- Io::Flow::V0::Models::Order
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Overview
An order represents all of the information about a particular line item, including pricing, currency rates, delivery options, etc. All information in an order is guaranteed by Flow - if an order is booked before its expiration. The intended use case is to create an order as a consumer enters checkout, then to book that order in order processing.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#deliveries ⇒ Object
readonly
Returns the value of attribute deliveries.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#prices ⇒ Object
readonly
Returns the value of attribute prices.
-
#selections ⇒ Object
readonly
Returns the value of attribute selections.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #copy(incoming = {}) ⇒ Object
-
#initialize(incoming = {}) ⇒ Order
constructor
A new instance of Order.
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(incoming = {}) ⇒ Order
Returns a new instance of Order.
14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14378 def initialize(incoming={}) opts = HttpClient::Helper.symbolize_keys(incoming) HttpClient::Preconditions.require_keys(opts, [:id, :number, :customer, :expires_at, :items, :destination, :deliveries, :selections, :prices, :total, :attributes], 'Order') @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String) @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String) @customer = (x = opts.delete(:customer); x.is_a?(::Io::Flow::V0::Models::Customer) ? x : ::Io::Flow::V0::Models::Customer.new(x)) @expires_at = HttpClient::Preconditions.assert_class('expires_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:expires_at)), DateTime) @items = HttpClient::Preconditions.assert_class('items', opts.delete(:items), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::LocalizedLineItem) ? x : ::Io::Flow::V0::Models::LocalizedLineItem.new(x)) } @destination = (x = opts.delete(:destination); x.is_a?(::Io::Flow::V0::Models::Address) ? x : ::Io::Flow::V0::Models::Address.new(x)) @deliveries = HttpClient::Preconditions.assert_class('deliveries', opts.delete(:deliveries), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::Delivery) ? x : ::Io::Flow::V0::Models::Delivery.new(x)) } @selections = HttpClient::Preconditions.assert_class('selections', opts.delete(:selections), Array).map { |v| HttpClient::Preconditions.assert_class('selections', v, String) } @prices = HttpClient::Preconditions.assert_class('prices', opts.delete(:prices), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::OrderPriceDetail) ? x : ::Io::Flow::V0::Models::OrderPriceDetail.new(x)) } @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::LocalizedTotal) ? x : ::Io::Flow::V0::Models::LocalizedTotal.new(x)) @attributes = HttpClient::Preconditions.assert_class('attributes', opts.delete(:attributes), Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h } end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def attributes @attributes end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def customer @customer end |
#deliveries ⇒ Object (readonly)
Returns the value of attribute deliveries.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def deliveries @deliveries end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def destination @destination end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def expires_at @expires_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def id @id end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def items @items end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def number @number end |
#prices ⇒ Object (readonly)
Returns the value of attribute prices.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def prices @prices end |
#selections ⇒ Object (readonly)
Returns the value of attribute selections.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def selections @selections end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
14376 14377 14378 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14376 def total @total end |
Instance Method Details
#copy(incoming = {}) ⇒ Object
14398 14399 14400 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14398 def copy(incoming={}) Order.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming))) end |
#to_hash ⇒ Object
14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14402 def to_hash { :id => id, :number => number, :customer => customer.to_hash, :expires_at => expires_at, :items => items.map { |o| o.to_hash }, :destination => destination.to_hash, :deliveries => deliveries.map { |o| o.to_hash }, :selections => selections, :prices => prices.map { |o| o.to_hash }, :total => total.to_hash, :attributes => attributes } end |
#to_json ⇒ Object
14394 14395 14396 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14394 def to_json JSON.dump(to_hash) end |