4 Commits

2 changed files with 15 additions and 6 deletions

View File

@@ -9,7 +9,8 @@
namespace AtolOnline\Api; namespace AtolOnline\Api;
use AtolOnline\{Entities\Document, use AtolOnline\{Entities\Company,
Entities\Document,
Exceptions\AtolCorrectionInfoException, Exceptions\AtolCorrectionInfoException,
Exceptions\AtolInvalidUuidException, Exceptions\AtolInvalidUuidException,
Exceptions\AtolKktLoginEmptyException, Exceptions\AtolKktLoginEmptyException,
@@ -172,7 +173,7 @@ class Kkt extends Client
*/ */
public function setCallbackUrl(string $url) public function setCallbackUrl(string $url)
{ {
$this->kkt_config['prod']['callback_url'] = $url; $this->kkt_config[$this->isTestMode() ? 'test' : 'prod']['callback_url'] = $url;
return $this; return $this;
} }
@@ -390,7 +391,7 @@ class Kkt extends Client
{ {
$headers['Content-type'] = 'application/json; charset=utf-8'; $headers['Content-type'] = 'application/json; charset=utf-8';
if ($this->getAuthToken()) { if ($this->getAuthToken()) {
$headers['Token'] = $this->auth_token; $headers['Token'] = $this->getAuthToken();
} }
return $headers; return $headers;
} }
@@ -429,6 +430,7 @@ class Kkt extends Client
* @param mixed $data Данные для передачи * @param mixed $data Данные для передачи
* @param array|null $options Параметры Guzzle * @param array|null $options Параметры Guzzle
* @return \AtolOnline\Api\KktResponse * @return \AtolOnline\Api\KktResponse
* @throws \GuzzleHttp\Exception\GuzzleException
* @see https://guzzle.readthedocs.io/en/latest/request-options.html * @see https://guzzle.readthedocs.io/en/latest/request-options.html
*/ */
protected function sendAtolRequest(string $http_method, string $api_method, $data = null, array $options = null) protected function sendAtolRequest(string $http_method, string $api_method, $data = null, array $options = null)
@@ -449,6 +451,7 @@ class Kkt extends Client
* Производит авторизацию на ККТ и получает токен доступа для дальнейших HTTP-запросов * Производит авторизацию на ККТ и получает токен доступа для дальнейших HTTP-запросов
* *
* @return bool * @return bool
* @throws \GuzzleHttp\Exception\GuzzleException
*/ */
protected function auth() protected function auth()
{ {
@@ -482,6 +485,12 @@ class Kkt extends Client
throw new AtolWrongDocumentTypeException($type); throw new AtolWrongDocumentTypeException($type);
} }
$this->auth(); $this->auth();
if ($this->isTestMode()) {
$document->setCompany((new Company())
->setInn('5544332219')
->setPaymentAddress('https://v4.online.atol.ru')
);
}
$data = [ $data = [
'timestamp' => date('d.m.y H:i:s'), 'timestamp' => date('d.m.y H:i:s'),
'external_id' => Uuid::uuid4()->toString(), 'external_id' => Uuid::uuid4()->toString(),
@@ -496,7 +505,7 @@ class Kkt extends Client
* *
* @return string * @return string
*/ */
protected function getAuthToken() public function getAuthToken(): ?string
{ {
return $this->auth_token; return $this->auth_token;
} }

View File

@@ -405,7 +405,7 @@ class Document extends Entity
$json['company'] = $this->getCompany()->jsonSerialize(); // обязательно $json['company'] = $this->getCompany()->jsonSerialize(); // обязательно
} }
if ($this->getPayments()) { if ($this->getPayments()) {
$json['payments'] = $this->getPayments()->jsonSerialize(); // обязательно $json['payments'] = $this->payments->jsonSerialize(); // обязательно
} }
if ($this->getCashier()) { if ($this->getCashier()) {
$json['cashier'] = $this->getCashier(); $json['cashier'] = $this->getCashier();
@@ -417,7 +417,7 @@ class Document extends Entity
$json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных $json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных
} }
if ($this->getItems()) { if ($this->getItems()) {
$json['items'] = $this->getItems()->jsonSerialize(); // обязательно для некоррекционных $json['items'] = $this->items->jsonSerialize(); // обязательно для некоррекционных
} }
$json['total'] = $this->calcTotal(); // обязательно для некоррекционных $json['total'] = $this->calcTotal(); // обязательно для некоррекционных
} }