class VertexClient::Payload::Quotation

Constants

SALE_TRANSACTION_TYPE

Public Instance Methods

body() click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 11
def body
  {
    :'@transactionType' => SALE_TRANSACTION_TYPE,
    line_item: params[:line_items].map.with_index do |line_item, index|
      transform_line_item(line_item, index, params)
    end
  }
end
validate!() click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 7
def validate!
  raise VertexClient::ValidationError.new('customer requires a state and postal_code') if customer_missing_location?
end

Private Instance Methods

customer_destination_present?(customer) click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 38
def customer_destination_present?(customer)
  customer[:state].present? && customer[:postal_code].present?
end
customer_lines(params) click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 34
def customer_lines(params)
  [params[:customer], params[:line_items].map { |li| li[:customer]}].flatten.compact
end
customer_missing_location?() click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 22
def customer_missing_location?
  !customer_lines(params).all? { |customer| customer_destination_present?(customer) }
end
transform_customer(customer_params) click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 26
def transform_customer(customer_params)
  super(customer_params).tap do |customer|
    if customer_params[:tax_area_id].present?
      customer[:destination] = { :@taxAreaId => customer_params[:tax_area_id]}
    end
  end
end
transform_line_item(line_item, number, defaults) click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 42
def transform_line_item(line_item, number, defaults)
  remove_nils({
    :'@lineItemNumber' => number+1,
    :'@taxDate' =>  line_item[:date] || defaults[:date],
    :'@locationCode' => line_item[:location_code] || defaults[:location_code],
    customer:       transform_customer(line_item[:customer] || defaults[:customer]),
    seller:         transform_seller(line_item[:seller] || defaults[:seller]),
    product:        transform_product(line_item),
    quantity:       line_item[:quantity],
    extended_price: line_item[:price],
  })
end
transform_product(line_item) click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 61
def transform_product(line_item)
  {
    :'@productClass' => line_item[:product_class],
    :content! => line_item[:product_code]
  }
end
transform_seller(seller) click to toggle source
# File lib/vertex_client/payloads/quotation.rb, line 55
def transform_seller(seller)
  {
    company: seller[:company]
  }
end