Validating Woocommerce webhook using HMAC in PHP

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.

READ :  Wordpress Verify Woocommerce webhooks in PHP Laravel 6

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

READ :  Laravel 6 FirstorCreate Increment and update column using Eloquent

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]

class VerifyWoocommerce { public function handle($request, Closure $next) { $wp_signature = Request::header('x-wc-webhook-signature'); $get_hmac = base64_encode(hash_hmac('sha256', $wp_signature, env('WOOCOMMERCE_WEBHOOK_ITEM_UPDATED'), true)); Log::debug($wp_signature); Log::debug($get_hmac); return $next($request); } } [/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.

Leave a Comment