Class: Qiwi::Handler
- Inherits:
-
Object
- Object
- Qiwi::Handler
- Defined in:
- lib/qiwi/handler.rb
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#txn ⇒ Object
readonly
Returns the value of attribute txn.
Class Method Summary collapse
Instance Method Summary collapse
- #check_transaction ⇒ Object
- #handle ⇒ Object
-
#initialize(txn, status) ⇒ Handler
constructor
A new instance of Handler.
- #logger ⇒ Object
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
#status ⇒ Object (readonly)
Returns the value of attribute status.
9 10 11 |
# File 'lib/qiwi/handler.rb', line 9 def status @status end |
#txn ⇒ Object (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_transaction ⇒ Object
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 |
#handle ⇒ Object
15 16 17 |
# File 'lib/qiwi/handler.rb', line 15 def handle check_transaction end |