Module: Bygpay::Utils
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_text ⇒ Object
Returns the value of attribute response_text.
-
#result ⇒ Object
Returns the value of attribute result.
-
#status ⇒ Object
Returns the value of attribute status.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#deposit_status_endpoint ⇒ Object
Deposit transactions status check endpoint.
-
#get_status(endpoint, uuid) ⇒ Object
Get transaction status.
-
#http_connect ⇒ Object
global Bygpay connect.
-
#mobile_deposit_endpoint ⇒ Object
Mobile Deposit transactions endpoint.
-
#mobile_withdraw_endpoint ⇒ Object
Mobile Withdrawal transactions endpoint.
-
#parse_response(body) ⇒ Object
{ “status”: “success”, “message”: “Some messages”, “data”: { “uuid”: “d1f3395e-ea08-4599-b8a5-41f5e7a4”, “status”: “accepted”, “trnx_code”: “DTX00000008”, “provider_txid”: null, “extrnx_code”: null, “walletno”: “0276967627”, “amount”: 0.1, “provider”: “TIGO” } }.
-
#post(endpoint, payload = {}) ⇒ Object
Post payload.
-
#withdraw_status_endpoint ⇒ Object
Withdraw transactions status check endpoint.
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/bygpay/utils.rb', line 7 def response @response end |
#response_text ⇒ Object
Returns the value of attribute response_text.
7 8 9 |
# File 'lib/bygpay/utils.rb', line 7 def response_text @response_text end |
#result ⇒ Object
Returns the value of attribute result.
7 8 9 |
# File 'lib/bygpay/utils.rb', line 7 def result @result end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/bygpay/utils.rb', line 7 def status @status end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
7 8 9 |
# File 'lib/bygpay/utils.rb', line 7 def transaction_id @transaction_id end |
#uuid ⇒ Object
Returns the value of attribute uuid.
7 8 9 |
# File 'lib/bygpay/utils.rb', line 7 def uuid @uuid end |
Instance Method Details
#deposit_status_endpoint ⇒ Object
Deposit transactions status check endpoint
15 16 17 |
# File 'lib/bygpay/utils.rb', line 15 def deposit_status_endpoint Bygpay.configuration.deposit_status_path end |
#get_status(endpoint, uuid) ⇒ Object
Get transaction status
39 40 41 42 43 44 |
# File 'lib/bygpay/utils.rb', line 39 def get_status(endpoint, uuid) url = "#{Bygpay.configuration.base_url}#{endpoint}" result = http_connect.get("#{url}/#{uuid}") parse_response(result.body) end |
#http_connect ⇒ Object
global Bygpay connect
71 72 73 |
# File 'lib/bygpay/utils.rb', line 71 def http_connect HTTP[Authorization: Bygpay.configuration.api_key] end |
#mobile_deposit_endpoint ⇒ Object
Mobile Deposit transactions endpoint
10 11 12 |
# File 'lib/bygpay/utils.rb', line 10 def mobile_deposit_endpoint Bygpay.configuration.deposit_mobile_path end |
#mobile_withdraw_endpoint ⇒ Object
Mobile Withdrawal transactions endpoint
20 21 22 |
# File 'lib/bygpay/utils.rb', line 20 def mobile_withdraw_endpoint Bygpay.configuration.withdraw_mobile_path end |
#parse_response(body) ⇒ Object
{
"status": "success",
"message": "Some messages",
"data": {
"uuid": "d1f3395e-ea08-4599-b8a5-41f5e7a4",
"status": "accepted",
"trnx_code": "DTX00000008",
"provider_txid": null,
"extrnx_code": null,
"walletno": "0276967627",
"amount": 0.1,
"provider": "TIGO"
}
}
60 61 62 63 64 65 66 67 68 |
# File 'lib/bygpay/utils.rb', line 60 def parse_response(body) result = JSON.parse(body) @result = result @transaction_id = result['data']['trnx_code'] @response_text = result['message'] @uuid = result['data']['uuid'] @status = result['data']['status'] @response = result['status'] == 'success' end |
#post(endpoint, payload = {}) ⇒ Object
Post payload
30 31 32 33 34 35 36 |
# File 'lib/bygpay/utils.rb', line 30 def post(endpoint, payload = {}) url = "#{Bygpay.configuration.base_url}#{endpoint}" puts "URL: #{url}" result = http_connect.post(url, json: payload) parse_response(result.body) end |
#withdraw_status_endpoint ⇒ Object
Withdraw transactions status check endpoint
25 26 27 |
# File 'lib/bygpay/utils.rb', line 25 def withdraw_status_endpoint Bygpay.configuration.withdraw_status_path end |