class SquareConnect::ChargeRequest

Defines the parameters that can be included in the body of a request to the Charge endpoint.

Attributes

additional_recipients[RW]

The basic primitive of multi-party transaction. The value is optional. The transaction facilitated by you can be split from here. If you provide this value, the `amount_money` value in your additional_recipients must not be more than 90% of the `amount_money` value in the charge request. The `location_id` must be the valid location of the app owner merchant. This field requires the `PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS` OAuth permission. This field is currently not supported in sandbox.

amount_money[RW]

The amount of money to charge. Note that you specify the amount in the __smallest denomination of the applicable currency__. For example, US dollar amounts are specified in cents. See [Working with monetary amounts](workingwithmonetaryamounts) for details. The value of `currency` must match the currency associated with the business that is charging the card.

billing_address[RW]

The buyer's billing address.

buyer_email_address[RW]

The buyer's email address, if available.

card_nonce[RW]

A nonce generated from the `SqPaymentForm` that represents the card to charge. The application that provides a nonce to this endpoint must be the _same application_ that generated the nonce with the `SqPaymentForm`. Otherwise, the nonce is invalid. Do not provide a value for this field if you provide a value for `customer_card_id`.

customer_card_id[RW]

The ID of the customer card on file to charge. Do not provide a value for this field if you provide a value for `card_nonce`. If you provide this value, you must also provide a value for `customer_id`.

customer_id[RW]

The ID of the customer to associate this transaction with. This field is required if you provide a value for `customer_card_id`, and optional otherwise.

delay_capture[RW]

If `true`, the request will only perform an Auth on the provided card. You can then later perform either a Capture (with the [CaptureTransaction](endpoint-capturetransaction) endpoint) or a Void (with the [VoidTransaction](endpoint-voidtransaction) endpoint). Default value: `false`

idempotency_key[RW]

A value you specify that uniquely identifies this transaction among transactions you've created. If you're unsure whether a particular transaction succeeded, you can reattempt it with the same idempotency key without worrying about double-charging the buyer. See [Idempotency](/basics/api101/idempotency) for more information.

note[RW]

An optional note to associate with the transaction. This value cannot exceed 60 characters.

order_id[RW]

The ID of the order to associate with this transaction. If you provide this value, the `amount_money` value of your request must __exactly match__ the value of the order's `total_money` field.

reference_id[RW]

An optional ID you can associate with the transaction for your own purposes (such as to associate the transaction with an entity ID in your own database). This value cannot exceed 40 characters.

shipping_address[RW]

The buyer's shipping address, if available.

verification_token[RW]

An identifying token generated by `SqPaymentForm.verifyBuyer()`. Verification tokens encapsulate customer device information and 3-D Secure challenge results to indicate that Square has verified the buyer identity.

Public Class Methods

attribute_map() click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 59
def self.attribute_map
  {
    :'idempotency_key' => :'idempotency_key',
    :'amount_money' => :'amount_money',
    :'card_nonce' => :'card_nonce',
    :'customer_card_id' => :'customer_card_id',
    :'delay_capture' => :'delay_capture',
    :'reference_id' => :'reference_id',
    :'note' => :'note',
    :'customer_id' => :'customer_id',
    :'billing_address' => :'billing_address',
    :'shipping_address' => :'shipping_address',
    :'buyer_email_address' => :'buyer_email_address',
    :'order_id' => :'order_id',
    :'additional_recipients' => :'additional_recipients',
    :'verification_token' => :'verification_token'
  }
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/charge_request.rb, line 100
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?(:'idempotency_key')
    self.idempotency_key = attributes[:'idempotency_key']
  end

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

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

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

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

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

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

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

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

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

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

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

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

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

end
swagger_types() click to toggle source

Attribute type mapping.

