Class: S6kPay::Client
- Inherits:
-
Object
- Object
- S6kPay::Client
- Defined in:
- lib/s6kpay/client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #get_order_redirect_url(order) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #verify_result(query) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
21 22 23 24 |
# File 'lib/s6kpay/client.rb', line 21 def initialize() [:webhost] = [:test] ? $Constants[:WEB_TEST] : $Constants[:WEB] @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/s6kpay/client.rb', line 19 def @options end |
Instance Method Details
#get_order_redirect_url(order) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/s6kpay/client.rb', line 26 def get_order_redirect_url(order) data = { merchantId: [:code], amount: order[:amount], merchantOrder: order[:orderId], } data[:merchantUser] = order[:userId] if order[:userId] sorted_params = data.sort.to_h query = sorted_params.map { |key, value| "#{key}=#{value}" }.join('&') signed_data = OpenSSL::HMAC.hexdigest("sha256", [:secret], query) return "#{@options[:test] ? $Constants[:WEB_TEST] : $Constants[:WEB]}?#{query}&secureHash=#{signed_data}&returnUrl=#{@options[:returnUrl]}" end |
#verify_result(query) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/s6kpay/client.rb', line 39 def verify_result(query) params = URI.decode_www_form(query).to_h return false unless params.key?("secureHash") secure_hash = params["secureHash"] params.delete("secureHash") sorted_params = params.sort.to_h query_str = sorted_params.map { |k, v| "#{k}=#{v}" }.join("&") signed_data = OpenSSL::HMAC.hexdigest("sha256", @options[:secret], query_str) secure_hash == signed_data end |