=begin #Square Connect API OpenAPI spec version: 2.0 Contact: developers@squareup.com Generated by: https://github.com/swagger-api/swagger-codegen.git =end require 'date' module SquareConnect # Defines the parameters that can be included in the body of a request to the [Charge](#endpoint-charge) endpoint. class ChargeRequest # 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 keys](#idempotencykeys) for more information. attr_accessor :idempotency_key # 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. attr_accessor :amount_money # 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`. attr_accessor :card_nonce # 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`. attr_accessor :customer_card_id # 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` attr_accessor :delay_capture # 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. attr_accessor :reference_id # An optional note to associate with the transaction. This value cannot exceed 60 characters. attr_accessor :note # 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. attr_accessor :customer_id # The buyer's billing address. This value is optional, but this transaction is ineligible for chargeback protection if neither this parameter nor `shipping_address` is provided. attr_accessor :billing_address # The buyer's shipping address, if available. This value is optional, but this transaction is ineligible for chargeback protection if neither this parameter nor `billing_address` is provided. attr_accessor :shipping_address # The buyer's email address, if available. This value is optional, but this transaction is ineligible for chargeback protection if it is not provided. attr_accessor :buyer_email_address # Attribute mapping from ruby-style variable name to JSON key. 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' } end # Attribute type mapping. 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' } end # Initializes the object # @param [Hash] attributes Model attributes in the form of hash 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 end # Show invalid properties with the reasons. Usually used together with valid? # @return Array for valid properies with the reasons 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 return invalid_properties end # Check to see if the all the properties in the model are valid # @return true if the model is valid 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 true end # Custom attribute writer method with validation # @param [Object] idempotency_key Value to be assigned 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 # Custom attribute writer method with validation # @param [Object] card_nonce Value to be assigned 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 # Custom attribute writer method with validation # @param [Object] customer_card_id Value to be assigned 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 # Custom attribute writer method with validation # @param [Object] reference_id Value to be assigned 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 # Custom attribute writer method with validation # @param [Object] note Value to be assigned 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 # Custom attribute writer method with validation # @param [Object] customer_id Value to be assigned 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 # Checks equality by comparing each attribute. # @param [Object] Object to be compared 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 end # @see the `==` method # @param [Object] Object to be compared def eql?(o) self == o end # Calculates hash code according to all attributes. # @return [Fixnum] Hash code 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].hash end # Builds the object from hash # @param [Hash] attributes Model attributes in the form of hash # @return [Object] Returns the model itself 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 # Deserializes the data based on type # @param string type Data type # @param string value Value to be deserialized # @return [Object] Deserialized data 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<(?.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?.+?), (?.+)>\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 # Returns the string representation of the object # @return [String] String presentation of the object def to_s to_hash.to_s end # to_body is an alias to to_hash (backward compatibility) # @return [Hash] Returns the object in the form of hash def to_body to_hash end # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash 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 # 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 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 end end