diff --git a/src/V4/AtolApi.php b/src/V4/AtolApi.php index 3558eb6..64b4b26 100644 --- a/src/V4/AtolApi.php +++ b/src/V4/AtolApi.php @@ -7,6 +7,8 @@ use Lamoda\AtolClient\Converter\ObjectConverter; use GuzzleHttp\ClientInterface; use GuzzleHttp\RequestOptions; +use Lamoda\AtolClient\V4\DTO\Correction\CorrectionRequest; +use Lamoda\AtolClient\V4\DTO\Correction\CorrectionResponse; use Lamoda\AtolClient\V4\DTO\GetToken\GetTokenRequest; use Lamoda\AtolClient\V4\DTO\GetToken\GetTokenResponse; use Lamoda\AtolClient\V4\DTO\Register\RegisterRequest; @@ -17,6 +19,7 @@ final class AtolApi { private const OPERATION_SELL = 'sell'; private const OPERATION_SELL_REFUND = 'sell_refund'; + private const OPERATION_SELL_CORRECTION = 'sell_correction'; /** * @var ClientInterface @@ -67,6 +70,11 @@ public function sellRefund(string $groupCode, string $token, RegisterRequest $re return $this->register(self::OPERATION_SELL_REFUND, $groupCode, $token, $request); } + public function sellCorrection(string $groupCode, string $token, CorrectionRequest $request): CorrectionResponse + { + return $this->correction(self::OPERATION_SELL_CORRECTION, $groupCode, $token, $request); + } + public function report(string $groupCode, string $token, string $uuid): ReportResponse { $response = $this->request( @@ -82,6 +90,25 @@ public function report(string $groupCode, string $token, string $uuid): ReportRe return $this->converter->getResponseObject(ReportResponse::class, $response); } + private function correction( + string $operation, + string $groupCode, + string $token, + CorrectionRequest $request + ): CorrectionResponse { + $response = $this->request( + 'POST', + "$groupCode/$operation", + [], + $request, + [ + 'Token' => $token, + ] + ); + + return $this->converter->getResponseObject(CorrectionResponse::class, $response); + } + private function register( string $operation, string $groupCode, diff --git a/src/V4/DTO/Correction/Correction.php b/src/V4/DTO/Correction/Correction.php new file mode 100644 index 0000000..00ccfbe --- /dev/null +++ b/src/V4/DTO/Correction/Correction.php @@ -0,0 +1,140 @@ +") + */ + private $payments; + + /** + * @var Vat[] + * + * @Serializer\Type("array") + */ + private $vats; + + /** + * @var string|null + * + * @Serializer\Type("string") + */ + private $cashier; + + public function __construct(Company $company, CorrectionInfo $correctionInfo, array $payments, array $vats) + { + $this->company = $company; + $this->correctionInfo = $correctionInfo; + $this->payments = $payments; + $this->vats = $vats; + } + + public function getCorrectionInfo(): CorrectionInfo + { + return $this->correctionInfo; + } + + public function setCorrectionInfo(CorrectionInfo $correctionInfo): self + { + $this->correctionInfo = $correctionInfo; + + return $this; + } + + public function getCompany(): Company + { + return $this->company; + } + + public function setCompany(Company $company): self + { + $this->company = $company; + + return $this; + } + + /** + * @return Payment[] + */ + public function getPayments(): array + { + return $this->payments; + } + + /** + * @param Payment[] $payments + * + * @return Correction + */ + public function setPayments(array $payments): self + { + $this->payments = $payments; + + return $this; + } + + /** + * @return Vat[] + */ + public function getVats(): array + { + return $this->vats; + } + + /** + * @param Vat[] $vats + * + * @return Correction + */ + public function setVats(array $vats): self + { + $this->vats = $vats; + + return $this; + } + + public function getCashier(): string + { + return $this->cashier; + } + + /** + * @param string $cashier + * + * @return Correction + */ + public function setCashier(string $cashier): self + { + $this->cashier = $cashier; + + return $this; + } + + +} diff --git a/src/V4/DTO/Correction/CorrectionInfo.php b/src/V4/DTO/Correction/CorrectionInfo.php new file mode 100644 index 0000000..9f9f660 --- /dev/null +++ b/src/V4/DTO/Correction/CorrectionInfo.php @@ -0,0 +1,98 @@ +") + */ + private $type; + + /** + * @var \DateTime + * + * @Serializer\Type("DateTime<'d.m.Y'>") + * @Serializer\SerializedName("base_date") + */ + private $baseDate; + + /** + * @var string + * + * @Serializer\Type("string") + * @Serializer\SerializedName("base_number") + */ + private $baseNumber; + + /** + * @var string + * + * @Serializer\Type("string") + * @Serializer\SerializedName("base_name") + */ + private $baseName; + + public function __construct(CorrectionType $type, \DateTime $baseDate, string $baseNumber, string $baseName) + { + $this->type = $type; + $this->baseDate = $baseDate; + $this->baseNumber = $baseNumber; + $this->baseName = $baseName; + } + + public function getType(): CorrectionType + { + return $this->type; + } + + public function setType(CorrectionType $type): self + { + $this->type = $type; + + return $this; + } + + public function getBaseDate(): \DateTime + { + return $this->baseDate; + } + + public function setBaseDate(\DateTime $baseDate): self + { + $this->baseDate = $baseDate; + + return $this; + } + + public function getBaseNumber(): string + { + return $this->baseNumber; + } + + public function setBaseNumber(string $baseNumber): self + { + $this->baseNumber = $baseNumber; + + return $this; + } + + public function getBaseName(): string + { + return $this->baseName; + } + + public function setBaseName(string $baseName): self + { + $this->baseName = $baseName; + + return $this; + } + +} diff --git a/src/V4/DTO/Correction/CorrectionRequest.php b/src/V4/DTO/Correction/CorrectionRequest.php new file mode 100644 index 0000000..f69006b --- /dev/null +++ b/src/V4/DTO/Correction/CorrectionRequest.php @@ -0,0 +1,83 @@ +externalId = $externalId; + $this->correction = $correction; + $this->timestamp = $timestamp; + } + + public function setTimestamp(\DateTime $timestamp): self + { + $this->timestamp = $timestamp; + + return $this; + } + + public function getExternalId(): string + { + return $this->externalId; + } + + public function setExternalId(string $externalId): void + { + $this->externalId = $externalId; + } + + public function getService(): ?Service + { + return $this->service; + } + + public function setService(?Service $service): void + { + $this->service = $service; + } + + public function getCorrection(): Correction + { + return $this->correction; + } + + public function setCorrection(Correction $correction): self + { + $this->correction = $correction; + + return $this; + } + +} diff --git a/src/V4/DTO/Correction/CorrectionResponse.php b/src/V4/DTO/Correction/CorrectionResponse.php new file mode 100644 index 0000000..261a161 --- /dev/null +++ b/src/V4/DTO/Correction/CorrectionResponse.php @@ -0,0 +1,40 @@ +") + */ + private $status; + + public function getUuid(): ?string + { + return $this->uuid; + } + + public function getStatus(): ?Status + { + return $this->status; + } +} diff --git a/src/V4/DTO/Correction/CorrectionType.php b/src/V4/DTO/Correction/CorrectionType.php new file mode 100644 index 0000000..1675075 --- /dev/null +++ b/src/V4/DTO/Correction/CorrectionType.php @@ -0,0 +1,17 @@ +register(self::OPERATION_SELL_REFUND, $groupCode, $token, $request); } + public function sellCorrection(string $groupCode, string $token, CorrectionRequest $request): CorrectionResponse + { + return $this->correction(self::OPERATION_SELL_CORRECTION, $groupCode, $token, $request); + } + public function report(string $groupCode, string $token, string $uuid): ReportResponse { $response = $this->request( @@ -82,6 +90,25 @@ public function report(string $groupCode, string $token, string $uuid): ReportRe return $this->converter->getResponseObject(ReportResponse::class, $response); } + private function correction( + string $operation, + string $groupCode, + string $token, + CorrectionRequest $request + ): CorrectionResponse { + $response = $this->request( + 'POST', + "$groupCode/$operation", + [], + $request, + [ + 'Token' => $token, + ] + ); + + return $this->converter->getResponseObject(CorrectionResponse::class, $response); + } + private function register( string $operation, string $groupCode, diff --git a/src/V5/DTO/Correction/AdditionalUserProps.php b/src/V5/DTO/Correction/AdditionalUserProps.php new file mode 100644 index 0000000..56ec660 --- /dev/null +++ b/src/V5/DTO/Correction/AdditionalUserProps.php @@ -0,0 +1,53 @@ +name = $name; + $this->value = $value; + } + + public function getName(): string + { + return $this->name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + + public function getValue(): string + { + return $this->value; + } + + public function setValue(string $value): self + { + $this->value = $value; + + return $this; + } + +} diff --git a/src/V5/DTO/Correction/Correction.php b/src/V5/DTO/Correction/Correction.php new file mode 100644 index 0000000..fd89c96 --- /dev/null +++ b/src/V5/DTO/Correction/Correction.php @@ -0,0 +1,312 @@ +") + */ + private $items; + + /** + * @var Payment[] + * + * @Serializer\Type("array") + */ + private $payments; + + /** + * @var Vat[] + * + * @Serializer\Type("array") + */ + private $vats; + + /** + * @var string|null + * + * @Serializer\Type("string") + */ + private $cashier; + + /** + * @var string|null + * + * @Serializer\Type("string") + * @Serializer\SerializedName("cashier_inn") + */ + private $cashierInn; + + /** + * @var string|null + * + * @Serializer\Type("string") + * @Serializer\SerializedName("additional_check_props") + */ + private $additionalCheckProps; + + /** + * @var AdditionalUserProps|null + * + * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Correction\AdditionalUserProps") + * @Serializer\SerializedName("additional_user_props") + */ + private $additionalUserProps; + + /** + * @var OperatingCheckProps|null + * + * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Correction\OperatingCheckProps") + * @Serializer\SerializedName("operating_check_props") + */ + private $operatingCheckProps; + + /** + * @var SectoralCheckProps|null + * + * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Correction\SectoralCheckProps") + * @Serializer\SerializedName("sectoral_check_props") + */ + private $sectoralCheckProps; + + /** + * @var float + * + * @Serializer\Type("float") + */ + private $total; + + public function __construct(Company $company, CorrectionInfo $correctionInfo, array $items, array $payments, array $vats, float $total) + { + $this->company = $company; + $this->correctionInfo = $correctionInfo; + $this->items = $items; + $this->payments = $payments; + $this->vats = $vats; + $this->total = $total; + } + + /** + * @return Item[] + */ + public function getItems(): array + { + return $this->items; + } + + /** + * @param Item[] $items + * + * @return Correction + */ + public function setItems(array $items): self + { + $this->items = $items; + + return $this; + } + + public function getCorrectionInfo(): CorrectionInfo + { + return $this->correctionInfo; + } + + public function setCorrectionInfo(CorrectionInfo $correctionInfo): self + { + $this->correctionInfo = $correctionInfo; + + return $this; + } + + public function getCompany(): Company + { + return $this->company; + } + + public function setCompany(Company $company): self + { + $this->company = $company; + + return $this; + } + + /** + * @return Payment[] + */ + public function getPayments(): array + { + return $this->payments; + } + + /** + * @param Payment[] $payments + * + * @return Correction + */ + public function setPayments(array $payments): self + { + $this->payments = $payments; + + return $this; + } + + /** + * @return Vat[] + */ + public function getVats(): array + { + return $this->vats; + } + + /** + * @param Vat[] $vats + * + * @return Correction + */ + public function setVats(array $vats): self + { + $this->vats = $vats; + + return $this; + } + + public function getCashier(): string + { + return $this->cashier; + } + + /** + * @param string $cashier + * + * @return Correction + */ + public function setCashier(string $cashier): self + { + $this->cashier = $cashier; + + return $this; + } + + /** + * @return Client|null + */ + public function getClient(): ?Client + { + return $this->client; + } + + /** + * @param Client|null $client + */ + public function setClient(?Client $client): void + { + $this->client = $client; + } + + public function getCashierInn(): ?string + { + return $this->cashierInn; + } + + public function setCashierInn(?string $cashierInn): self + { + $this->cashierInn = $cashierInn; + + return $this; + } + + public function getAdditionalCheckProps(): ?string + { + return $this->additionalCheckProps; + } + + public function setAdditionalCheckProps(?string $additionalCheckProps): self + { + $this->additionalCheckProps = $additionalCheckProps; + + return $this; + } + + public function getAdditionalUserProps(): ?AdditionalUserProps + { + return $this->additionalUserProps; + } + + public function setAdditionalUserProps(?AdditionalUserProps $additionalUserProps): self + { + $this->additionalUserProps = $additionalUserProps; + + return $this; + } + + public function getOperatingCheckProps(): ?OperatingCheckProps + { + return $this->operatingCheckProps; + } + + public function setOperatingCheckProps(?OperatingCheckProps $operatingCheckProps): self + { + $this->operatingCheckProps = $operatingCheckProps; + + return $this; + } + + public function getSectoralCheckProps(): ?SectoralCheckProps + { + return $this->sectoralCheckProps; + } + + public function setSectoralCheckProps(?SectoralCheckProps $sectoralCheckProps): self + { + $this->sectoralCheckProps = $sectoralCheckProps; + + return $this; + } + + public function getTotal(): float + { + return $this->total; + } + + public function setTotal(float $total): self + { + $this->total = $total; + + return $this; + } + +} diff --git a/src/V5/DTO/Correction/CorrectionInfo.php b/src/V5/DTO/Correction/CorrectionInfo.php new file mode 100644 index 0000000..06a7fd3 --- /dev/null +++ b/src/V5/DTO/Correction/CorrectionInfo.php @@ -0,0 +1,75 @@ +") + */ + private $type; + + /** + * @var \DateTime|null + * + * @Serializer\Type("DateTime<'d.m.Y'>") + * @Serializer\SerializedName("base_date") + */ + private $baseDate; + + /** + * @var string|null + * + * @Serializer\Type("string") + * @Serializer\SerializedName("base_number") + */ + private $baseNumber; + + public function __construct(CorrectionType $type) + { + $this->type = $type; + } + + public function getType(): CorrectionType + { + return $this->type; + } + + public function setType(CorrectionType $type): self + { + $this->type = $type; + + return $this; + } + + public function getBaseDate(): \DateTime + { + return $this->baseDate; + } + + public function setBaseDate(\DateTime $baseDate): self + { + $this->baseDate = $baseDate; + + return $this; + } + + public function getBaseNumber(): string + { + return $this->baseNumber; + } + + public function setBaseNumber(string $baseNumber): self + { + $this->baseNumber = $baseNumber; + + return $this; + } + +} diff --git a/src/V5/DTO/Correction/CorrectionRequest.php b/src/V5/DTO/Correction/CorrectionRequest.php new file mode 100644 index 0000000..716ee48 --- /dev/null +++ b/src/V5/DTO/Correction/CorrectionRequest.php @@ -0,0 +1,83 @@ +externalId = $externalId; + $this->correction = $correction; + $this->timestamp = $timestamp; + } + + public function setTimestamp(\DateTime $timestamp): self + { + $this->timestamp = $timestamp; + + return $this; + } + + public function getExternalId(): string + { + return $this->externalId; + } + + public function setExternalId(string $externalId): void + { + $this->externalId = $externalId; + } + + public function getService(): ?Service + { + return $this->service; + } + + public function setService(?Service $service): void + { + $this->service = $service; + } + + public function getCorrection(): Correction + { + return $this->correction; + } + + public function setCorrection(Correction $correction): self + { + $this->correction = $correction; + + return $this; + } + +} diff --git a/src/V5/DTO/Correction/CorrectionResponse.php b/src/V5/DTO/Correction/CorrectionResponse.php new file mode 100644 index 0000000..2c674f8 --- /dev/null +++ b/src/V5/DTO/Correction/CorrectionResponse.php @@ -0,0 +1,40 @@ +") + */ + private $status; + + public function getUuid(): ?string + { + return $this->uuid; + } + + public function getStatus(): ?Status + { + return $this->status; + } +} diff --git a/src/V5/DTO/Correction/CorrectionType.php b/src/V5/DTO/Correction/CorrectionType.php new file mode 100644 index 0000000..ccdec48 --- /dev/null +++ b/src/V5/DTO/Correction/CorrectionType.php @@ -0,0 +1,17 @@ +") + */ + private $timestamp; + + public function __construct(string $name, string $value, \DateTime $timestamp) + { + $this->name = $name; + $this->value = $value; + $this->timestamp = $timestamp; + } + + public function getTimestamp(): \DateTime + { + return $this->timestamp; + } + + public function setTimestamp($timestamp): self + { + $this->timestamp = $timestamp; + + return $this; + } + + public function getName(): string + { + return $this->name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } + + public function getValue(): string + { + return $this->value; + } + + public function setValue(string $value): self + { + $this->value = $value; + + return $this; + } + +} diff --git a/src/V5/DTO/Correction/SectoralCheckProps.php b/src/V5/DTO/Correction/SectoralCheckProps.php new file mode 100644 index 0000000..7b57595 --- /dev/null +++ b/src/V5/DTO/Correction/SectoralCheckProps.php @@ -0,0 +1,94 @@ +) + */ + private $federalId; + + /** + * @var \DateTime + * + * @Serializer\Type("DateTime<'d.m.Y'>") + */ + private $date; + + /** + * @var string + * + * @Serializer\Type("string") + */ + private $number; + + /** + * @var string + * + * @Serializer\Type("string") + */ + private $value; + + public function __construct(string $federalId, \DateTime $date, string $number, string $value) + { + $this->federalId = $federalId; + $this->date = $date; + $this->number = $number; + $this->value = $value; + } + + + public function getFederalId(): FederalId + { + return $this->federalId; + } + + public function setFederalId(FederalId $federalId): self + { + $this->federalId = $federalId; + + return $this; + } + + public function getDate(): \DateTime + { + return $this->date; + } + + public function setDate(\DateTime $date): self + { + $this->date = $date; + + return $this; + } + + public function getNumber(): string + { + return $this->number; + } + + public function setNumber(string $number): self + { + $this->number = $number; + + return $this; + } + + public function getValue(): string + { + return $this->value; + } + + public function setValue(string $value): self + { + $this->value = $value; + + return $this; + } + +} diff --git a/tests/Functional/V4/AtolApiTest.php b/tests/Functional/V4/AtolApiTest.php index d676696..3a1e931 100644 --- a/tests/Functional/V4/AtolApiTest.php +++ b/tests/Functional/V4/AtolApiTest.php @@ -96,12 +96,24 @@ protected function setUpTestSell(): void $this->appendSuccessRegisterResponse(); } + protected function setUpTestSellCorrection(): void + { + $this->appendSuccessTokenResponse(); + $this->appendSuccessCorrectionResponse(); + } + protected function setUpTestSellWithInvalidRequest(): void { $this->appendSuccessTokenResponse(); $this->appendErrorRegisterResponse(); } + protected function setUpTestSellCorrectionWithInvalidRequest(): void + { + $this->appendSuccessTokenResponse(); + $this->appendErrorRegisterResponse(); + } + protected function setUpTestSellRefund(): void { $this->appendSuccessTokenResponse(); @@ -169,6 +181,21 @@ private function appendSuccessRegisterResponse(): void ); } + private function appendSuccessCorrectionResponse(): void + { + $this->mockHandler->append( + new Response(200, [], <<mockHandler->append( diff --git a/tests/Functional/V5/AtolApiTest.php b/tests/Functional/V5/AtolApiTest.php index 29ed4f3..d44280c 100644 --- a/tests/Functional/V5/AtolApiTest.php +++ b/tests/Functional/V5/AtolApiTest.php @@ -102,6 +102,19 @@ protected function setUpTestSellWithInvalidRequest(): void $this->appendErrorRegisterResponse(); } + protected function setUpTestSellCorrection(): void + { + $this->appendSuccessTokenResponse(); + $this->appendSuccessCorrectionResponse(); + } + + protected function setUpTestSellCorrectionWithInvalidRequest(): void + { + $this->appendSuccessTokenResponse(); + $this->appendErrorRegisterResponse(); + } + + protected function setUpTestSellRefund(): void { $this->appendSuccessTokenResponse(); @@ -169,6 +182,21 @@ private function appendSuccessRegisterResponse(): void ); } + private function appendSuccessCorrectionResponse(): void + { + $this->mockHandler->append( + new Response(200, [], <<mockHandler->append( diff --git a/tests/Integrational/V4/AtolApiTest.php b/tests/Integrational/V4/AtolApiTest.php index 291aa11..4fbb531 100644 --- a/tests/Integrational/V4/AtolApiTest.php +++ b/tests/Integrational/V4/AtolApiTest.php @@ -82,11 +82,21 @@ protected function setUpTestSell(): void // nothing } + protected function setUpTestSellCorrection(): void + { + // nothing + } + protected function setUpTestSellWithInvalidRequest(): void { // nothing } + protected function setUpTestSellCorrectionWithInvalidRequest(): void + { + // nothing + } + protected function setUpTestSellRefund(): void { // nothing diff --git a/tests/Integrational/V5/AtolApiTest.php b/tests/Integrational/V5/AtolApiTest.php index c4905c2..8e2054e 100644 --- a/tests/Integrational/V5/AtolApiTest.php +++ b/tests/Integrational/V5/AtolApiTest.php @@ -87,6 +87,16 @@ protected function setUpTestSellWithInvalidRequest(): void // nothing } + protected function setUpTestSellCorrection(): void + { + // nothing + } + + protected function setUpTestSellCorrectionWithInvalidRequest(): void + { + // nothing + } + protected function setUpTestSellRefund(): void { // nothing diff --git a/tests/TestCase/V4/AtolApiTestCase.php b/tests/TestCase/V4/AtolApiTestCase.php index 7fe771d..fd17622 100644 --- a/tests/TestCase/V4/AtolApiTestCase.php +++ b/tests/TestCase/V4/AtolApiTestCase.php @@ -5,6 +5,10 @@ namespace Lamoda\AtolClient\Tests\TestCase\V4; use Lamoda\AtolClient\V4\AtolApi; +use Lamoda\AtolClient\V4\DTO\Correction\Correction; +use Lamoda\AtolClient\V4\DTO\Correction\CorrectionInfo; +use Lamoda\AtolClient\V4\DTO\Correction\CorrectionRequest; +use Lamoda\AtolClient\V4\DTO\Correction\CorrectionType; use Lamoda\AtolClient\V4\DTO\GetToken\GetTokenRequest; use Lamoda\AtolClient\V4\DTO\Register\AgentInfo; use Lamoda\AtolClient\V4\DTO\Register\AgentType; @@ -47,8 +51,12 @@ abstract protected function setUpTestGetTokenWithInvalidCredentials(): void; abstract protected function setUpTestSell(): void; + abstract protected function setUpTestSellCorrection(): void; + abstract protected function setUpTestSellWithInvalidRequest(): void; + abstract protected function setUpTestSellCorrectionWithInvalidRequest(): void; + abstract protected function setUpTestSellRefund(): void; abstract protected function setUpTestSellRefundWithInvalidRequest(): void; @@ -137,6 +145,42 @@ final public function testSellWithInvalidRequest(): void $this->assertEquals(32, $error->getCode()); } + final public function testSellCorrection(): void + { + $this->setUpTestSellCorrection(); + + $token = $this->requestToken(); + + $request = $this->createSellCorrectionRequest(); + + $response = $this->api->sellCorrection($this->getGroupCode(), $token, $request); + + $this->assertNull($response->getError()); + $this->assertNotNull($response->getUuid()); + $this->assertInstanceOf(\DateTimeInterface::class, $response->getTimestamp()); + $this->assertEquals(RegisterStatus::WAIT(), $response->getStatus()); + } + + final public function testSellCorrectionWithInvalidRequest(): void + { + $this->setUpTestSellCorrectionWithInvalidRequest(); + + $token = $this->requestToken(); + + $request = $this->createInvalidSellCorrectionRequest(); + + $response = $this->api->sellCorrection($this->getGroupCode(), $token, $request); + + $this->assertNotNull($response->getError()); + $this->assertNull($response->getUuid()); + $this->assertInstanceOf(\DateTimeInterface::class, $response->getTimestamp()); + $this->assertEquals(RegisterStatus::FAIL(), $response->getStatus()); + + $error = $response->getError(); + + $this->assertEquals(32, $error->getCode()); + } + final public function testSellRefund(): void { $this->setUpTestSellRefund(); @@ -226,6 +270,37 @@ private function requestToken(): string return $response->getToken(); } + private function createSellCorrectionRequest(): CorrectionRequest + { + return new CorrectionRequest( + 'test-' . md5((string) microtime(true)), + new Correction( + new Company( + 'test@test.ru', + '5544332219', + 'https://v4.online.atol.ru' + ), + new CorrectionInfo( + CorrectionType::SELF(), + new \DateTime(), + 'num1', + 'Что-то поправлено' + ), + [ + new Payment( + PaymentType::ELECTRONIC(), + 1000.1 + ), + ], + [new Vat( + VatType::VAT120(), + 166.68 + )] + ), + new \DateTime() + ); + } + private function createRegisterRequest(): RegisterRequest { return new RegisterRequest( @@ -319,4 +394,13 @@ private function createInvalidRegisterRequest(): RegisterRequest new \DateTime() ); } + + private function createInvalidSellCorrectionRequest(): CorrectionRequest + { + $r = $this->createSellCorrectionRequest(); + $correction = $r->getCorrection()->setVats([]); + + return $r->setCorrection($correction); + } + } diff --git a/tests/TestCase/V5/AtolApiTestCase.php b/tests/TestCase/V5/AtolApiTestCase.php index 8e35e65..f57ff65 100644 --- a/tests/TestCase/V5/AtolApiTestCase.php +++ b/tests/TestCase/V5/AtolApiTestCase.php @@ -4,6 +4,10 @@ namespace Lamoda\AtolClient\Tests\TestCase\V5; +use Lamoda\AtolClient\V5\DTO\Correction\Correction; +use Lamoda\AtolClient\V5\DTO\Correction\CorrectionInfo; +use Lamoda\AtolClient\V5\DTO\Correction\CorrectionRequest; +use Lamoda\AtolClient\V5\DTO\Correction\CorrectionType; use Lamoda\AtolClient\V5\AtolApi; use Lamoda\AtolClient\V5\DTO\GetToken\GetTokenRequest; use Lamoda\AtolClient\V5\DTO\Register\AgentInfo; @@ -18,6 +22,7 @@ use Lamoda\AtolClient\V5\DTO\Register\PaymentObject; use Lamoda\AtolClient\V5\DTO\Register\PaymentType; use Lamoda\AtolClient\V5\DTO\Register\Receipt; +use Lamoda\AtolClient\V5\DTO\Register\ReceivePaymentsOperator; use Lamoda\AtolClient\V5\DTO\Register\RegisterRequest; use Lamoda\AtolClient\V5\DTO\Register\Sno; use Lamoda\AtolClient\V5\DTO\Register\Status as RegisterStatus; @@ -51,6 +56,10 @@ abstract protected function setUpTestSell(): void; abstract protected function setUpTestSellWithInvalidRequest(): void; + abstract protected function setUpTestSellCorrection(): void; + + abstract protected function setUpTestSellCorrectionWithInvalidRequest(): void; + abstract protected function setUpTestSellRefund(): void; abstract protected function setUpTestSellRefundWithInvalidRequest(): void; @@ -139,6 +148,42 @@ final public function testSellWithInvalidRequest(): void $this->assertEquals(32, $error->getCode()); } + final public function testSellCorrection(): void + { + $this->setUpTestSellCorrection(); + + $token = $this->requestToken(); + + $request = $this->createSellCorrectionRequest(); + + $response = $this->api->sellCorrection($this->getGroupCode(), $token, $request); + + $this->assertNull($response->getError()); + $this->assertNotNull($response->getUuid()); + $this->assertInstanceOf(\DateTimeInterface::class, $response->getTimestamp()); + $this->assertEquals(RegisterStatus::WAIT(), $response->getStatus()); + } + + final public function testSellCorrectionWithInvalidRequest(): void + { + $this->setUpTestSellCorrectionWithInvalidRequest(); + + $token = $this->requestToken(); + + $request = $this->createInvalidSellCorrectionRequest(); + + $response = $this->api->sellCorrection($this->getGroupCode(), $token, $request); + + $this->assertNotNull($response->getError()); + $this->assertNull($response->getUuid()); + $this->assertInstanceOf(\DateTimeInterface::class, $response->getTimestamp()); + $this->assertEquals(RegisterStatus::FAIL(), $response->getStatus()); + + $error = $response->getError(); + + $this->assertEquals(32, $error->getCode()); + } + final public function testSellRefund(): void { $this->setUpTestSellRefund(); @@ -269,6 +314,9 @@ private function createRegisterRequest(): RegisterRequest 'test', ['+79101234567'] )) + ->setReceivePaymentsOperator(new ReceivePaymentsOperator( + ['+79101234567'] + )) ) ->setSupplierInfo( new SupplierInfo( @@ -281,10 +329,10 @@ private function createRegisterRequest(): RegisterRequest [ new Payment( PaymentType::ELECTRONIC(), - 1500.1 + 1000.1 ), ], - 1500.1 + 1000.1 ), new \DateTime() ); @@ -331,4 +379,58 @@ private function createInvalidRegisterRequest(): RegisterRequest new \DateTime() ); } + + private function createSellCorrectionRequest(): CorrectionRequest + { + return new CorrectionRequest( + 'test-' . md5((string) microtime(true)), + new Correction( + new Company( + 'test@test.ru', + '5544332219', + 'https://v4.online.atol.ru', + Sno::OSN() + ), + (new CorrectionInfo( + CorrectionType::SELF() + )), + [ + new Item( + 'Test item', + 1000.1, + 1, + 1000.1, + PaymentMethod::FULL_PAYMENT(), + new Vat( + VatType::VAT120(), + 166.68 + ), + Measure::PIECE(), + PaymentObject::COMMODITY() + ), + ], + [ + new Payment( + PaymentType::ELECTRONIC(), + 1000.1 + ), + ], + [new Vat( + VatType::VAT120(), + 166.68 + )], + 1000.1 + ), + new \DateTime() + ); + } + + private function createInvalidSellCorrectionRequest(): CorrectionRequest + { + $r = $this->createSellCorrectionRequest(); + $correction = $r->getCorrection()->setVats([]); + + return $r->setCorrection($correction); + } + }