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.



16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16574

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :number, :customer, :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)
  @customer = (x = opts.delete(:customer); x.is_a?(::Io::Flow::V0::Models::Customer) ? x : ::Io::Flow::V0::Models::Customer.new(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

#attributes ⇒ Object (readonly)

Returns the value of attribute attributes.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def attributes
  @attributes
end

#customer ⇒ Object (readonly)

Returns the value of attribute customer.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def customer
  @customer
end

#deliveries ⇒ Object (readonly)

Returns the value of attribute deliveries.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def deliveries
  @deliveries
end

#destination ⇒ Object (readonly)

Returns the value of attribute destination.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def destination
  @destination
end

#expires_at ⇒ Object (readonly)

Returns the value of attribute expires_at.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def expires_at
  @expires_at
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def id
  @id
end

#identifiers ⇒ Object (readonly)

Returns the value of attribute identifiers.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def identifiers
  @identifiers
end

#items ⇒ Object (readonly)

Returns the value of attribute items.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def items
  @items
end

#lines ⇒ Object (readonly)

Returns the value of attribute lines.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def lines
  @lines
end

#number ⇒ Object (readonly)

Returns the value of attribute number.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def number
  @number
end

#prices ⇒ Object (readonly)

Returns the value of attribute prices.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def prices
  @prices
end

#promotions ⇒ Object (readonly)

Returns the value of attribute promotions.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def promotions
  @promotions
end

#selections ⇒ Object (readonly)

Returns the value of attribute selections.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def selections
  @selections
end

#submitted_at ⇒ Object (readonly)

Returns the value of attribute submitted_at.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def 
  @submitted_at
end

#total ⇒ Object (readonly)

Returns the value of attribute total.



16572
16573
16574
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16572

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



16598
16599
16600
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16598

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

#to_hash ⇒ Object



16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16602

def to_hash
  {
    :id => id,
    :number => number,
    :customer => customer.to_hash,
    :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_json ⇒ Object



16594
16595
16596
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16594

def to_json
  JSON.dump(to_hash)
end