212 protected function call($methodName, $additionalParams =
null, $licenseCheck =
false, $clearAccessSettings =
false)
214 $this->errorCollection->clear();
216 if($clearAccessSettings)
219 if(is_null($this->accessSettings))
222 if($this->accessSettings ===
false)
225 if(!is_array($additionalParams))
227 $additionalParams = array();
231 $additionalParams = Encoding::convertEncodingArray($additionalParams, LANG_CHARSET,
"utf-8");
234 $additionalParams[
'client_id'] = $this->accessSettings[
'client_id'];
235 $additionalParams[
'client_secret'] = $this->accessSettings[
'client_secret'];
237 $additionalParams[
'key'] = static::getLicenseHash();
239 $http =
new HttpClient(array(
'socketTimeout' => $this->httpTimeout));
240 $result = $http->post(
241 static::SERVICE_HOST.static::REST_URI.$methodName,
245 if($result ===
false)
247 $httpErrors = $http->getError();
248 foreach ($httpErrors as $errorCode => $errorText)
250 $this->errorCollection->add(array(
new Error($errorText, $errorCode)));
257 if(!is_array($answer) || count($answer) == 0)
259 $this->errorCollection->add(array(
new Error(
'Malformed answer from service: '.$http->getStatus().
' '.$result, static::ERROR_SERVICE_UNAVAILABLE)));
263 if(array_key_exists(
'error', $answer))
265 if($answer[
'error'] ===
'verification_needed' && !$licenseCheck)
267 return $this->
call($methodName, $additionalParams,
true);
269 else if(($answer[
'error'] ===
'ACCESS_DENIED' || $answer[
'error'] ===
'Invalid client')
270 && !$clearAccessSettings)
272 return $this->
call($methodName, $additionalParams,
true,
true);
275 $this->errorCollection->add(array(
new Error($answer[
'error_description'], $answer[
'error'])));
279 if($answer[
'result'] ==
false)
281 $this->errorCollection->add(array(
new Error(
Loc::getMessage(
'SALE_PROPERTIES_ERROR_NOTHING_FOUND'), static::ERROR_NOTHING_FOUND)));
284 return $answer[
'result'];
308 protected function register()
312 $queryParams = array(
313 "key" => static::getLicenseHash(),
314 "scope" => static::SCOPE,
315 "redirect_uri" => static::getRedirectUri(),
318 $result = $httpClient->post(static::SERVICE_HOST.static::REGISTER_URI, $queryParams);
320 if($result ===
false)
322 $this->errorCollection->add(array(
new Error($result[
"error"], static::ERROR_SERVICE_UNAVAILABLE)));
326 $result = Json::decode($result);
329 $this->errorCollection->add(array(
new Error($result[
"error"], static::ERROR_WRONG_LICENSE)));