Module: Adyen::REST::Signature

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

Overview

The Signature module can sign and verify HMAC SHA-256 signatures for API

Instance Method Summary collapse

Instance Method Details

#sign(params) ⇒ String

Sign the parameters with the given shared secret

Parameters:

  • params (Hash)

    The set of parameters to sign. Should sent ‘sharedSecret` to sign.

Returns:

  • (String)

    signature from parameters



12
13
14
# File 'lib/adyen/rest/signature.rb', line 12

def sign(params)
  Adyen::Signature.sign(params, :rest)
end

#verify(params) ⇒ Boolean

Verify the parameters with the given shared secret Should include ‘sharedSecret` param to sign and the `hmacSignature` param to compare with the signature calculated

Parameters:

  • params (Hash)

    The set of parameters to verify.

Returns:

  • (Boolean)

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

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/adyen/rest/signature.rb', line 20

def verify(params)
  their_sig = params.delete('hmacSignature')
  raise ArgumentError, "params must include 'hmacSignature' for verification" if their_sig.empty?
  Adyen::Signature.verify(params, their_sig, :rest)
end