Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Cannot verify webhook for php 5.4

Cannot verify webhook for php 5.4

salmanhaidar
Visitor
1 0 0

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);
}

}
Replies 0 (0)