Skip to content

Commit

Permalink
Merge pull request #8 from lamoda/feature/CORE-3376
Browse files Browse the repository at this point in the history
Add method sell_correction for v4 and v5
  • Loading branch information
DmitriyMatvienko committed Sep 24, 2021
2 parents e346500 + 6372f53 commit 7fb0f9b
Show file tree
Hide file tree
Showing 22 changed files with 1,600 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/V4/AtolApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
140 changes: 140 additions & 0 deletions src/V4/DTO/Correction/Correction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

declare(strict_types=1);

namespace Lamoda\AtolClient\V4\DTO\Correction;

use JMS\Serializer\Annotation as Serializer;
use Lamoda\AtolClient\V4\DTO\Register\Company;
use Lamoda\AtolClient\V4\DTO\Register\Payment;
use Lamoda\AtolClient\V4\DTO\Register\Vat;

final class Correction
{
/**
* @var Company
*
* @Serializer\Type("Lamoda\AtolClient\V4\DTO\Register\Company")
*/
private $company;

/**
* @var CorrectionInfo
*
* @Serializer\Type("Lamoda\AtolClient\V4\DTO\Correction\CorrectionInfo")
* @Serializer\SerializedName("correction_info")
*/
private $correctionInfo;

/**
* @var Payment[]
*
* @Serializer\Type("array<Lamoda\AtolClient\V4\DTO\Register\Payment>")
*/
private $payments;

/**
* @var Vat[]
*
* @Serializer\Type("array<Lamoda\AtolClient\V4\DTO\Register\Vat>")
*/
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;
}


}
98 changes: 98 additions & 0 deletions src/V4/DTO/Correction/CorrectionInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

declare(strict_types=1);

namespace Lamoda\AtolClient\V4\DTO\Correction;

use JMS\Serializer\Annotation as Serializer;

final class CorrectionInfo
{
/**
* @var CorrectionType
*
* @Serializer\Type("Enum<'Lamoda\AtolClient\V4\DTO\Correction\CorrectionType'>")
*/
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;
}

}
83 changes: 83 additions & 0 deletions src/V4/DTO/Correction/CorrectionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

namespace Lamoda\AtolClient\V4\DTO\Correction;

use JMS\Serializer\Annotation as Serializer;
use Lamoda\AtolClient\V4\DTO\Register\Service;
use Lamoda\AtolClient\V4\DTO\Shared\TimestampTrait;

final class CorrectionRequest
{
use TimestampTrait;

/**
* @var string
*
* @Serializer\Type("string")
* @Serializer\SerializedName("external_id")
*/
private $externalId;

/**
* @var Service|null
*
* @Serializer\Type("Lamoda\AtolClient\V4\DTO\Register\Service")
*/
private $service;

/**
* @var Correction
*
* @Serializer\Type("Lamoda\AtolClient\V4\DTO\Correction\Correction")
*/
private $correction;

public function __construct(string $externalId, Correction $correction, \DateTime $timestamp)
{
$this->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;
}

}
Loading

0 comments on commit 7fb0f9b

Please sign in to comment.