# File lib/square_connect/models/charge_request.rb, line 79
def self.swagger_types
  {
    :'idempotency_key' => :'String',
    :'amount_money' => :'Money',
    :'card_nonce' => :'String',
    :'customer_card_id' => :'String',
    :'delay_capture' => :'BOOLEAN',
    :'reference_id' => :'String',
    :'note' => :'String',
    :'customer_id' => :'String',
    :'billing_address' => :'Address',
    :'shipping_address' => :'Address',
    :'buyer_email_address' => :'String',
    :'order_id' => :'String',
    :'additional_recipients' => :'Array<AdditionalRecipient>',
    :'verification_token' => :'String'
  }
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/charge_request.rb, line 315
def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      idempotency_key == o.idempotency_key &&
      amount_money == o.amount_money &&
      card_nonce == o.card_nonce &&
      customer_card_id == o.customer_card_id &&
      delay_capture == o.delay_capture &&
      reference_id == o.reference_id &&
      note == o.note &&
      customer_id == o.customer_id &&
      billing_address == o.billing_address &&
      shipping_address == o.shipping_address &&
      buyer_email_address == o.buyer_email_address &&
      order_id == o.order_id &&
      additional_recipients == o.additional_recipients &&
      verification_token == o.verification_token
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/charge_request.rb, line 370
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/charge_request.rb, line 436
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/charge_request.rb, line 349
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
card_nonce=(card_nonce) click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 249
def card_nonce=(card_nonce)

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

  @card_nonce = card_nonce
end
customer_card_id=(customer_card_id) click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 260
def customer_card_id=(customer_card_id)

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

  @customer_card_id = customer_card_id
end
customer_id=(customer_id) click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 293
def customer_id=(customer_id)

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

  @customer_id = customer_id
end
eql?(o) click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 336
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/charge_request.rb, line 342
def hash
  [idempotency_key, amount_money, card_nonce, customer_card_id, delay_capture, reference_id, note, customer_id, billing_address, shipping_address, buyer_email_address, order_id, additional_recipients, verification_token].hash
end
idempotency_key=(idempotency_key) click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 231
def idempotency_key=(idempotency_key)
  if idempotency_key.nil?
    fail ArgumentError, "idempotency_key cannot be nil"
  end

  if idempotency_key.to_s.length > 192
    fail ArgumentError, "invalid value for 'idempotency_key', the character length must be smaller than or equal to 192."
  end

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

  @idempotency_key = idempotency_key
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/charge_request.rb, line 168
def list_invalid_properties
  invalid_properties = Array.new
  if @idempotency_key.nil?
    invalid_properties.push("invalid value for 'idempotency_key', idempotency_key cannot be nil.")
  end

  if @idempotency_key.to_s.length > 192
    invalid_properties.push("invalid value for 'idempotency_key', the character length must be smaller than or equal to 192.")
  end

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

  if @amount_money.nil?
    invalid_properties.push("invalid value for 'amount_money', amount_money cannot be nil.")
  end

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

  if !@customer_card_id.nil? && @customer_card_id.to_s.length > 192
    invalid_properties.push("invalid value for 'customer_card_id', the character length must be smaller than or equal to 192.")
  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

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

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

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

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

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

# File lib/square_connect/models/charge_request.rb, line 282
def note=(note)

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

  @note = note
end
order_id=(order_id) click to toggle source

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

# File lib/square_connect/models/charge_request.rb, line 304
def order_id=(order_id)

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

  @order_id = order_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/charge_request.rb, line 271
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/charge_request.rb, line 416
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/charge_request.rb, line 422
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/charge_request.rb, line 410
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/charge_request.rb, line 215
def valid?
  return false if @idempotency_key.nil?
  return false if @idempotency_key.to_s.length > 192
  return false if @idempotency_key.to_s.length < 1
  return false if @amount_money.nil?
  return false if !@card_nonce.nil? && @card_nonce.to_s.length > 192
  return false if !@customer_card_id.nil? && @customer_card_id.to_s.length > 192
  return false if !@reference_id.nil? && @reference_id.to_s.length > 40
  return false if !@note.nil? && @note.to_s.length > 60
  return false if !@customer_id.nil? && @customer_id.to_s.length > 50
  return false if !@order_id.nil? && @order_id.to_s.length > 192
  return true
end