From 392c3d77f2acda3f1421c97241bf392491dc9976 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Wed, 26 Feb 2025 17:02:25 +0100 Subject: [PATCH] fix: remove toggle optin in customer activation --- composer.json | 2 +- src/WordPress/WPCrm.php | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 10d60c2..665e22d 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V4", "license": "MIT", - "version": "4.0.8", + "version": "4.0.9", "authors": [ { "name": "Jérémy Munsch", diff --git a/src/WordPress/WPCrm.php b/src/WordPress/WPCrm.php index c688767..90e1fe6 100644 --- a/src/WordPress/WPCrm.php +++ b/src/WordPress/WPCrm.php @@ -302,8 +302,7 @@ class WPCrm } /** - * Toggle the current user optin value - * on the current user and the crm + * Activate the current user * * @return boolean True if the operation succeeded. * @throws \LDC\LDCCRM\Exceptions\ValidationException If a customer's hashcode could not be validated. @@ -320,10 +319,19 @@ class WPCrm if ($customer->status) { return true; } - if (!self::makeApiV4Call($customer, 'activate')) { - return false; + try { + if (!self::makeApiV4Call($customer, 'activate')) { + return false; + } + } catch (ApiErrorException $e) { + switch ($e->getApiError()) { + case ApiError::authorizationException->value(): + case ApiError::modelNotFound->value(): + return false; + default: + throw $e; + } } - $customer->opt_in = !$customer->opt_in; return true; }