Class: Io::Flow::V0::Models::Refund

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

Overview

Refunds can be created against either a specific capture or an authorization (in which case we will select 1 or more specific captures against which to execute the refund).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Refund

Returns a new instance of Refund.



46237
46238
46239
46240
46241
46242
46243
46244
46245
46246
46247
46248
46249
46250
46251
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46237

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :key, :authorization, :amount, :currency, :captures, :created_at], 'Refund')
  @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))
  @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)
  @requested = (x = opts.delete(:requested); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x)))
  @captures = HttpClient::Preconditions.assert_class('captures', opts.delete(:captures), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::RefundCaptureSummary) ? x : ::Io::Flow::V0::Models::RefundCaptureSummary.new(x)) }
  @created_at = HttpClient::Preconditions.assert_class('created_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:created_at)), DateTime)
  @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 })
  @status = (x = (x = opts.delete(:status); x.nil? ? "succeeded" : x); x.is_a?(::Io::Flow::V0::Models::RefundStatus) ? x : ::Io::Flow::V0::Models::RefundStatus.apply(x))
  @base = (x = opts.delete(:base); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x)))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def amount
  @amount
end

#attributesObject (readonly)

Returns the value of attribute attributes.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def attributes
  @attributes
end

#authorizationObject (readonly)

Returns the value of attribute authorization.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def authorization
  @authorization
end

#baseObject (readonly)

Returns the value of attribute base.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def base
  @base
end

#capturesObject (readonly)

Returns the value of attribute captures.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def captures
  @captures
end

#created_atObject (readonly)

Returns the value of attribute created_at.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def created_at
  @created_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def currency
  @currency
end

#idObject (readonly)

Returns the value of attribute id.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def key
  @key
end

#requestedObject (readonly)

Returns the value of attribute requested.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def requested
  @requested
end

#statusObject (readonly)

Returns the value of attribute status.



46235
46236
46237
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46235

def status
  @status
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



46257
46258
46259
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46257

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

#to_hashObject



46261
46262
46263
46264
46265
46266
46267
46268
46269
46270
46271
46272
46273
46274
46275
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46261

def to_hash
  {
    :id => id,
    :key => key,
    :authorization => authorization.to_hash,
    :amount => amount.to_f.to_s,
    :currency => currency,
    :requested => requested.nil? ? nil : requested.to_hash,
    :captures => captures.map { |o| o.to_hash },
    :created_at => created_at,
    :attributes => attributes.nil? ? nil : attributes,
    :status => status.value,
    :base => base.nil? ? nil : base.to_hash
  }
end

#to_jsonObject



46253
46254
46255
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 46253

def to_json
  JSON.dump(to_hash)
end