Problems: Second function "verify_webhook_2" always returns false. Code in if statement runs whether tests return true or not.
I copied and pasted the first function, then made (what I would think to be) appropriate changes, so I can verify webhooks coming from two different Shopify stores. I'm sure it's something simple that I am just oblivious to, as I'm still fairly new to all of this. If I change $verify
to the secret for $verify2
then webhooks received from that shop will verify true.
And I cannot for the life of me understand why the code in the if statement runs even when both requirements test false. There's no way I can think of that either could prove true when the receiving a webhook from the shop related to the $verify2
secret. Probably a rookie mistake?
$verify = "xxxxsecretxxxx";
$verify2 = "xxxxsecretxxxx";
define('SHOPIFY_APP_SECRET', $verify);
define('SHOPIFY_APP_SECRET_2', $verify2);
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return hash_equals($hmac_header, $calculated_hmac);
}
function verify_webhook_2($data, $hmac_header)
{
$calculated_hmac_2 = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET_2, true));
return hash_equals($hmac_header, $calculated_hmac_2);
}
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);
$verified_2 = verify_webhook_2($data, $hmac_header);
error_log('Webhook verified: '.var_export($verified, true)); //check error.log to see the result
if ($verified == true || $verified_2 == true){
header("HTTP/1.1 200 OK"); //respond with success
http_response_code(201); //respond with success
file_put_contents('/var/www/html/temp/webhook.json', $data);
$POST = json_decode(file_get_contents('/var/www/html/temp/webhook.json'), true);
//$POST = $POST['id'];
$report = "id: " . $POST['id'] . " - email: " . $POST['email'] . " - name: " . $POST['customer']['first_name'] . " " . $POST['customer']['last_name'] ;
}else{
}
Aucun commentaire:
Enregistrer un commentaire