I'm working with gocardless hooks , and i'm stuck on validating hmac signature with sandbox environment.
So I generated webhook test in sandbox and it gives to me the request body and headers as it has sent.
So as far as i understand , i must get the request body and generate a hash with secret key , and compare it with the webhook signature header hash ( not sounds really complicated ) .
So i'm using postman to reproduce it in my local environment, attaching the equal headers and the same body , but signature never match.
Here is what i tried :
$signature = hash_hmac('sha256',$request->getContent(), 'secret');
Notice i'm using laravel framework , so my first thinking was maybe the framework is manipulating internally the request , so i tried this :
$request_data = file_get_contents('php://input');
$signature = hash_hmac('sha256',$request_data, 'secret');
But still doesn't match , i noticed meany new lines and maybe this could modify the results so i cleaned it ...
$request_data = str_replace(array('.', ' ', "\n", "\t", "\r"), '', $request_data);
But still not match , and also i tried to cast body data in utf8 , and making hmac returning raw and encoding it in base64 ... but no success.
So what can be wrong here? Maybe signatures not working in sandbox environment? Has anyone dealed with it ?
Thank's in advance!