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.



9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9742

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)))
  @order = (x = opts.delete(:order); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::AuthorizationOrderReference) ? x : ::Io::Flow::V0::Models::AuthorizationOrderReference.new(x)))
  @ip = (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', 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

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def amount
  @amount
end

#attributes ⇒ Object (readonly)

Returns the value of attribute attributes.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def attributes
  @attributes
end

#card ⇒ Object (readonly)

Returns the value of attribute card.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def card
  @card
end

#created_at ⇒ Object (readonly)

Returns the value of attribute created_at.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def created_at
  @created_at
end

#currency ⇒ Object (readonly)

Returns the value of attribute currency.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def currency
  @currency
end

#customer ⇒ Object (readonly)

Returns the value of attribute customer.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def customer
  @customer
end

#destination ⇒ Object (readonly)

Returns the value of attribute destination.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def destination
  @destination
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def id
  @id
end

#ip ⇒ Object (readonly)

Returns the value of attribute ip.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def ip
  @ip
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def key
  @key
end

#order ⇒ Object (readonly)

Returns the value of attribute order.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def order
  @order
end

#result ⇒ Object (readonly)

Returns the value of attribute result.



9740
9741
9742
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9740

def result
  @result
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



9763
9764
9765
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9763

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

#to_hash ⇒ Object



9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9767

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,
    :order => order.nil? ? nil : order.to_hash,
    :ip => ip,
    :result => result.to_hash,
    :created_at => created_at
  }
end

#to_json ⇒ Object



9759
9760
9761
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9759

def to_json
  JSON.dump(to_hash)
end