diff --git a/src/Models/SingleOptin.php b/src/Models/SingleOptin.php index 279ef3d..cee2273 100644 --- a/src/Models/SingleOptin.php +++ b/src/Models/SingleOptin.php @@ -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|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); }