class SquareConnect::Order

Contains all information related to a single order to process with Square, including line items that specify the products to purchase. Order objects also include information on any associated tenders, refunds, and returns. All Connect V2 Transactions have all been converted to Orders including all associated itemization data.

Attributes

closed_at[RW]

Timestamp for when the order was closed. In RFC 3339 format, e.g., "2016-09-04T23:59:33.123Z". This field is read-only.

created_at[RW]

Timestamp for when the order was created. In RFC 3339 format, e.g., "2016-09-04T23:59:33.123Z". This field is read-only.

customer_id[RW]

The [Customer](type-customer) ID of the customer associated with the order.

discounts[RW]

A list of discounts applied to this order. On read or retrieve, this list includes both order-level and item-level discounts. When creating an Order, set your order-level discounts in this list.

fulfillments[RW]

Details on order fulfillment. Orders can only be created with at most one fulfillment. However, orders returned by the API may contain multiple fulfillments.

id[RW]

The order's unique ID. This field is read-only.

line_items[RW]

The line items included in the order.

location_id[RW]

The ID of the merchant location this order is associated with.

net_amounts[RW]

Net money amounts (sale money - return money). This field is read-only.

reference_id[RW]

A client specified identifier to associate an entity in another system with this order.

refunds[RW]

The Refunds that are part of this Order. This field is read-only.

return_amounts[RW]

Rollup of returned money amounts. This field is read-only.

returns[RW]

Collection of items from sale Orders being returned in this one. Normally part of an Itemized Return or Exchange. There will be exactly one `Return` object per sale Order being referenced. This field is read-only.

rounding_adjustment[RW]

A positive or negative rounding adjustment to the total of the order, commonly used to apply Cash Rounding when the minimum unit of account is smaller than the lowest physical denomination of currency. This field is read-only.

service_charges[RW]

A list of service charges applied to the order.

source[RW]

The origination details of the order.

state[RW]

The current state of the order. `OPEN`,`COMPLETED`,`CANCELED` See [OrderState](type-orderstate) for possible values

taxes[RW]

A list of taxes applied to this order. On read or retrieve, this list includes both order-level and item-level taxes. When creating an Order, set your order-level taxes in this list.

tenders[RW]

The Tenders which were used to pay for the Order. This field is read-only.

total_discount_money[RW]

The total discount amount of money to collect for the order. This field is read-only.

total_money[RW]

The total amount of money to collect for the order. This field is read-only.

total_service_charge_money[RW]

The total amount of money collected in service charges for the order. Note: `total_service_charge_money` is the sum of `applied_money` fields for each individual service charge. Therefore, `total_service_charge_money` will only include inclusive tax amounts, not additive tax amounts. This field is read-only.

total_tax_money[RW]

The total tax amount of money to collect for the order. This field is read-only.

updated_at[RW]

Timestamp for when the order was last updated. In RFC 3339 format, e.g., "2016-09-04T23:59:33.123Z". This field is read-only.

Public Class Methods

attribute_map() click to toggle source

Attribute mapping from ruby-style variable name to JSON key.

# File lib/square_connect/models/order.rb, line 89
def self.attribute_map
  {
    :'id' => :'id',
    :'location_id' => :'location_id',
    :'reference_id' => :'reference_id',
    :'source' => :'source',
    :'customer_id' => :'customer_id',
    :'line_items' => :'line_items',
    :'taxes' => :'taxes',
    :'discounts' => :'discounts',
    :'service_charges' => :'service_charges',
    :'fulfillments' => :'fulfillments',
    :'returns' => :'returns',
    :'return_amounts' => :'return_amounts',
    :'net_amounts' => :'net_amounts',
    :'rounding_adjustment' => :'rounding_adjustment',
    :'tenders' => :'tenders',
    :'refunds' => :'refunds',
    :'created_at' => :'created_at',
    :'updated_at' => :'updated_at',
    :'closed_at' => :'closed_at',
    :'state' => :'state',
    :'total_money' => :'total_money',
    :'total_tax_money' => :'total_tax_money',
    :'total_discount_money' => :'total_discount_money',
    :'total_service_charge_money' => :'total_service_charge_money'
  }
end
new(attributes = {}) click to toggle source

Initializes the object @param [Hash] attributes Model attributes in the form of hash

