Class: Io::Flow::V0::Models::CreditPayment

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

Overview

A Credit Payment records a ‘non cash’ payment against an order (e.g. a store credit, gift card, etc.), recording the amount of that credit and additional details to reconcile payments. The primary purpose of the credit payment is to record that a payment has been made against an order so the remaining balance can be correctly computed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ CreditPayment

Returns a new instance of CreditPayment.



21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21265

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :order, :key, :description, :value, :original, :attributes], 'CreditPayment')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @order = (x = opts.delete(:order); x.is_a?(::Io::Flow::V0::Models::ExpandableOrder) ? x : ::Io::Flow::V0::Models::ExpandableOrder.from_json(x))
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
  @description = HttpClient::Preconditions.assert_class('description', opts.delete(:description), String)
  @value = (x = opts.delete(:value); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @original = (x = opts.delete(:original); x.is_a?(::Io::Flow::V0::Models::OriginalPrices) ? x : ::Io::Flow::V0::Models::OriginalPrices.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 }
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def attributes
  @attributes
end

#descriptionObject (readonly)

Returns the value of attribute description.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def key
  @key
end

#orderObject (readonly)

Returns the value of attribute order.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def order
  @order
end

#originalObject (readonly)

Returns the value of attribute original.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def original
  @original
end

#valueObject (readonly)

Returns the value of attribute value.



21263
21264
21265
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21263

def value
  @value
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



21281
21282
21283
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21281

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

#to_hashObject



21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21285

def to_hash
  {
    :id => id,
    :order => order.to_hash,
    :key => key,
    :description => description,
    :value => value.to_hash,
    :original => original.to_hash,
    :attributes => attributes
  }
end

#to_jsonObject



21277
21278
21279
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 21277

def to_json
  JSON.dump(to_hash)
end