Today, We want to share with you Validating Woocommerce webhook using HMAC in PHP.In this post we will show you wordpress plugin require another plugin, hear for Woocommerce webhook not showing response we will give you demo and example for implement.In this post, we will learn about Send data from Woocommerce to Laravel via webhook with an example.
Validating Woocommerce webhook using HMAC in PHP
There are the Following The simple About Validating Woocommerce webhook using HMAC in PHP Full Information With Example and source code.
As I will cover this Post with live Working example to develop Verify Woocommerce web hook in PHP Laravel, so the How to Authenticate Webhook Requests is used for this example is following below.
setup Verify & Validating woocommerce webhooks
Get the HMAC value from request/header from the Woocommerce request, whatever the hmac value you want is called
Get the signature – your secret
Get the woocommerce URL, They should give you a code or some kind of ID and also a TIMESTAMP (this is important in your HMAC Calculation) in the request, You’d need to figure out this bit
Calculate the HMAC
encode the calculated HMAC
Check if the HMAC and Calculated HMAC Match, if they do continue
If they don’t stop processing
[php]
public function handle(Request $request, Closure $next)
{
$hmac = $request->get(‘hmac’);
$signature = Request::header(‘x-wc-webhook-signature’);
$woocommerceData = $request->get(‘woocomerceData’);
$get_hmac = hash_hmac(‘sha256’, $woocommerceData, $secret, true);
$get_hmac = base64_encode($get_hmac)
if ($hmac == $get_hmac) {
return $next($request);
}
else {
return false;
}
}
[/php]
Verify Woocommerce web hook in PHP Laravel
[php]
public function handle($request, Closure $next)
{
$wp_signature = Request::header(‘x-wc-webhook-signature’);
$payload = Request::getContent();
$get_hmac = base64_encode(hash_hmac(‘sha256’, $payload, env(‘WOOCOMMERCE_WEBHOOK_ITEM_UPDATED’), true));
if($wp_signature != $get_hmac) {
return false;
}
return $next($request);
}
[/php]
PHP – Verify Woocommerce web hook in Laravel
VerifyWoocommerce.php
[php]