Merge branch 'single-optin-answer' into 'develop'

fix: 🐛 update optionnal answer id parameter when set new single optin for laravel and wordpress

See merge request ldc-web/projets/crm-client!10
This commit is contained in:
Vincent BRIDIER 2025-08-06 15:15:32 +00:00
commit 28596bc9e8
5 changed files with 26 additions and 19 deletions

View file

@ -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

View file

@ -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",

View file

@ -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);
}
/**

View file

@ -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);
}

View file

@ -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))
);
}
/**