diff --git a/CHANGELOG.md b/CHANGELOG.md index 24e2962..07645f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ### All notable changes to `CRM CLient V4` will be documented in this file. +# version 4.1.1 +- Changed: update optionnal answer id parameter when set new single optin for laravel and wordpress + +# version 4.1.0 +- Added: new api route for sending new claim +- Added: optionnal answer id parameter when set new single optin + # version 4.0.4 - chore: :arrow_up: bump to v4.0.4 diff --git a/composer.json b/composer.json index 72c27c5..467c305 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "description": "LDC CRM Client V4", "license": "MIT", - "version": "4.1.0", + "version": "4.1.1", "authors": [ { "name": "Jérémy Munsch", diff --git a/src/CrmApiV4.php b/src/CrmApiV4.php index 89b74f0..e8bf403 100644 --- a/src/CrmApiV4.php +++ b/src/CrmApiV4.php @@ -95,8 +95,9 @@ class CrmApiV4 /** * Set the single optin status for an email * - * @param string $email - * @param boolean $opt_in + * @param string $email + * @param boolean $opt_in + * @param array|null $answerId * @return boolean true if succeeded * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field email could not be validated. * @throws \LDC\LDCCRM\Exceptions\CrmException If an error occurs on server side or on getting response. @@ -104,9 +105,9 @@ class CrmApiV4 * Possibles are : - singleOptinCustomerExists, If a customer exists with this email. * @phpcs:ignore Squiz.Commenting.FunctionCommentThrowTag.WrongNumber */ - public static function setStatus(#[\SensitiveParameter] string $email, bool $opt_in): bool + public static function setStatus(#[\SensitiveParameter] string $email, bool $opt_in, ?array $answerId = null): bool { - return SingleOptin::setStatus($email, $opt_in); + return SingleOptin::setStatus($email, $opt_in, $answerId); } /** diff --git a/src/Models/SingleOptin.php b/src/Models/SingleOptin.php index cee2273..b284831 100644 --- a/src/Models/SingleOptin.php +++ b/src/Models/SingleOptin.php @@ -45,16 +45,13 @@ abstract class SingleOptin extends ClientModel static::setUpApiInterface(); $payload = [ - 'email' => $email, - 'opt_in' => $opt_in, + 'email' => $email, + 'opt_in' => $opt_in, + 'answer_id' => (!empty($answerId)) ? $answerId : null, ]; - if (!is_null($answerId) && count($answerId)) { - $payload['answer_id'] = $answerId; - } - $response = static::$apiInterface->call( - Utils::getResquest('apiV4.optin', [], $payload) + Utils::getResquest('apiV4.optin', [], array_filter($payload, fn($v) => !is_null($v))) ); return $response->status->equals(ApiStatus::OK); } diff --git a/src/WordPress/WPCrm.php b/src/WordPress/WPCrm.php index 90e1fe6..fa41bba 100644 --- a/src/WordPress/WPCrm.php +++ b/src/WordPress/WPCrm.php @@ -284,8 +284,9 @@ class WPCrm * Set the single optin status for an email * on the crm * - * @param string $email - * @param boolean $opt_in + * @param string $email + * @param boolean $opt_in + * @param array|null $answerId * * @return boolean true if the operation succeeded false otherwise * @throws \LDC\LDCCRM\Exceptions\ValidationException If a field email could not be validated. @@ -293,12 +294,13 @@ class WPCrm * @throws \LDC\LDCCRM\Exceptions\ApiErrorException If any error or \LDC\LDCCRM\Enums\ApiError occurs. * Possibles are : - singleOptinCustomerExists, If a customer exists with this email. */ - public static function setSingleOptin(string $email, bool $opt_in): bool + public static function setSingleOptin(string $email, bool $opt_in, ?array $answerId = null): bool { - return self::makeApiV4Call(SingleOptin::class, 'setStatus', [ - $email, - $opt_in - ]); + return self::makeApiV4Call( + SingleOptin::class, + 'setStatus', + array_filter([$email, $opt_in, $answerId], fn($v) => !is_null($v)) + ); } /**