Class: Bygpay::BygResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/bygpay/byg_response.rb

Constant Summary collapse

SUCCESS =
'success'
FAILED =
'fail'
PENDING =
%w(accepted pending)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject

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

#amountObject



52
53
54
# File 'lib/bygpay/byg_response.rb', line 52

def amount
  data.data.amount
end

#currencyObject



48
49
50
# File 'lib/bygpay/byg_response.rb', line 48

def currency
  data.data.currency
end

#failed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/bygpay/byg_response.rb', line 24

def failed?
  data.data.status == FAILED
end

#meta_dataObject



64
65
66
# File 'lib/bygpay/byg_response.rb', line 64

def 
  data.data.
end

#pending?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/bygpay/byg_response.rb', line 28

def pending?
  PENDING.include?(data.data.status)
end

#processor_transaction_idObject



40
41
42
# File 'lib/bygpay/byg_response.rb', line 40

def processor_transaction_id
  data.data.provider_txid
end

#providerObject



56
57
58
# File 'lib/bygpay/byg_response.rb', line 56

def provider
  data.data.provider
end


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

Returns:

  • (Boolean)


16
17
18
# File 'lib/bygpay/byg_response.rb', line 16

def request_successful?
  data.status == SUCCESS
end

#success?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/bygpay/byg_response.rb', line 20

def success?
  data.data.status == SUCCESS
end

#transaction_idObject



36
37
38
# File 'lib/bygpay/byg_response.rb', line 36

def transaction_id
  data.data.trnx_code
end

#transaction_statusObject



44
45
46
# File 'lib/bygpay/byg_response.rb', line 44

def transaction_status
  data.data.status
end

#uuidObject



32
33
34
# File 'lib/bygpay/byg_response.rb', line 32

def uuid
  data.data.uuid
end