- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/services/base/restclient.php
- Класс: BitrixSaleServicesBaseRestClient
- Вызов: RestClient::register
protected function register()
{
$result = new Result();
$httpClient = new HttpClient();
$queryParams = array(
"scope" => static::SCOPE,
"redirect_uri" => static::getRedirectUri(),
);
$queryParams = static::signLicenseRequest($queryParams, static::getLicense());
$host = $this->getServiceHost();
$postResult = $httpClient->post($host.static::REGISTER_URI, $queryParams);
if ($postResult === false)
{
$result->addError(new Error(implode("n", $httpClient->getError()), static::ERROR_SERVICE_UNAVAILABLE));
return $result;
}
try
{
$jsonResult = Json::decode($postResult);
}
catch(Exception $e)
{
$result->addError(new Error($e->getMessage()));
return $result;
}
if (!empty($jsonResult["error"]))
{
$result->addError(new Error($jsonResult["error"], static::ERROR_WRONG_LICENSE));
}
else
{
$result->addData($jsonResult);
}
return $result;
}