@@ -9,8 +9,7 @@
namespace AtolOnline\Api ;
use AtolOnline\ { Entities\Company ,
Entities\Document ,
use AtolOnline\ { Entities\Document ,
Exceptions\AtolCorrectionInfoException ,
Exceptions\AtolInvalidUuidException ,
Exceptions\AtolKktLoginEmptyException ,
@@ -223,104 +222,115 @@ class Kkt extends Client
* Регистрирует документ прихода
*
* @param \AtolOnline\Entities\Document $document
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function sell ( Document $document )
public function sell ( Document $document , ? string $external_id = null )
{
if ( $document -> getCorrectionInfo ()) {
throw new AtolCorrectionInfoException ( 'Некорректная операция над документом коррекции' );
}
return $this -> registerDocument ( 'sell' , 'receipt' , $document );
return $this -> registerDocument ( 'sell' , 'receipt' , $document , $external_id );
}
/**
* Регистрирует документ возврата прихода
*
* @param \AtolOnline\Entities\Document $document
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException Слишком большая сумма
* @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
*/
public function sellRefund ( Document $document )
public function sellRefund ( Document $document , ? string $external_id = null )
{
if ( $document -> getCorrectionInfo ()) {
throw new AtolCorrectionInfoException ( 'Некорректная операция над документом коррекции' );
}
return $this -> registerDocument ( 'sell_refund' , 'receipt' , $document -> clearVats ());
return $this -> registerDocument ( 'sell_refund' , 'receipt' , $document -> clearVats (), $external_id );
}
/**
* Регистрирует документ коррекции прихода
*
* @param \AtolOnline\Entities\Document $document
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе отсутствуют данные коррекции
* @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function sellCorrection ( Document $document )
public function sellCorrection ( Document $document , ? string $external_id = null )
{
if ( ! $document -> getCorrectionInfo ()) {
throw new AtolCorrectionInfoException ();
}
$document -> setClient ( null ) -> setItems ([]);
return $this -> registerDocument ( 'sell_correction' , 'correction' , $document );
return $this -> registerDocument ( 'sell_correction' , 'correction' , $document , $external_id );
}
/**
* Регистрирует документ расхода
*
* @param \AtolOnline\Entities\Document $document
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function buy ( Document $document )
public function buy ( Document $document , ? string $external_id = null )
{
if ( $document -> getCorrectionInfo ()) {
throw new AtolCorrectionInfoException ( 'Некорректная операция над документом коррекции' );
}
return $this -> registerDocument ( 'buy' , 'receipt' , $document );
return $this -> registerDocument ( 'buy' , 'receipt' , $document , $external_id );
}
/**
* Регистрирует документ возврата расхода
*
* @param \AtolOnline\Entities\Document $document
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException Слишком большая сумма
* @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function buyRefund ( Document $document )
public function buyRefund ( Document $document , ? string $external_id = null )
{
if ( $document -> getCorrectionInfo ()) {
throw new AtolCorrectionInfoException ( 'Некорректная операция над документом коррекции' );
}
return $this -> registerDocument ( 'buy_refund' , 'receipt' , $document -> clearVats ());
return $this -> registerDocument ( 'buy_refund' , 'receipt' , $document -> clearVats (), $external_id );
}
/**
* Регистрирует документ коррекции расхода
*
* @param Document $document
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе отсутствуют данные коррекции
* @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function buyCorrection ( Document $document )
public function buyCorrection ( Document $document , ? string $external_id = null )
{
if ( ! $document -> getCorrectionInfo ()) {
throw new AtolCorrectionInfoException ();
}
$document -> setClient ( null ) -> setItems ([]);
return $this -> registerDocument ( 'buy_correction' , 'correction' , $document );
return $this -> registerDocument ( 'buy_correction' , 'correction' , $document , $external_id );
}
/**
@@ -365,6 +375,28 @@ class Kkt extends Client
return $response ;
}
/**
* Возвращает текущий токен авторизации
*
* @return string
*/
public function getAuthToken () : ? string
{
return $this -> auth_token ;
}
/**
* Устанавливает заранее известный токен авторизации
*
* @param string|null $auth_token
* @return $this
*/
public function setAuthToken ( ? string $auth_token )
{
$this -> auth_token = $auth_token ;
return $this ;
}
/**
* Сбрасывает настройки К К Т по умолчанию
*/
@@ -476,11 +508,7 @@ class Kkt extends Client
* @param \AtolOnline\Entities\Document $document Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return \AtolOnline\Api\KktResponse
* @throws \AtolOnline\Exceptions\AtolEmailTooLong Exception
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
* @throws \AtolOnline\Exceptions\AtolPaymentAddressTooLongException
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
* @throws \AtolOnline\Exceptions\AtolWrongDocumentType Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
protected function registerDocument ( string $api_method , string $type , Document $document , ? string $external_id = null )
@@ -490,14 +518,6 @@ class Kkt extends Client
throw new AtolWrongDocumentTypeException ( $type );
}
$this -> auth ();
if ( $this -> isTestMode ()) {
$document -> setCompany (( new Company ())
-> setInn ( '5544332219' )
-> setPaymentAddress ( 'https://v4.online.atol.ru' )
-> setEmail ( 'test@example.com' )
-> setSno ( 'osn' )
);
}
$data [ 'timestamp' ] = date ( 'd.m.y H:i:s' );
$data [ 'external_id' ] = $external_id ? : Uuid :: uuid4 () -> toString ();
$data [ $type ] = $document ;
@@ -506,14 +526,4 @@ class Kkt extends Client
}
return $this -> sendAtolRequest ( 'POST' , trim ( $api_method ), $data );
}
/**
* Возвращает текущий токен авторизации
*
* @return string
*/
public function getAuthToken () : ? string
{
return $this -> auth_token ;
}
}