feat: ✨ add optionnal answer id parameter when set new single optin
This commit is contained in:
parent
1cb88fce19
commit
833d024d99
1 changed files with 18 additions and 9 deletions
|
|
@ -27,26 +27,35 @@ abstract class SingleOptin extends ClientModel
|
|||
];
|
||||
|
||||
/**
|
||||
* Set the single opt in status for an email
|
||||
* Set the single opt in status for an email,
|
||||
* with an optionnal answer associated.
|
||||
*
|
||||
* @param string $email
|
||||
* @param boolean $opt_in
|
||||
* @param string $email
|
||||
* @param boolean $opt_in
|
||||
* @param array<int,int>|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.
|
||||
* @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 setStatus(#[\SensitiveParameter] string $email, bool $opt_in): bool
|
||||
public static function setStatus(#[\SensitiveParameter] string $email, bool $opt_in, ?array $answerId = null): bool
|
||||
{
|
||||
self::validateValue('email', $email);
|
||||
static::setUpApiInterface();
|
||||
$request = Utils::getResquest('apiV4.optin', [], [
|
||||
'email' => $email,
|
||||
'opt_in' => $opt_in
|
||||
]);
|
||||
|
||||
$response = static::$apiInterface->call($request);
|
||||
$payload = [
|
||||
'email' => $email,
|
||||
'opt_in' => $opt_in,
|
||||
];
|
||||
|
||||
if (!is_null($answerId) && count($answerId)) {
|
||||
$payload['answer_id'] = $answerId;
|
||||
}
|
||||
|
||||
$response = static::$apiInterface->call(
|
||||
Utils::getResquest('apiV4.optin', [], $payload)
|
||||
);
|
||||
return $response->status->equals(ApiStatus::OK);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue