I want to use square terminal to receive information from square API webhook and save it as a json file in a folder, but the Received Signature and Calculated Signature do not match. Whether I wrote it in perl or in php, the results did not match. The php code is below. I would be grateful if someone could help me.
<?php $secret = 'Webhook Signature key';$request_body = file_get_contents("php://input");
$received_signature = $_SERVER['HTTP_X_SQUARE_SIGNATURE'];
$signing_data = $request_body;
$calculated_signature = hash_hmac('sha256', $signing_data, $secret);
file_put_contents('/path/to/log.txt', "Received Signature: " . $received_signature . "\n", FILE_APPEND);
file_put_contents('/path/to/log.txt', "Calculated Signature: " . $calculated_signature . "\n", FILE_APPEND);
if ($received_signature === $calculated_signature) {
file_put_contents('/path/to/log.txt', "Signatures match!\n", FILE_APPEND);
} else {
file_put_contents('/path/to/log.txt', "Signatures do not match.\n", FILE_APPEND);
}
?>