Class: Io::Flow::V0::Models::Authorization

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

Overview

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

Constructor Details

#initialize(incoming = {}) ⇒ Authorization

Returns a new instance of Authorization.



7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7518

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :key, :card, :amount, :currency, :customer, :attributes, :result, :created_at], 'Authorization')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
  @card = (x = opts.delete(:card); x.is_a?(::Io::Flow::V0::Models::CardReference) ? x : ::Io::Flow::V0::Models::CardReference.new(x))
  @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))
  @attributes = HttpClient::Preconditions.assert_class('attributes', opts.delete(:attributes), 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))
  @cvv = (x = opts.delete(:cvv); x.nil? ? nil : HttpClient::Preconditions.assert_class('cvv', x, String))
  @result = (x = opts.delete(:result); x.is_a?(::Io::Flow::V0::Models::AuthorizationResult) ? x : ::Io::Flow::V0::Models::AuthorizationResult.new(x))
  @created_at = HttpClient::Preconditions.assert_class('created_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:created_at)), DateTime)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def amount
  @amount
end

#attributesObject (readonly)

Returns the value of attribute attributes.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def attributes
  @attributes
end

#cardObject (readonly)

Returns the value of attribute card.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def card
  @card
end

#created_atObject (readonly)

Returns the value of attribute created_at.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def created_at
  @created_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def currency
  @currency
end

#customerObject (readonly)

Returns the value of attribute customer.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def customer
  @customer
end

#cvvObject (readonly)

Returns the value of attribute cvv.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def cvv
  @cvv
end

#destinationObject (readonly)

Returns the value of attribute destination.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def destination
  @destination
end

#idObject (readonly)

Returns the value of attribute id.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def id
  @id
end

#ipObject (readonly)

Returns the value of attribute ip.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def ip
  @ip
end

#keyObject (readonly)

Returns the value of attribute key.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def key
  @key
end

#resultObject (readonly)

Returns the value of attribute result.



7516
7517
7518
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7516

def result
  @result
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



7539
7540
7541
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7539

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

#to_hashObject



7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7543

def to_hash
  {
    :id => id,
    :key => key,
    :card => card.to_hash,
    :amount => amount,
    :currency => currency,
    :customer => customer.to_hash,
    :attributes => attributes,
    :destination => destination.nil? ? nil : destination.to_hash,
    :ip => ip,
    :cvv => cvv,
    :result => result.to_hash,
    :created_at => created_at
  }
end

#to_jsonObject



7535
7536
7537
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 7535

def to_json
  JSON.dump(to_hash)
end