Class: Newebpay::Donation::Response
- Inherits:
-
Object
- Object
- Newebpay::Donation::Response
- Defined in:
- lib/newebpay/donation/response.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #check_data_raw ⇒ Object
- #expected_check_code ⇒ Object
-
#initialize(response_params) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(response_params) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/newebpay/donation/response.rb', line 7 def initialize(response_params) @response_data = JSON.parse(response_params.to_json) @status = @response_data['Status'] @message = @response_data['Message'] @result = @response_data['Result'] @result.each do |key, values| define_singleton_method(key.underscore) do values end end end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/newebpay/donation/response.rb', line 5 def @message end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/newebpay/donation/response.rb', line 5 def status @status end |
Instance Method Details
#check_data_raw ⇒ Object
34 35 36 |
# File 'lib/newebpay/donation/response.rb', line 34 def check_data_raw @check_data_raw ||= URI.encode_www_form(@result.slice('Amt', 'MerchantID', 'MerchantOrderNo', 'TradeNo').sort) end |
#expected_check_code ⇒ Object
30 31 32 |
# File 'lib/newebpay/donation/response.rb', line 30 def expected_check_code Newebpay::NewebpayHelper.sha256_encode(Newebpay.config.hash_key, Newebpay.config.hash_iv, check_data_raw) end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/newebpay/donation/response.rb', line 22 def success? status == 'SUCCESS' end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/newebpay/donation/response.rb', line 26 def valid? check_code == expected_check_code end |