I'm using GoCardless (sandbox account) webhook for a billing project. I want to recover the clients who choose to pay with GoCardless. The problem is that in the JSON that I get from GoCardless there is no such information.
I need the company name to put the mandate number into a sql database where all my clients are.
Is there a way to get the company name when a mandate is created ? Or to connect the mandate number to the company name ?
Here is my code :
<?php
putenv('GC_WEBHOOK_SECRET=my_secret...');
$token = getenv("GC_WEBHOOK_SECRET");
$raw_payload = file_get_contents('php://input');
$headers = getallheaders();
$provided_signature = $headers["Webhook-Signature"];
$calculated_signature = hash_hmac("sha256", $raw_payload, $token);
if ($provided_signature == $calculated_signature) {
$payload = json_decode($raw_payload, true);
foreach ($payload["events"] as $event) {
if ($event["resource_type"]=="mandates" && $event["action"]=="created"){
$mandates=$event["links"];
$mandate=$mandates["mandate"];
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('sqlsrv...', $pdo_options);
$reqi="INSERT INTO goCardLess (client) VALUES ('".$mandate."')";
$req = $bdd->query($reqi);
$req->closeCursor();
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
header("HTTP/1.1 200 OK");
}
}
}
else {
header("HTTP/1.1 498 Invalid Token test");
}
?>