Class: ChargeBase
- Defined in:
- lib/rave_ruby/rave_objects/base/charge_base.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#get_auth_type(suggested_auth) ⇒ Object
method to the passed suggested auth to the corresponding value in the available hash.
-
#handle_charge_response(response) ⇒ Object
method to charge response.
-
#handle_validate_account_response(response) ⇒ Object
method to handle validate account response.
-
#handle_validate_response(response) ⇒ Object
method to handle validate card response.
-
#handle_verify_account_response(response) ⇒ Object
method to handle account verify response.
-
#handle_verify_response(response) ⇒ Object
method to handle card verify response.
-
#update_payload(suggested_auth, payload, **keyword_args) ⇒ Object
method to update payload.
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
#get_auth_type(suggested_auth) ⇒ Object
method to the passed suggested auth to the corresponding value in the available hash
6 7 8 9 10 11 12 13 14 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 6 def get_auth_type(suggested_auth) auth_map = {"PIN" => :pin, "AVS_VBVSECURECODE" => :address, "NOAUTH_INTERNATIONAL" => :address, "AVS_NOAUTH" => :address} # Raise Error if the right authorization type is not passed unless !auth_map.has_key? auth_map[suggested_auth] raise RequiredAuthError, "Required suggested authorization type not available." end return auth_map[suggested_auth] end |
#handle_charge_response(response) ⇒ Object
method to charge response
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 40 def handle_charge_response (response) charge_response = response # print charge_response flwRef = charge_response["data"]["flwRef"] txRef = charge_response["data"]["txRef"] # status = charge_response["data"]["status"] = charge_response["message"] status = charge_response["status"] suggested_auth = charge_response["data"]["suggested_auth"] amount = charge_response["data"]["amount"] currency = charge_response["data"]["currency"] auth_model_used = charge_response["data"]["authModelUsed"] validate_instruction = charge_response["data"]["validateInstruction"] payment_type = charge_response["data"]["paymentType"] charge_response_code = charge_response["data"]["chargeResponseCode"] = charge_response["data"]["chargeResponseMessage"] if charge_response["data"]["authurl"] == "N/A" authurl = "N/A" else authurl = charge_response["data"]["authurl"] end if charge_response_code == "00" res = {"error": false, "status": status, "validation_required": false, "message": , "suggested_auth": suggested_auth, "txRef": txRef, "flwRef": flwRef, "chargeResponseCode": charge_response_code, "chargeResponseMessage": , "amount": amount, "currency": currency, "validateInstruction": validate_instruction, "paymentType": payment_type, "authModelUsed": auth_model_used, "authurl": authurl} return JSON.parse(res.to_json) else res = {"error": false, "status": status, "validation_required": true, "message": , "suggested_auth": suggested_auth, "txRef": txRef, "flwRef": flwRef, "chargeResponseCode": charge_response_code, "chargeResponseMessage": , "amount": amount, "currency": currency, "validateInstruction": validate_instruction, "paymentType": payment_type, "authModelUsed": auth_model_used, "authurl": authurl} return JSON.parse(res.to_json) # else # # return charge_response # res = {"status": charge_response["status"], "message": charge_response["message"], "data": charge_response["data"]} # return JSON.parse(res.to_json) end end |
#handle_validate_account_response(response) ⇒ Object
method to handle validate account response
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 103 def handle_validate_account_response(response) validate_response = response flwRef = validate_response["data"]["flwRef"] txRef = validate_response["data"]["txRef"] status = validate_response["status"] = validate_response["message"] amount = validate_response["data"]["amount"] currency = validate_response["data"]["currency"] charge_response_code = validate_response["data"]["chargeResponseCode"] = validate_response["data"]["chargeResponseMessage"] if charge_response_code == "00" res = {"error": false, "status": status, "message": , "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "chargeResponseCode": charge_response_code, "chargeResponseMessage": } return JSON.parse(res.to_json) else res = {"error": true, "status": status, "message": , "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "chargeResponseCode": charge_response_code, "chargeResponseMessage": } return JSON.parse(res.to_json) end end |
#handle_validate_response(response) ⇒ Object
method to handle validate card response
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 80 def handle_validate_response(response) validate_response = response flwRef = validate_response["data"]["tx"]["flwRef"] txRef = validate_response["data"]["tx"]["txRef"] status = validate_response["status"] = validate_response["message"] amount = validate_response["data"]["tx"]["amount"] currency = validate_response["data"]["tx"]["currency"] charge_response_code = validate_response["data"]["tx"]["chargeResponseCode"] = validate_response["data"]["tx"]["chargeResponseMessage"] if charge_response_code == "00" res = {"error": false, "status": status, "message": , "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "chargeResponseCode": charge_response_code, "chargeResponseMessage": } return JSON.parse(res.to_json) else res = {"error": true, "status": status, "message": , "txRef": txRef, "flwRef": flwRef, "amount": amount, "currency": currency, "chargeResponseCode": charge_response_code, "chargeResponseMessage": } return JSON.parse(res.to_json) end end |
#handle_verify_account_response(response) ⇒ Object
method to handle account verify response
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 141 def handle_verify_account_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": true, "transaction_complete": false, "data": verify_response["data"]} return JSON.parse(res.to_json) end end |
#handle_verify_response(response) ⇒ Object
method to handle card verify response
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 125 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": true, "transaction_complete": false, "data": verify_response["data"]} return JSON.parse(res.to_json) end end |
#update_payload(suggested_auth, payload, **keyword_args) ⇒ Object
method to update payload
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rave_ruby/rave_objects/base/charge_base.rb', line 18 def update_payload(suggested_auth, payload, **keyword_args) auth_type = get_auth_type(suggested_auth) # Error is raised if the expected suggested auth is not found in the keyword arguments if !keyword_args.key?(auth_type) raise SuggestedAuthError, "Please pass the suggested auth." end # if the authorization type is equal to address symbol, update with the required parameters if auth_type == :address required_parameters = ["billingzip", "billingcity", "billingaddress", "billingstate", "billingcountry"] check_passed_parameters(required_parameters, keyword_args[auth_type]) payload.merge!({"suggested_auth" => suggested_auth}) return payload.merge!(keyword_args[auth_type]) end # return this updated payload if the passed authorization type isn't address symbol return payload.merge!({"suggested_auth" => suggested_auth, auth_type.to_s => keyword_args[auth_type]}) end |