Class: Kojn::Tx

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Model, ActiveModel::Validations, Model
Defined in:
lib/kojn/transaction.rb

Constant Summary collapse

UNCONFIRMED =
1
INSUFFICIENT =
2
SEEN =
3
CANCELLED =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Tx

Returns a new instance of Tx.



50
51
52
# File 'lib/kojn/transaction.rb', line 50

def initialize(attributes = {})
  self.attributes = attributes
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def address
  @address
end

#amountObject

Returns the value of attribute amount.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def amount
  @amount
end

#amount_in_fiatObject

Returns the value of attribute amount_in_fiat.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def amount_in_fiat
  @amount_in_fiat
end

#amount_leftObject

Returns the value of attribute amount_left.



60
61
62
# File 'lib/kojn/transaction.rb', line 60

def amount_left
  @amount_left
end

#confirmedObject

Returns the value of attribute confirmed.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def confirmed
  @confirmed
end

#currencyObject

Returns the value of attribute currency.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def description
  @description
end

#errorObject

Returns the value of attribute error.



61
62
63
# File 'lib/kojn/transaction.rb', line 61

def error
  @error
end

#errorsObject

Returns the value of attribute errors.



61
62
63
# File 'lib/kojn/transaction.rb', line 61

def errors
  @errors
end

#exchange_rateObject

Returns the value of attribute exchange_rate.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def exchange_rate
  @exchange_rate
end

#external_idObject

Returns the value of attribute external_id.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def external_id
  @external_id
end

#internal_idObject

Returns the value of attribute internal_id.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def internal_id
  @internal_id
end

#messageObject

Returns the value of attribute message.



61
62
63
# File 'lib/kojn/transaction.rb', line 61

def message
  @message
end

Returns the value of attribute paid.



60
61
62
# File 'lib/kojn/transaction.rb', line 60

def paid
  @paid
end

#received_amountObject

Returns the value of attribute received_amount.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def received_amount
  @received_amount
end

#received_amount_in_fiatObject

Returns the value of attribute received_amount_in_fiat.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def received_amount_in_fiat
  @received_amount_in_fiat
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



60
61
62
# File 'lib/kojn/transaction.rb', line 60

def redirect_uri
  @redirect_uri
end

#seenObject

Returns the value of attribute seen.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def seen
  @seen
end

#statusObject

Returns the value of attribute status.



59
60
61
# File 'lib/kojn/transaction.rb', line 59

def status
  @status
end

#time_leftObject

Returns the value of attribute time_left.



60
61
62
# File 'lib/kojn/transaction.rb', line 60

def time_left
  @time_left
end

Instance Method Details

#new_record?Boolean

Returns whether this ‘record’ is new. Inspired by rails :) TODO Make sure if a newly initialized object’s internal_id is actually set to nil.

Returns:

  • (Boolean)


75
76
77
# File 'lib/kojn/transaction.rb', line 75

def new_record?
  self.internal_id == nil
end

#saveObject



63
64
65
66
67
68
69
70
71
# File 'lib/kojn/transaction.rb', line 63

def save
  # Uses the transactions helper class to create and update
  # Copies the returned transactions' attributes over to its own.
  if self.new_record?
    self.attributes = Kojn.transactions.create(self.attributes).attributes
  else
    self.attributes = Kojn.transactions.update(self.internal_id, self.attributes).attributes
  end
end