# File lib/square_connect/models/order.rb, line 150
def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}

  if attributes.has_key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.has_key?(:'location_id')
    self.location_id = attributes[:'location_id']
  end

  if attributes.has_key?(:'reference_id')
    self.reference_id = attributes[:'reference_id']
  end

  if attributes.has_key?(:'source')
    self.source = attributes[:'source']
  end

  if attributes.has_key?(:'customer_id')
    self.customer_id = attributes[:'customer_id']
  end

  if attributes.has_key?(:'line_items')
    if (value = attributes[:'line_items']).is_a?(Array)
      self.line_items = value
    end
  end

  if attributes.has_key?(:'taxes')
    if (value = attributes[:'taxes']).is_a?(Array)
      self.taxes = value
    end
  end

  if attributes.has_key?(:'discounts')
    if (value = attributes[:'discounts']).is_a?(Array)
      self.discounts = value
    end
  end

  if attributes.has_key?(:'service_charges')
    if (value = attributes[:'service_charges']).is_a?(Array)
      self.service_charges = value
    end
  end

  if attributes.has_key?(:'fulfillments')
    if (value = attributes[:'fulfillments']).is_a?(Array)
      self.fulfillments = value
    end
  end

  if attributes.has_key?(:'returns')
    if (value = attributes[:'returns']).is_a?(Array)
      self.returns = value
    end
  end

  if attributes.has_key?(:'return_amounts')
    self.return_amounts = attributes[:'return_amounts']
  end

  if attributes.has_key?(:'net_amounts')
    self.net_amounts = attributes[:'net_amounts']
  end

  if attributes.has_key?(:'rounding_adjustment')
    self.rounding_adjustment = attributes[:'rounding_adjustment']
  end

  if attributes.has_key?(:'tenders')
    if (value = attributes[:'tenders']).is_a?(Array)
      self.tenders = value
    end
  end

  if attributes.has_key?(:'refunds')
    if (value = attributes[:'refunds']).is_a?(Array)
      self.refunds = value
    end
  end

  if attributes.has_key?(:'created_at')
    self.created_at = attributes[:'created_at']
  end

  if attributes.has_key?(:'updated_at')
    self.updated_at = attributes[:'updated_at']
  end

  if attributes.has_key?(:'closed_at')
    self.closed_at = attributes[:'closed_at']
  end

  if attributes.has_key?(:'state')
    self.state = attributes[:'state']
  end

  if attributes.has_key?(:'total_money')
    self.total_money = attributes[:'total_money']
  end

  if attributes.has_key?(:'total_tax_money')
    self.total_tax_money = attributes[:'total_tax_money']
  end

  if attributes.has_key?(:'total_discount_money')
    self.total_discount_money = attributes[:'total_discount_money']
  end

  if attributes.has_key?(:'total_service_charge_money')
    self.total_service_charge_money = attributes[:'total_service_charge_money']
  end

end
swagger_types() click to toggle source

Attribute type mapping.

# File lib/square_connect/models/order.rb, line 119
def self.swagger_types
  {
    :'id' => :'String',
    :'location_id' => :'String',
    :'reference_id' => :'String',
    :'source' => :'OrderSource',
    :'customer_id' => :'String',
    :'line_items' => :'Array<OrderLineItem>',
    :'taxes' => :'Array<OrderLineItemTax>',
    :'discounts' => :'Array<OrderLineItemDiscount>',
    :'service_charges' => :'Array<OrderServiceCharge>',
    :'fulfillments' => :'Array<OrderFulfillment>',
    :'returns' => :'Array<OrderReturn>',
    :'return_amounts' => :'OrderMoneyAmounts',
    :'net_amounts' => :'OrderMoneyAmounts',
    :'rounding_adjustment' => :'OrderRoundingAdjustment',
    :'tenders' => :'Array<Tender>',
    :'refunds' => :'Array<Refund>',
    :'created_at' => :'String',
    :'updated_at' => :'String',
    :'closed_at' => :'String',
    :'state' => :'String',
    :'total_money' => :'Money',
    :'total_tax_money' => :'Money',
    :'total_discount_money' => :'Money',
    :'total_service_charge_money' => :'Money'
  }
end

Public Instance Methods

==(o) click to toggle source

Checks equality by comparing each attribute. @param [Object] Object to be compared

