Class: Io::Flow::V0::Models::Order

Inherits:
Object
  • Object
show all
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 submitted before its expiration. The intended use case is to create an order as a consumer enters checkout, then to submit that order as part of the user submitting their order. Note that Flow will automatically mark an order submitted if we see a payment authorization for an order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Order

Returns a new instance of Order.



17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17738

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :number, :customer, :delivered_duty, :destination, :expires_at, :items, :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)
  @experience = (x = opts.delete(:experience); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::ExpandableExperience) ? x : ::Io::Flow::V0::Models::ExpandableExperience.from_json(x)))
  @customer = (x = opts.delete(:customer); x.is_a?(::Io::Flow::V0::Models::Customer) ? x : ::Io::Flow::V0::Models::Customer.new(x))
  @delivered_duty = (x = opts.delete(:delivered_duty); x.is_a?(::Io::Flow::V0::Models::DeliveredDuty) ? x : ::Io::Flow::V0::Models::DeliveredDuty.apply(x))
  @destination = (x = opts.delete(:destination); x.is_a?(::Io::Flow::V0::Models::OrderAddress) ? x : ::Io::Flow::V0::Models::OrderAddress.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)) }
  @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 }
  @submitted_at = (x = opts.delete(:submitted_at); x.nil? ? nil : HttpClient::Preconditions.assert_class('submitted_at', HttpClient::Helper.to_date_time_iso8601(x), DateTime))
  @lines = (x = opts.delete(:lines); x.nil? ? nil : HttpClient::Preconditions.assert_class('lines', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::Line) ? x : ::Io::Flow::V0::Models::Line.new(x)) })
  @identifiers = (x = opts.delete(:identifiers); x.nil? ? nil : HttpClient::Preconditions.assert_class('identifiers', x, Array).map { |v| HttpClient::Preconditions.assert_class('identifiers', v, String) })
  @promotions = (x = opts.delete(:promotions); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Promotions) ? x : ::Io::Flow::V0::Models::Promotions.new(x)))
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def attributes
  @attributes
end

#customerObject (readonly)

Returns the value of attribute customer.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def customer
  @customer
end

#delivered_dutyObject (readonly)

Returns the value of attribute delivered_duty.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def delivered_duty
  @delivered_duty
end

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def deliveries
  @deliveries
end

#destinationObject (readonly)

Returns the value of attribute destination.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def destination
  @destination
end

#experienceObject (readonly)

Returns the value of attribute experience.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def experience
  @experience
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def expires_at
  @expires_at
end

#idObject (readonly)

Returns the value of attribute id.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def id
  @id
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def identifiers
  @identifiers
end

#itemsObject (readonly)

Returns the value of attribute items.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def items
  @items
end

#linesObject (readonly)

Returns the value of attribute lines.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def lines
  @lines
end

#numberObject (readonly)

Returns the value of attribute number.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def number
  @number
end

#pricesObject (readonly)

Returns the value of attribute prices.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def prices
  @prices
end

#promotionsObject (readonly)

Returns the value of attribute promotions.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def promotions
  @promotions
end

#selectionsObject (readonly)

Returns the value of attribute selections.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def selections
  @selections
end

#submitted_atObject (readonly)

Returns the value of attribute submitted_at.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def 
  @submitted_at
end

#totalObject (readonly)

Returns the value of attribute total.



17736
17737
17738
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17736

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



17764
17765
17766
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17764

def copy(incoming={})
  Order.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17768

def to_hash
  {
    :id => id,
    :number => number,
    :experience => experience.nil? ? nil : experience.to_hash,
    :customer => customer.to_hash,
    :delivered_duty => delivered_duty.value,
    :destination => destination.to_hash,
    :expires_at => expires_at,
    :items => items.map { |o| o.to_hash },
    :deliveries => deliveries.map { |o| o.to_hash },
    :selections => selections,
    :prices => prices.map { |o| o.to_hash },
    :total => total.to_hash,
    :attributes => attributes,
    :submitted_at => ,
    :lines => lines.nil? ? nil : lines.map { |o| o.to_hash },
    :identifiers => identifiers.nil? ? nil : identifiers,
    :promotions => promotions.nil? ? nil : promotions.to_hash
  }
end

#to_jsonObject



17760
17761
17762
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17760

def to_json
  JSON.dump(to_hash)
end