52 protected function call($methodName, $additionalParams =
null, $licenseCheck =
false, $clearAccessSettings =
false)
56 if(!self::isServerAlive() && !defined(
'SALE_SRVS_RESTCLIENT_DISABLE_SRV_ALIVE_CHECK'))
60 Loc::getMessage(
'SALE_SRV_BASE_REST_CONNECT_ERROR').
' '.$this->
getServiceHost(),
61 self::ERROR_SERVICE_UNAVAILABLE
67 if ($clearAccessSettings)
70 $this->accessSettings =
null;
73 if (is_null($this->accessSettings))
75 $this->accessSettings = $this->getAccessSettings();
78 if (!$this->accessSettings)
82 'SALE_SRV_BASE_REST_ACCESS_SETTINGS_ERROR_MSGVER_1',
83 [
'#TECH_DOMAIN#' => $urlProvider->getTechDomain()],
89 if (!is_array($additionalParams))
90 $additionalParams =
array();
93 $additionalParams[
'client_id'] = $this->accessSettings[
'client_id'];
94 $additionalParams[
'client_secret'] = $this->accessSettings[
'client_secret'];
95 $additionalParams[
'lang'] = LANGUAGE_ID;
99 $additionalParams = static::signLicenseRequest($additionalParams, static::getLicense());
104 'socketTimeout' => $this->httpTimeout,
105 'streamTimeout' => $this->streamTimeout,
107 $postResult = @$http->post(
108 $host.static::REST_URI.$methodName,
121 if (!is_array($answer))
123 $result->addError(
new Error(Loc::getMessage(
'SALE_SRV_BASE_REST_ANSWER_ERROR').
' '.$this->
getServiceHost().
'. (Status: "'.$http->getStatus().
'", Result: "'.$postResult.
'")', static::ERROR_SERVICE_UNAVAILABLE));
128 if(self::getLastUnSuccessCount() > 0)
131 if (array_key_exists(
'error', $answer))
133 if ($answer[
'error'] ===
'verification_needed')
137 $result->addError(
new Error($answer[
'error'].
". ".$answer[
'error_description'], self::ERROR_WRONG_LICENSE));
142 return $this->
call($methodName, $additionalParams,
true);
145 else if (($answer[
'error'] ===
'ACCESS_DENIED' || $answer[
'error'] ===
'Invalid client' || $answer[
'error'] ===
'NO_AUTH_FOUND')
146 && !$clearAccessSettings)
148 return $this->
call($methodName, $additionalParams,
true,
true);
151 $result->addError(
new Error($answer[
'error'].
". ".$answer[
'error_description']));
155 if ($answer[
'result'] ==
false)
156 $result->addError(
new Error(
'Nothing found', static::ERROR_NOTHING_FOUND));
158 if (is_array($answer[
'result']))
159 $result->addData($answer[
'result']);
197 protected function register()
202 $queryParams =
array(
203 "scope" => static::SCOPE,
204 "redirect_uri" => static::getRedirectUri(),
207 $queryParams = static::signLicenseRequest($queryParams, static::getLicense());
209 $postResult = $httpClient->post(
$host.static::REGISTER_URI, $queryParams);
211 if ($postResult ===
false)
213 $result->addError(
new Error(implode(
"\n", $httpClient->getError()), static::ERROR_SERVICE_UNAVAILABLE));
219 $jsonResult = Json::decode($postResult);
227 if (!empty($jsonResult[
"error"]))
229 $result->addError(
new Error($jsonResult[
"error"], static::ERROR_WRONG_LICENSE));
352 static $alreadySetted =
false;
354 if($alreadySetted && !$reset)
361 $alreadySetted =
true;
362 $last = static::getLastUnSuccessCallInfo();
364 $lastCount = (int)($last[
'COUNT'] ?? 0);
367 'COUNT' => $lastCount > 0 ? $lastCount + 1 : 1,
368 'TIMESTAMP' => time()
372 Option::set(
'sale', static::UNSUCCESSFUL_CALL_OPTION,
$data);