Validating Woocommerce webhook using HMAC in PHP

Rate this post

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.

READ :  Laravel 6 Dynamic get and set config variables value

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

READ :  Vuejs Game Programming - fastest click GAME

$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]
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

READ :  ASP.NET UpdateProgress control Tutorial with Examples

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 Reply

Your email address will not be published.