Module: Bygpay::Utils

Extended by:
Utils
Included in:
Deposits, Utils, Withdrawals
Defined in:
lib/bygpay/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/bygpay/utils.rb', line 7

def response
  @response
end

#response_textObject

Returns the value of attribute response_text.



7
8
9
# File 'lib/bygpay/utils.rb', line 7

def response_text
  @response_text
end

#resultObject

Returns the value of attribute result.



7
8
9
# File 'lib/bygpay/utils.rb', line 7

def result
  @result
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/bygpay/utils.rb', line 7

def status
  @status
end

#transaction_idObject

Returns the value of attribute transaction_id.



7
8
9
# File 'lib/bygpay/utils.rb', line 7

def transaction_id
  @transaction_id
end

#uuidObject

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_endpointObject

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_connectObject

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_endpointObject

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_endpointObject

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_endpointObject

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