Class: MpesaBase
- Defined in:
- lib/rave_ruby/rave_objects/base/mpesa_base.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#handle_charge_response(response) ⇒ Object
method to handle mpesa charge response.
-
#handle_verify_response(response) ⇒ Object
method to handle mpesa verify response.
Methods inherited from Base
#check_passed_parameters, #get_request, #handle_list_bank, #initialize, #post_request
Constructor Details
This class inherits a constructor from Base
Instance Method Details
#handle_charge_response(response) ⇒ Object
method to handle mpesa charge response
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rave_ruby/rave_objects/base/mpesa_base.rb', line 6 def handle_charge_response(response) charge_response = response flwRef = charge_response["data"]["flwRef"] txRef = charge_response["data"]["txRef"] status = charge_response["data"]["status"] amount = charge_response["data"]["amount"] currency = charge_response["data"]["currency"] payment_type = charge_response["data"]["paymentType"] if status == "pending" res = {"error": false, "status": status, "validation_required": true, "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "paymentType": payment_type} return JSON.parse(res.to_json) else res = {"error": false, "status": status, "validation_required": false, "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "paymentType": payment_type} return JSON.parse(res.to_json) end end |
#handle_verify_response(response) ⇒ Object
method to handle mpesa verify response
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rave_ruby/rave_objects/base/mpesa_base.rb', line 28 def handle_verify_response(response) verify_response = response status = verify_response["data"]["status"] charge_code = verify_response["data"]["chargecode"] if charge_code == "00" && status == "successful" res = {"error": false, "transaction_complete": true, "data": verify_response["data"]} return JSON.parse(res.to_json) else res = {"error": false, "transaction_complete": false, "data": verify_response["data"]} return JSON.parse(res.to_json) end end |