Class: Bygpay::BygResponse
- Inherits:
-
Object
- Object
- Bygpay::BygResponse
- Defined in:
- lib/bygpay/byg_response.rb
Constant Summary collapse
- SUCCESS =
'success'
- FAILED =
'fail'
- PENDING =
%w(accepted pending)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
-
.parse_response(json_payload) ⇒ Object
Hash strucuture { “status”: “success”, “message”: “Some messages”, “data”: { “uuid”: “d1f3395e-ea08-4599-b8a5-41f5e7a4”, “status”: “accepted”, “currency”: “GHS”, “trnx_code”: “DTX00000008”, “provider_txid”: null, “extrnx_code”: null, “walletno”: “0276967627”, “amount”: 0.1, “provider”: “TIGO”, “meta_data”: { “key”: “value” } } } This may throw JSON::ParserError if the json_payload is not valid JSON.
Instance Method Summary collapse
- #amount ⇒ Object
- #currency ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(hash = {}) ⇒ BygResponse
constructor
A new instance of BygResponse.
- #meta_data ⇒ Object
- #pending? ⇒ Boolean
- #processor_transaction_id ⇒ Object
- #provider ⇒ Object
- #redirect_link ⇒ Object
-
#request_successful? ⇒ Boolean
Check if Bygpay Gateway processed requests without any issues.
- #success? ⇒ Boolean
- #transaction_id ⇒ Object
- #transaction_status ⇒ Object
- #uuid ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ BygResponse
Returns a new instance of BygResponse.
11 12 13 |
# File 'lib/bygpay/byg_response.rb', line 11 def initialize(hash = {}) @data = Hashie::Mash.new(hash) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/bygpay/byg_response.rb', line 9 def data @data end |
Class Method Details
.parse_response(json_payload) ⇒ Object
Hash strucuture {
"status": "success",
"message": "Some messages",
"data": {
"uuid": "d1f3395e-ea08-4599-b8a5-41f5e7a4",
"status": "accepted",
"currency": "GHS",
"trnx_code": "DTX00000008",
"provider_txid": null,
"extrnx_code": null,
"walletno": "0276967627",
"amount": 0.1,
"provider": "TIGO",
"meta_data": { "key": "value" }
}
} This may throw JSON::ParserError if the json_payload is not valid JSON.
86 87 88 89 90 |
# File 'lib/bygpay/byg_response.rb', line 86 def self.parse_response(json_payload) data = JSON.parse(json_payload, symbolize_names: true) resp = BygResponse.new(data) resp end |
Instance Method Details
#amount ⇒ Object
52 53 54 |
# File 'lib/bygpay/byg_response.rb', line 52 def amount data.data.amount end |
#currency ⇒ Object
48 49 50 |
# File 'lib/bygpay/byg_response.rb', line 48 def currency data.data.currency end |
#failed? ⇒ Boolean
24 25 26 |
# File 'lib/bygpay/byg_response.rb', line 24 def failed? data.data.status == FAILED end |
#meta_data ⇒ Object
64 65 66 |
# File 'lib/bygpay/byg_response.rb', line 64 def data.data. end |
#pending? ⇒ Boolean
28 29 30 |
# File 'lib/bygpay/byg_response.rb', line 28 def pending? PENDING.include?(data.data.status) end |
#processor_transaction_id ⇒ Object
40 41 42 |
# File 'lib/bygpay/byg_response.rb', line 40 def processor_transaction_id data.data.provider_txid end |
#provider ⇒ Object
56 57 58 |
# File 'lib/bygpay/byg_response.rb', line 56 def provider data.data.provider end |
#redirect_link ⇒ Object
60 61 62 |
# File 'lib/bygpay/byg_response.rb', line 60 def redirect_link data.data.redirect_url end |
#request_successful? ⇒ Boolean
Check if Bygpay Gateway processed requests without any issues
16 17 18 |
# File 'lib/bygpay/byg_response.rb', line 16 def request_successful? data.status == SUCCESS end |
#success? ⇒ Boolean
20 21 22 |
# File 'lib/bygpay/byg_response.rb', line 20 def success? data.data.status == SUCCESS end |
#transaction_id ⇒ Object
36 37 38 |
# File 'lib/bygpay/byg_response.rb', line 36 def transaction_id data.data.trnx_code end |
#transaction_status ⇒ Object
44 45 46 |
# File 'lib/bygpay/byg_response.rb', line 44 def transaction_status data.data.status end |
#uuid ⇒ Object
32 33 34 |
# File 'lib/bygpay/byg_response.rb', line 32 def uuid data.data.uuid end |