Class: Qiwi::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/qiwi/handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(txn, status) ⇒ Handler

Returns a new instance of Handler.



10
11
12
13
# File 'lib/qiwi/handler.rb', line 10

def initialize(txn, status)
  @txn = Transaction.new(txn)
  @status = status
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/qiwi/handler.rb', line 9

def status
  @status
end

#txnObject (readonly)

Returns the value of attribute txn.



9
10
11
# File 'lib/qiwi/handler.rb', line 9

def txn
  @txn
end

Class Method Details

.call(txn, status) ⇒ Object



5
6
7
# File 'lib/qiwi/handler.rb', line 5

def self.call(txn, status)
  new(txn, status).handle
end

Instance Method Details

#check_transactionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/qiwi/handler.rb', line 19

def check_transaction
  unless txn.exists?
    logger.error "Transaction doesn't exist: #{txn.txn}"
    return 210
  end

  if status != txn.remote_status
    logger.error "Stati don't match: #{txn.status} vs. #{status}"
    return 300
  end

  unless txn.valid_amount?
    logger.error "Incorrect amount: #{txn.amount}"
    return 241
  end

  if txn.valid?
    return  0
  else
    logger.error "Unknown error: #{txn.inspect}"
    return 300
  end

ensure
  txn.commit!
end

#handleObject



15
16
17
# File 'lib/qiwi/handler.rb', line 15

def handle
  check_transaction
end

#loggerObject



46
47
48
# File 'lib/qiwi/handler.rb', line 46

def logger
  Qiwi.logger
end