From 4355cf50cf20f207ed331ef39cb697f782be7884 Mon Sep 17 00:00:00 2001 From: Sebastien Hattry Date: Thu, 8 Jul 2021 15:34:00 +0200 Subject: [PATCH] Add unsubscribe page --- unsubscribe.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/unsubscribe.php b/unsubscribe.php index 3dc1edc..30a6d05 100644 --- a/unsubscribe.php +++ b/unsubscribe.php @@ -1,23 +1,22 @@ load(); +require_once 'LDCCRM/ApiV1.php'; +require_once 'vendor/autoload.php'; +Dotenv\Dotenv::createImmutable(__DIR__)->load(); -// /* CRM */ -// define( 'CRM_TOKEN', getenv('CRM_API_TOKEN') ); -// define( 'CRM_ENDPOINT', getenv('CRM_ENDPOINT') ); +/* CRM */ +define( 'CRM_TOKEN', getenv('CRM_API_TOKEN') ); +define( 'CRM_ENDPOINT', getenv('CRM_ENDPOINT') ); if (!isset($_GET['hashcode']) || empty($_GET['hashcode'])) die('Missing fields.'); $hashcode = filter_var($_GET['hashcode'], FILTER_SANITIZE_STRING); -// $apiCrm = new \LDCCRM\ApiV1(CRM_ENDPOINT, CRM_TOKEN); +$apiCrm = new \LDCCRM\ApiV1(CRM_ENDPOINT, CRM_TOKEN); -$result = getApiCRM()->removeOptInCustomer($hashcode); -if ($result->status === "OK"){ - die('Vous avez été désabonné avec succès.'); -}else{ +$result = $apiCrm->removeOptInCustomer($hashcode); + +if ($result->status !== "OK"){ error_log("ERROR CRM API : $result->code - $result->message | hashcode : $hashcode"); die('Une erreur est survenue. Veuillez réessayer ultérieurement.'); }