Module: Adyen::HPP::Signature

Extended by:
Signature
Included in:
Signature
Defined in:
lib/adyen/hpp/signature.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#sign(params, shared_secret) ⇒ Hash

Sign the parameters with the given shared secret

Parameters:

  • params (Hash)

    The set of parameters to sign.

  • shared_secret (String)

    The shared secret for signing.

Returns:

  • (Hash)

    params The params that were passed in plus a new ‘merchantSig` param



13
14
15
16
17
18
# File 'lib/adyen/hpp/signature.rb', line 13

def sign(params, shared_secret)
  params = params.dup
  params.delete('merchantSig')
  params["sharedSecret"] ||= shared_secret
  params.merge('merchantSig' => Adyen::Signature.sign(params))
end

#verify(params, shared_secret) ⇒ Boolean

Verify the parameters with the given shared secret

Parameters:

  • params (Hash)

    The set of parameters to verify. Must include a ‘merchantSig` param that will be compared to the signature we calculate.

  • shared_secret (String)

    The shared secret for verification.

Returns:

  • (Boolean)

    true if the ‘merchantSig` in the params matches our calculated signature

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
# File 'lib/adyen/hpp/signature.rb', line 25

def verify(params, shared_secret)
  params = params.dup
  params["sharedSecret"] ||= shared_secret
  their_sig = params.delete('merchantSig')
  raise ArgumentError, "params must include 'merchantSig' for verification" if their_sig.empty?
  Adyen::Signature.verify(params, their_sig)
end