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 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

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Order

Returns a new instance of Order.



12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12747

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::LocalizedPrice) ? x : ::Io::Flow::V0::Models::LocalizedPrice.new(x)) }
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::LocalizedPrice) ? x : ::Io::Flow::V0::Models::LocalizedPrice.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

#attributesObject (readonly)

Returns the value of attribute attributes.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def attributes
  @attributes
end

#customerObject (readonly)

Returns the value of attribute customer.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def customer
  @customer
end

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def deliveries
  @deliveries
end

#destinationObject (readonly)

Returns the value of attribute destination.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def destination
  @destination
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def expires_at
  @expires_at
end

#idObject (readonly)

Returns the value of attribute id.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def id
  @id
end

#itemsObject (readonly)

Returns the value of attribute items.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def items
  @items
end

#numberObject (readonly)

Returns the value of attribute number.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def number
  @number
end

#pricesObject (readonly)

Returns the value of attribute prices.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def prices
  @prices
end

#selectionsObject (readonly)

Returns the value of attribute selections.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def selections
  @selections
end

#totalObject (readonly)

Returns the value of attribute total.



12745
12746
12747
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12745

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



12767
12768
12769
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12767

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

#to_hashObject



12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12771

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_jsonObject



12763
12764
12765
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12763

def to_json
  JSON.dump(to_hash)
end