# File lib/square_connect/models/order.rb, line 325
def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      location_id == o.location_id &&
      reference_id == o.reference_id &&
      source == o.source &&
      customer_id == o.customer_id &&
      line_items == o.line_items &&
      taxes == o.taxes &&
      discounts == o.discounts &&
      service_charges == o.service_charges &&
      fulfillments == o.fulfillments &&
      returns == o.returns &&
      return_amounts == o.return_amounts &&
      net_amounts == o.net_amounts &&
      rounding_adjustment == o.rounding_adjustment &&
      tenders == o.tenders &&
      refunds == o.refunds &&
      created_at == o.created_at &&
      updated_at == o.updated_at &&
      closed_at == o.closed_at &&
      state == o.state &&
      total_money == o.total_money &&
      total_tax_money == o.total_tax_money &&
      total_discount_money == o.total_discount_money &&
      total_service_charge_money == o.total_service_charge_money
end
_deserialize(type, value) click to toggle source

Deserializes the data based on type @param string type Data type @param string value Value to be deserialized @return [Object] Deserialized data

# File lib/square_connect/models/order.rb, line 390
def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BOOLEAN
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    temp_model = SquareConnect.const_get(type).new
    temp_model.build_from_hash(value)
  end
end
_to_hash(value) click to toggle source

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value @param [Object] value Any valid value @return [Hash] Returns the value in the form of hash

# File lib/square_connect/models/order.rb, line 456
def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map{ |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end
build_from_hash(attributes) click to toggle source

Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself

# File lib/square_connect/models/order.rb, line 369
def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.swagger_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end
eql?(o) click to toggle source

@see the `==` method @param [Object] Object to be compared

# File lib/square_connect/models/order.rb, line 356
def eql?(o)
  self == o
end
hash() click to toggle source

Calculates hash code according to all attributes. @return [Fixnum] Hash code

# File lib/square_connect/models/order.rb, line 362
def hash
  [id, location_id, reference_id, source, customer_id, line_items, taxes, discounts, service_charges, fulfillments, returns, return_amounts, net_amounts, rounding_adjustment, tenders, refunds, created_at, updated_at, closed_at, state, total_money, total_tax_money, total_discount_money, total_service_charge_money].hash
end
list_invalid_properties() click to toggle source

Show invalid properties with the reasons. Usually used together with valid? @return Array for valid properies with the reasons

# File lib/square_connect/models/order.rb, line 272
def list_invalid_properties
  invalid_properties = Array.new
  if @location_id.nil?
    invalid_properties.push("invalid value for 'location_id', location_id cannot be nil.")
  end

  if @location_id.to_s.length < 1
    invalid_properties.push("invalid value for 'location_id', the character length must be great than or equal to 1.")
  end

  if !@reference_id.nil? && @reference_id.to_s.length > 40
    invalid_properties.push("invalid value for 'reference_id', the character length must be smaller than or equal to 40.")
  end

  return invalid_properties
end
location_id=(location_id) click to toggle source

Custom attribute writer method with validation @param [Object] location_id Value to be assigned

# File lib/square_connect/models/order.rb, line 300
def location_id=(location_id)
  if location_id.nil?
    fail ArgumentError, "location_id cannot be nil"
  end

  if location_id.to_s.length < 1
    fail ArgumentError, "invalid value for 'location_id', the character length must be great than or equal to 1."
  end

  @location_id = location_id
end
reference_id=(reference_id) click to toggle source

Custom attribute writer method with validation @param [Object] reference_id Value to be assigned

# File lib/square_connect/models/order.rb, line 314
def reference_id=(reference_id)

  if !reference_id.nil? && reference_id.to_s.length > 40
    fail ArgumentError, "invalid value for 'reference_id', the character length must be smaller than or equal to 40."
  end

  @reference_id = reference_id
end
to_body() click to toggle source

to_body is an alias to to_hash (backward compatibility) @return [Hash] Returns the object in the form of hash

# File lib/square_connect/models/order.rb, line 436
def to_body
  to_hash
end
to_hash() click to toggle source

Returns the object in the form of hash @return [Hash] Returns the object in the form of hash

# File lib/square_connect/models/order.rb, line 442
def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    hash[param] = _to_hash(value)
  end
  hash
end
to_s() click to toggle source

Returns the string representation of the object @return [String] String presentation of the object

# File lib/square_connect/models/order.rb, line 430
def to_s
  to_hash.to_s
end
valid?() click to toggle source

Check to see if the all the properties in the model are valid @return true if the model is valid

# File lib/square_connect/models/order.rb, line 291
def valid?
  return false if @location_id.nil?
  return false if @location_id.to_s.length < 1
  return false if !@reference_id.nil? && @reference_id.to_s.length > 40
  return true
end