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.



18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18338

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :buyer, :seller, :status, :date, :key, :order, :economic_title_location, :lines, :documents, :attributes], 'B2bInvoice')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), 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 = HttpClient::Preconditions.assert_class('economic_title_location', opts.delete(:economic_title_location), String)
  @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)))
  @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 }
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def attributes
  @attributes
end

#buyerObject (readonly)

Returns the value of attribute buyer.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def buyer
  @buyer
end

#centerObject (readonly)

Returns the value of attribute center.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def center
  @center
end

#dateObject (readonly)

Returns the value of attribute date.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def date
  @date
end

#destinationObject (readonly)

Returns the value of attribute destination.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def destination
  @destination
end

#documentsObject (readonly)

Returns the value of attribute documents.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def documents
  @documents
end

#economic_title_locationObject (readonly)

Returns the value of attribute economic_title_location.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def economic_title_location
  @economic_title_location
end

#idObject (readonly)

Returns the value of attribute id.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def key
  @key
end

#linesObject (readonly)

Returns the value of attribute lines.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def lines
  @lines
end

#orderObject (readonly)

Returns the value of attribute order.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def order
  @order
end

#sellerObject (readonly)

Returns the value of attribute seller.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def seller
  @seller
end

#statusObject (readonly)

Returns the value of attribute status.



18336
18337
18338
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18336

def status
  @status
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



18360
18361
18362
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18360

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

#to_hashObject



18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18364

def to_hash
  {
    :id => id,
    :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,
    :center => center.nil? ? nil : center.to_hash,
    :destination => destination.nil? ? nil : destination.to_hash,
    :lines => lines.map { |o| o.to_hash },
    :documents => documents.map { |o| o.to_hash },
    :attributes => attributes
  }
end

#to_jsonObject



18356
18357
18358
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18356

def to_json
  JSON.dump(to_hash)
end