Class: Io::Flow::V0::Models::Reversal

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

Overview

A reversal is used to clear an authorization (full or partial).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Reversal

Returns a new instance of Reversal.



25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25687

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :key, :authorization, :status, :amount, :currency, :original, :created_at, :attributes], 'Reversal')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
  @authorization = (x = opts.delete(:authorization); x.is_a?(::Io::Flow::V0::Models::AuthorizationReference) ? x : ::Io::Flow::V0::Models::AuthorizationReference.new(x))
  @status = (x = opts.delete(:status); x.is_a?(::Io::Flow::V0::Models::ReversalStatus) ? x : ::Io::Flow::V0::Models::ReversalStatus.apply(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)
  @original = (x = opts.delete(:original); x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x))
  @created_at = HttpClient::Preconditions.assert_class('created_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:created_at)), DateTime)
  @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 }
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def amount
  @amount
end

#attributesObject (readonly)

Returns the value of attribute attributes.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def attributes
  @attributes
end

#authorizationObject (readonly)

Returns the value of attribute authorization.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def authorization
  @authorization
end

#created_atObject (readonly)

Returns the value of attribute created_at.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def created_at
  @created_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def currency
  @currency
end

#idObject (readonly)

Returns the value of attribute id.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def key
  @key
end

#originalObject (readonly)

Returns the value of attribute original.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def original
  @original
end

#statusObject (readonly)

Returns the value of attribute status.



25685
25686
25687
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25685

def status
  @status
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



25705
25706
25707
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25705

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

#to_hashObject



25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25709

def to_hash
  {
    :id => id,
    :key => key,
    :authorization => authorization.to_hash,
    :status => status.value,
    :amount => amount,
    :currency => currency,
    :original => original.to_hash,
    :created_at => created_at,
    :attributes => attributes
  }
end

#to_jsonObject



25701
25702
25703
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 25701

def to_json
  JSON.dump(to_hash)
end