Class: S6kPay::Client
- Inherits:
-
Object
- Object
- S6kPay::Client
- Defined in:
- lib/s6kpay.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.
19 20 21 22 |
# File 'lib/s6kpay.rb', line 19 def initialize() [:webhost] = [:test] ? $Constants[:WEB_TEST] : $Constants[:WEB] @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/s6kpay.rb', line 17 def @options end |
Instance Method Details
#get_order_redirect_url(order) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/s6kpay.rb', line 24 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
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/s6kpay.rb', line 37 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 |