Class: Io::Flow::V0::Models::Transaction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Transaction

Returns a new instance of Transaction.



66701
66702
66703
66704
66705
66706
66707
66708
66709
66710
66711
66712
66713
66714
66715
66716
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66701

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :shopify_transaction_id, :order, :currency, :source, :gross, :net, :created_at], 'Transaction')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @shopify_transaction_id = HttpClient::Preconditions.assert_class('shopify_transaction_id', opts.delete(:shopify_transaction_id), String)
  @order = (x = opts.delete(:order); x.is_a?(::Io::Flow::V0::Models::BillingChannelOrderReference) ? x : ::Io::Flow::V0::Models::BillingChannelOrderReference.new(x))
  @statement = (x = opts.delete(:statement); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::BillingChannelStatementReference) ? x : ::Io::Flow::V0::Models::BillingChannelStatementReference.new(x)))
  @payment_request = (x = opts.delete(:payment_request); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::BillingChannelPaymentRequestReference) ? x : ::Io::Flow::V0::Models::BillingChannelPaymentRequestReference.new(x)))
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @source = (x = opts.delete(:source); x.is_a?(::Io::Flow::V0::Models::TransactionSource) ? x : ::Io::Flow::V0::Models::TransactionSource.apply(x))
  @gross = HttpClient::Preconditions.assert_class('gross', HttpClient::Helper.to_big_decimal(opts.delete(:gross)), BigDecimal)
  @fees = HttpClient::Preconditions.assert_class('fees', (x = opts.delete(:fees); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::FeeDeduction) ? x : ::Io::Flow::V0::Models::FeeDeduction.new(x)) }
  @withholdings = HttpClient::Preconditions.assert_class('withholdings', (x = opts.delete(:withholdings); x.nil? ? [] : x), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::WithholdingDeduction) ? x : ::Io::Flow::V0::Models::WithholdingDeduction.new(x)) }
  @net = HttpClient::Preconditions.assert_class('net', HttpClient::Helper.to_big_decimal(opts.delete(:net)), BigDecimal)
  @created_at = HttpClient::Preconditions.assert_class('created_at', HttpClient::Helper.to_date_time_iso8601(opts.delete(:created_at)), DateTime)
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def created_at
  @created_at
end

#currencyObject (readonly)

Returns the value of attribute currency.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def currency
  @currency
end

#feesObject (readonly)

Returns the value of attribute fees.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def fees
  @fees
end

#grossObject (readonly)

Returns the value of attribute gross.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def gross
  @gross
end

#idObject (readonly)

Returns the value of attribute id.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def id
  @id
end

#netObject (readonly)

Returns the value of attribute net.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def net
  @net
end

#orderObject (readonly)

Returns the value of attribute order.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def order
  @order
end

#payment_requestObject (readonly)

Returns the value of attribute payment_request.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def payment_request
  @payment_request
end

#shopify_transaction_idObject (readonly)

Returns the value of attribute shopify_transaction_id.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def shopify_transaction_id
  @shopify_transaction_id
end

#sourceObject (readonly)

Returns the value of attribute source.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def source
  @source
end

#statementObject (readonly)

Returns the value of attribute statement.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def statement
  @statement
end

#withholdingsObject (readonly)

Returns the value of attribute withholdings.



66699
66700
66701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66699

def withholdings
  @withholdings
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



66722
66723
66724
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66722

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

#to_hashObject



66726
66727
66728
66729
66730
66731
66732
66733
66734
66735
66736
66737
66738
66739
66740
66741
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66726

def to_hash
  {
    :id => id,
    :shopify_transaction_id => shopify_transaction_id,
    :order => order.to_hash,
    :statement => statement.nil? ? nil : statement.to_hash,
    :payment_request => payment_request.nil? ? nil : payment_request.to_hash,
    :currency => currency,
    :source => source.value,
    :gross => gross.to_f.to_s,
    :fees => fees.map { |o| o.to_hash },
    :withholdings => withholdings.map { |o| o.to_hash },
    :net => net.to_f.to_s,
    :created_at => created_at
  }
end

#to_jsonObject



66718
66719
66720
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 66718

def to_json
  JSON.dump(to_hash)
end