Class: Io::Flow::V0::Models::B2bInvoice

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

Overview

The b2b invoice represents a transaction between Flow and one of our clients (e.g. Flow purchasing inventory to resell to a consumer).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ B2bInvoice

Returns a new instance of B2bInvoice.



31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31980

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :number, :buyer, :seller, :status, :date, :key, :order, :economic_title_location, :tax, :lines, :documents, :attributes], 'B2bInvoice')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
  @buyer = (x = opts.delete(:buyer); x.is_a?(::Io::Flow::V0::Models::MerchantOfRecordEntity) ? x : ::Io::Flow::V0::Models::MerchantOfRecordEntity.new(x))
  @seller = (x = opts.delete(:seller); x.is_a?(::Io::Flow::V0::Models::MerchantOfRecordEntity) ? x : ::Io::Flow::V0::Models::MerchantOfRecordEntity.new(x))
  @status = (x = opts.delete(:status); x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceStatus) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceStatus.apply(x))
  @date = HttpClient::Preconditions.assert_class('date', HttpClient::Helper.to_date_time_iso8601(opts.delete(:date)), DateTime)
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
  @order = (x = opts.delete(:order); x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceOrderSummary) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceOrderSummary.new(x))
  @economic_title_location = (x = opts.delete(:economic_title_location); x.is_a?(::Io::Flow::V0::Models::EconomicTitleLocation) ? x : ::Io::Flow::V0::Models::EconomicTitleLocation.apply(x))
  @center = (x = opts.delete(:center); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceCenterReference) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceCenterReference.new(x)))
  @destination = (x = opts.delete(:destination); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderAddress) ? x : ::Io::Flow::V0::Models::OrderAddress.new(x)))
  @tax = (x = opts.delete(:tax); x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x))
  @lines = HttpClient::Preconditions.assert_class('lines', opts.delete(:lines), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceLine) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceLine.from_json(x)) }
  @documents = HttpClient::Preconditions.assert_class('documents', opts.delete(:documents), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceDocument) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceDocument.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 }
  @estimated_delivery_date = (x = opts.delete(:estimated_delivery_date); x.nil? ? nil : HttpClient::Preconditions.assert_class('estimated_delivery_date', HttpClient::Helper.to_date_time_iso8601(x), DateTime))
  @b2b_invoice_type = (x = (x = opts.delete(:b2b_invoice_type); x.nil? ? "self_bill_invoice" : x); x.is_a?(::Io::Flow::V0::Models::B2bInvoiceType) ? x : ::Io::Flow::V0::Models::B2bInvoiceType.apply(x))
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def attributes
  @attributes
end

#b2b_invoice_typeObject (readonly)

Returns the value of attribute b2b_invoice_type.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def b2b_invoice_type
  @b2b_invoice_type
end

#buyerObject (readonly)

Returns the value of attribute buyer.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def buyer
  @buyer
end

#centerObject (readonly)

Returns the value of attribute center.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def center
  @center
end

#dateObject (readonly)

Returns the value of attribute date.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def date
  @date
end

#destinationObject (readonly)

Returns the value of attribute destination.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def destination
  @destination
end

#documentsObject (readonly)

Returns the value of attribute documents.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def documents
  @documents
end

#economic_title_locationObject (readonly)

Returns the value of attribute economic_title_location.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def economic_title_location
  @economic_title_location
end

#estimated_delivery_dateObject (readonly)

Returns the value of attribute estimated_delivery_date.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def estimated_delivery_date
  @estimated_delivery_date
end

#idObject (readonly)

Returns the value of attribute id.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def key
  @key
end

#linesObject (readonly)

Returns the value of attribute lines.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def lines
  @lines
end

#numberObject (readonly)

Returns the value of attribute number.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def number
  @number
end

#orderObject (readonly)

Returns the value of attribute order.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def order
  @order
end

#sellerObject (readonly)

Returns the value of attribute seller.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def seller
  @seller
end

#statusObject (readonly)

Returns the value of attribute status.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def status
  @status
end

#taxObject (readonly)

Returns the value of attribute tax.



31978
31979
31980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31978

def tax
  @tax
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



32006
32007
32008
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32006

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

#to_hashObject



32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32010

def to_hash
  {
    :id => id,
    :number => number,
    :buyer => buyer.to_hash,
    :seller => seller.to_hash,
    :status => status.value,
    :date => date,
    :key => key,
    :order => order.to_hash,
    :economic_title_location => economic_title_location.value,
    :center => center.nil? ? nil : center.to_hash,
    :destination => destination.nil? ? nil : destination.to_hash,
    :tax => tax.to_hash,
    :lines => lines.map { |o| o.to_hash },
    :documents => documents.map { |o| o.to_hash },
    :attributes => attributes,
    :estimated_delivery_date => estimated_delivery_date,
    :b2b_invoice_type => b2b_invoice_type.value
  }
end

#to_jsonObject



32002
32003
32004
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32002

def to_json
  JSON.dump(to_hash)
end