module Adyen::HPP::Signature

The Signature module can sign and verify HMAC SHA-256 signatures for Hosted Payment Pages

Public Instance Methods

sign(params, shared_secret) click to toggle source

Sign the parameters with the given shared secret @param [Hash] params The set of parameters to sign. @param [String] shared_secret The shared secret for signing. @return [Hash] params The params that were passed in plus a new `merchantSig` param

   # File lib/adyen/hpp/signature.rb
13 def sign(params, shared_secret)
14   params = params.dup
15   params.delete('merchantSig')
16   params["sharedSecret"] ||= shared_secret
17   params.merge('merchantSig' => Adyen::Signature.sign(params))
18 end
verify(params, shared_secret) click to toggle source

Verify the parameters with the given shared secret @param [Hash] params The set of parameters to verify. Must include a `merchantSig`

param that will be compared to the signature we calculate.

@param [String] shared_secret The shared secret for verification. @return [Boolean] true if the `merchantSig` in the params matches our calculated signature

   # File lib/adyen/hpp/signature.rb
25 def verify(params, shared_secret)
26   params = params.dup
27   params["sharedSecret"] ||= shared_secret
28   their_sig = params.delete('merchantSig')
29   raise ArgumentError, "params must include 'merchantSig' for verification" if their_sig.empty?
30   Adyen::Signature.verify(params, their_sig)
31 end