Class: JuspayCheckout::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/juspay_checkout/signature.rb

Class Method Summary collapse

Class Method Details

.is_valid?(params, signature) ⇒ Boolean

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.

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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