class Qiwi::Transaction

Attributes

finder[RW]

Finder should respond_to?(:find_by_txn) and return an object, which can respond_to?(:amount)

txn[R]

Public Class Methods

new(txn) { |self| ... } click to toggle source
# File lib/qiwi/transaction.rb, line 32
def initialize(txn)
  @txn = txn

  # A logging observer
  add_observer(self, :log_transaction)

  if block_given?
    yield self
  else
    Qiwi.config.transaction_handler.call(self) if Qiwi.config.transaction_handler
  end
end

Public Instance Methods

amount() click to toggle source
# File lib/qiwi/transaction.rb, line 64
def amount
  persisted.amount if exists?
end
commit!() click to toggle source
# File lib/qiwi/transaction.rb, line 50
def commit!
  changed
  notify_observers(self)
end
exists?() click to toggle source
# File lib/qiwi/transaction.rb, line 55
def exists?
  !!persisted
end
find(txn) click to toggle source
# File lib/qiwi/transaction.rb, line 80
def find(txn)
  finder.find_by_txn(txn) if finder
end
inspect() click to toggle source
# File lib/qiwi/transaction.rb, line 45
def inspect
  error_msgs = errors.full_messages.join(', ')
  %{<Qiwi::Transaction id: #{txn}, remote: #{remote.inspect} persisted: #{persisted.inspect} errors: #{error_msgs}}
end
log_transaction(transaction) click to toggle source
# File lib/qiwi/transaction.rb, line 68
def log_transaction(transaction)
  Qiwi.logger.info "Transaction update: #{transaction.inspect}"
end
persisted() click to toggle source
# File lib/qiwi/transaction.rb, line 76
def persisted
  @persisted ||= find(txn)
end
remote() click to toggle source
# File lib/qiwi/transaction.rb, line 72
def remote
  @remote ||= Qiwi::Client.new.check_bill(txn: txn)
end
valid_amount?() click to toggle source
# File lib/qiwi/transaction.rb, line 59
def valid_amount?
  valid?
  errors[:amount].empty?
end