Class: Io::Flow::V0::Models::DirectAuthorizationForm

Inherits:
AuthorizationForm show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

Creates an authorization for a transaction in which you remain the merchant of record. An authorization is used to check and reserve funds w/ a given payment method. No funds are actually transferred; once you have you an authorization, you can capture up to the amount of the authorization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AuthorizationForm

from_json, #to_hash

Constructor Details

#initialize(incoming = {}) ⇒ DirectAuthorizationForm

Returns a new instance of DirectAuthorizationForm.



8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8920

def initialize(incoming={})
  super(:name => AuthorizationForm::Types::DIRECT_AUTHORIZATION_FORM)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:token, :amount, :currency, :customer], 'DirectAuthorizationForm')
  @token = HttpClient::Preconditions.assert_class('token', opts.delete(:token), String)
  @amount = HttpClient::Preconditions.assert_class('amount', HttpClient::Helper.to_big_decimal(opts.delete(:amount)), BigDecimal)
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @customer = (x = opts.delete(:customer); x.is_a?(::Io::Flow::V0::Models::Customer) ? x : ::Io::Flow::V0::Models::Customer.new(x))
  @key = (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, String))
  @cvv = (x = opts.delete(:cvv); x.nil? ? nil : HttpClient::Preconditions.assert_class('cvv', x, String))
  @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', x, Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h })
  @destination = (x = opts.delete(:destination); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Address) ? x : ::Io::Flow::V0::Models::Address.new(x)))
  @ip = (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def amount
  @amount
end

#attributesObject (readonly)

Returns the value of attribute attributes.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def attributes
  @attributes
end

#currencyObject (readonly)

Returns the value of attribute currency.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def currency
  @currency
end

#customerObject (readonly)

Returns the value of attribute customer.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def customer
  @customer
end

#cvvObject (readonly)

Returns the value of attribute cvv.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def cvv
  @cvv
end

#destinationObject (readonly)

Returns the value of attribute destination.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def destination
  @destination
end

#ipObject (readonly)

Returns the value of attribute ip.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def ip
  @ip
end

#keyObject (readonly)

Returns the value of attribute key.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def key
  @key
end

#tokenObject (readonly)

Returns the value of attribute token.



8918
8919
8920
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8918

def token
  @token
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



8939
8940
8941
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8939

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

#subtype_to_hashObject



8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8943

def subtype_to_hash
  {
    :token => token,
    :amount => amount,
    :currency => currency,
    :customer => customer.to_hash,
    :key => key,
    :cvv => cvv,
    :attributes => attributes.nil? ? nil : attributes,
    :destination => destination.nil? ? nil : destination.to_hash,
    :ip => ip
  }
end

#to_jsonObject



8935
8936
8937
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 8935

def to_json
  JSON.dump(to_hash)
end