Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Hi, I have created a Webhook For Order Create to get Data on my server. Webhook request going to my local server. But webhook verification faild. i am using this code to verify webhook But its goes to else part.
public function webhookCreateOrder(Request $request){
//define('SHOPIFY_APP_SECRET', 'my_shared_secret');
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
//$verified = $this->verify_webhook($data, $hmac_header);
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, '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', true));
$verified = hash_equals($hmac_header, $calculated_hmac);
//error_log('Webhook verified: '.var_export($verified, true)); # Check error.log to see the result
if ($verified) {
$jsonData = json_encode($data);
DB::table('test007')->insert([
'detail' => 'verified'
]);
http_response_code(200);
} else {
DB::table('test007')->insert([
'detail' => $hmac_header. ' verification equall to '. $calculated_hmac,
]);
http_response_code(401);
}
}