class JuspayCheckout::Signature
Public Class Methods
is_valid?(params, signature)
click to toggle source
DOC - www.juspay.in/docs/advanced/ec/response/index.html After the redirect, the authenticity should be verified using the signature in the response. The signature parameter in the return_url gives the HMAC signature computed using the algorithm specified by the signature_algorithm parameter.
# File lib/juspay_checkout/signature.rb, line 7 def is_valid?(params, signature) if params.present? $juspay_config or JuspayCheckout::ExpressCheckout.credential_config parameter = params.except("signature", "signature_algorithm", "format", "controller", "action") encoded_list = [] parameter.keys.sort.each { |k| encoded_list << URI.encode(k) + "=" + URI.encode(params[k]) } data = CGI.escape(encoded_list.join("&")) hash_string = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), $juspay_config['response_key'], data)).strip() return signature == hash_string end false end