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

Inherits:
ExpandableOrder show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

An order represents all of the information about a particular set of line items, 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 payment authorization(s) covering the full balance of an order.

Instance Attribute Summary collapse

Attributes inherited from ExpandableOrder

#discriminator

Instance Method Summary collapse

Methods inherited from ExpandableOrder

from_json, #to_hash

Constructor Details

#initialize(incoming = {}) ⇒ Order

Returns a new instance of Order.



47350
47351
47352
47353
47354
47355
47356
47357
47358
47359
47360
47361
47362
47363
47364
47365
47366
47367
47368
47369
47370
47371
47372
47373
47374
47375
47376
47377
47378
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47350

def initialize(incoming={})
  super(:discriminator => ExpandableOrder::Types::ORDER)
  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)
  @order_type = (x = (x = opts.delete(:order_type); x.nil? ? "standard" : x); x.is_a?(::Io::Flow::V0::Models::OrderType) ? x : ::Io::Flow::V0::Models::OrderType.apply(x))
  @merchant_of_record = (x = opts.delete(:merchant_of_record); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderMerchantOfRecord) ? x : ::Io::Flow::V0::Models::OrderMerchantOfRecord.apply(x)))
  @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::OrderCustomer) ? x : ::Io::Flow::V0::Models::OrderCustomer.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.from_json(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)))
  @payments = (x = opts.delete(:payments); x.nil? ? nil : HttpClient::Preconditions.assert_class('payments', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::OrderPayment) ? x : ::Io::Flow::V0::Models::OrderPayment.new(x)) })
  @balance = (x = opts.delete(:balance); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::LocalizedTotal) ? x : ::Io::Flow::V0::Models::LocalizedTotal.new(x)))
  @rules = (x = opts.delete(:rules); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderRulesSummary) ? x : ::Io::Flow::V0::Models::OrderRulesSummary.new(x)))
  @tax_registration = (x = opts.delete(:tax_registration); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::TaxRegistration) ? x : ::Io::Flow::V0::Models::TaxRegistration.new(x)))
  @geo = (x = opts.delete(:geo); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderGeo) ? x : ::Io::Flow::V0::Models::OrderGeo.new(x)))
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def attributes
  @attributes
end

#balanceObject (readonly)

Returns the value of attribute balance.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def balance
  @balance
end

#customerObject (readonly)

Returns the value of attribute customer.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def customer
  @customer
end

#delivered_dutyObject (readonly)

Returns the value of attribute delivered_duty.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def delivered_duty
  @delivered_duty
end

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def deliveries
  @deliveries
end

#destinationObject (readonly)

Returns the value of attribute destination.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def destination
  @destination
end

#experienceObject (readonly)

Returns the value of attribute experience.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def experience
  @experience
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def expires_at
  @expires_at
end

#geoObject (readonly)

Returns the value of attribute geo.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def geo
  @geo
end

#idObject (readonly)

Returns the value of attribute id.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def id
  @id
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def identifiers
  @identifiers
end

#itemsObject (readonly)

Returns the value of attribute items.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def items
  @items
end

#linesObject (readonly)

Returns the value of attribute lines.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def lines
  @lines
end

#merchant_of_recordObject (readonly)

Returns the value of attribute merchant_of_record.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def merchant_of_record
  @merchant_of_record
end

#numberObject (readonly)

Returns the value of attribute number.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def number
  @number
end

#order_typeObject (readonly)

Returns the value of attribute order_type.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def order_type
  @order_type
end

#paymentsObject (readonly)

Returns the value of attribute payments.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def payments
  @payments
end

#pricesObject (readonly)

Returns the value of attribute prices.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def prices
  @prices
end

#promotionsObject (readonly)

Returns the value of attribute promotions.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def promotions
  @promotions
end

#rulesObject (readonly)

Returns the value of attribute rules.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def rules
  @rules
end

#selectionsObject (readonly)

Returns the value of attribute selections.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def selections
  @selections
end

#submitted_atObject (readonly)

Returns the value of attribute submitted_at.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def 
  @submitted_at
end

#tax_registrationObject (readonly)

Returns the value of attribute tax_registration.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def tax_registration
  @tax_registration
end

#totalObject (readonly)

Returns the value of attribute total.



47348
47349
47350
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47348

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



47384
47385
47386
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47384

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

#subtype_to_hashObject



47388
47389
47390
47391
47392
47393
47394
47395
47396
47397
47398
47399
47400
47401
47402
47403
47404
47405
47406
47407
47408
47409
47410
47411
47412
47413
47414
47415
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47388

def subtype_to_hash
  {
    :id => id,
    :number => number,
    :order_type => order_type.value,
    :merchant_of_record => merchant_of_record.nil? ? nil : merchant_of_record.value,
    :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,
    :payments => payments.nil? ? nil : payments.map { |o| o.to_hash },
    :balance => balance.nil? ? nil : balance.to_hash,
    :rules => rules.nil? ? nil : rules.to_hash,
    :tax_registration => tax_registration.nil? ? nil : tax_registration.to_hash,
    :geo => geo.nil? ? nil : geo.to_hash
  }
end

#to_jsonObject



47380
47381
47382
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47380

def to_json
  JSON.dump(to_hash)
end