Today, We want to share with you WordPress Verify Woocommerce webhooks in PHP Laravel 6.In this post we will show you wordpress plugin require another plugin, hear for Receive WooCommerce webhoops in Laravel apps we will give you demo and example for implement.In this post, we will learn about How to Connect Your PHP Based Web App to the WooCommerce Rest API with an example.
WordPress Verify Woocommerce webhooks in PHP Laravel 6
There are the Following The simple About WooCommerce Webhooks verification in PHP Full Information With Example and source code.
As I will cover this Post with live Working example to develop WooCommerce Webhooks verification in Laravel application, so the Send data from Woocommerce to Laravel via webhook is used for this example is following below.
Example 1: laravel verify Woocommerce WordPress webhook
[php]
public function handle($request, Closure $next)
{
$signature = Request::header(‘x-wc-webhook-signature’);
//$payload = @file_get_contents(‘php://input’);
$payload = file_get_contents(‘php://input’);
//$payload = json_decode( $payload, true);
$calculated_hmac = base64_encode(hash_hmac(‘sha256’, $payload, $secret_key, true));
if($signature != $calculated_hmac) {
return false;
}
return $next($request);
}
[/php]
Example 2: Get data from Woocommerce to Laravel via webhook verify
[php]
$all_header =$request->headers->all();
dump($all_header);
$hmac_header = $request->header(‘x-wc-webhook-signature’);
dump($hmac_header);
$payload = file_get_contents(“php://input”);
dump($payload);
$website_domain = $request->header(‘x-wc-webhook-source’);
dump($website_domain);
$webs = Webs::where([‘website_domain’=>$website_domain])->first();
dump($webs);
if($webs){
$secret_key = $webs->secret_key;
dump($secret_key);
$calculated_hmac = base64_encode(hash_hmac(‘sha256’, $payload, $secret_key, true));
dump($hmac_header);
dump($calculated_hmac);
dump($hmac_header . “: ======= :” . $calculated_hmac);
if($hmac_header == $calculated_hmac){
dump(“laravel verify Woocommerce WordPress webhook”);
} else {
dump(“error For : laravel verify Woocommerce WordPress webhook”);
}
}
[/php]
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Validating Woocommerce webhook using HMAC in PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.