DEV Community

Slothy
Slothy

Posted on

Authorize.net - Validate Webhook Signature

Couldn't find any complete examples on how to do this, so here is one:

define('AUTHORIZE_SIGNATURE_KEY', 'abc123');

$body = file_get_contents('php://input');

$headers = getallheaders();

$header = $headers['X-ANET-Signature'];

parse_str($header, $output);

// need to match case since PHP will generate the hash as lowercase
$signature = strtolower($output['sha512']);

$hash = hash_hmac('sha512', $body, AUTHORIZE_SIGNATURE_KEY);

if($hash === $signature) {
    echo "signature matches";
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)