Class: Newebpay::QueryTrade::Response
- Inherits:
-
Object
- Object
- Newebpay::QueryTrade::Response
- Defined in:
- lib/newebpay/query_trade/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.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/newebpay/query_trade/response.rb', line 6 def initialize(response_params) response_data = JSON.parse(response_params) @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/query_trade/response.rb', line 5 def @message end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/newebpay/query_trade/response.rb', line 5 def status @status end |
Instance Method Details
#check_data_raw ⇒ Object
31 32 33 |
# File 'lib/newebpay/query_trade/response.rb', line 31 def check_data_raw @check_data_raw ||= URI.encode_www_form(@result.slice('Amt', 'MerchantID', 'MerchantOrderNo', 'TradeNo').sort) end |
#expected_check_code ⇒ Object
27 28 29 |
# File 'lib/newebpay/query_trade/response.rb', line 27 def expected_check_code Newebpay::NewebpayHelper.create_check_code(check_data_raw) end |
#success? ⇒ Boolean
19 20 21 |
# File 'lib/newebpay/query_trade/response.rb', line 19 def success? status == 'SUCCESS' end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/newebpay/query_trade/response.rb', line 23 def valid? check_code == expected_check_code end |