1
0
mirror of synced 2024-11-21 20:46:03 +03:00

Remove V3 (#8)

This commit is contained in:
Vragov Roman 2019-08-22 17:04:26 +03:00 committed by Alexey
parent 6e0adffb46
commit ffd5b85fe0
22 changed files with 323 additions and 870 deletions

View File

@ -12,7 +12,6 @@ use Psr\Log\LoggerInterface;
class AtolOnlineApi
{
public const API_VERSION_V4 = 'v4';
public const API_VERSION_V3 = 'v3';
public const TOKEN_CACHE_KEY = 'crm_fiscal_atol_online_token';
public const TOKEN_CACHE_TIME = 86400;
@ -94,7 +93,7 @@ class AtolOnlineApi
*/
public function getVersion(): string
{
return $this->connection->version ?: self::API_VERSION_V3;
return $this->connection->version ?: self::API_VERSION_V4;
}
/**
@ -191,32 +190,19 @@ class AtolOnlineApi
if ($response) {
$response = json_decode($response->getBody(), true);
if ($this->connection->isVersion4()) {
if ($this->cache && !isset($response['error'])) {
$this->cache->save($this->getTokenCacheKey(), $response['token'], self::TOKEN_CACHE_TIME);
}
if ($this->logger && isset($response['error'])) {
$this->logger->error($response['error']['code'] . ' '. $response['error']['text']);
}
if (!isset($response['error'])) {
return $response['token'];
}
return false;
if ($this->cache && !isset($response['error'])) {
$this->cache->save($this->getTokenCacheKey(), $response['token'], self::TOKEN_CACHE_TIME);
}
if (isset($response['code']) && in_array($response['code'], [0, 1], true)) {
if ($this->cache) {
$this->cache->save($this->getTokenCacheKey(), $response['token'], self::TOKEN_CACHE_TIME);
}
if ($this->logger && isset($response['error'])) {
$this->logger->error($response['error']['code'] . ' '. $response['error']['text']);
}
if (!isset($response['error'])) {
return $response['token'];
}
}
return false;
}
@ -236,11 +222,7 @@ class AtolOnlineApi
return $url;
}
if ($this->getVersion() === self::API_VERSION_V4) {
return $url.'?token='.$token;
}
return $url.'?tokenid='.$token;
return $url.'?token='.$token;
}
/**

View File

@ -25,7 +25,6 @@ class Connection
];
const versions = [
AtolOnlineApi::API_VERSION_V3,
AtolOnlineApi::API_VERSION_V4,
];
@ -45,7 +44,7 @@ class Connection
public $sno;
/** @var string */
public $version = AtolOnlineApi::API_VERSION_V3;
public $version = AtolOnlineApi::API_VERSION_V4;
/** @var bool */
public $testMode = false;
@ -53,7 +52,7 @@ class Connection
/**
* @return bool
*/
public function isTestMode()
public function isTestMode(): bool
{
return $this->testMode;
}
@ -61,7 +60,7 @@ class Connection
/**
* @param bool $testMode
*/
public function setTestMode(bool $testMode)
public function setTestMode(bool $testMode): void
{
$this->testMode = $testMode;
}
@ -85,7 +84,7 @@ class Connection
/**
* @param ClassMetadata $metadata
*/
public static function loadValidatorMetadata(ClassMetadata $metadata)
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
$metadata->addPropertyConstraint('login', new Assert\NotBlank());
$metadata->addPropertyConstraint('pass', new Assert\NotBlank());
@ -111,14 +110,6 @@ class Connection
return $this->version;
}
/**
* @return bool
*/
public function isVersion3()
{
return $this->getVersion() === AtolOnlineApi::API_VERSION_V3;
}
/**
* @return bool
*/

View File

@ -1,129 +0,0 @@
<?php
namespace AtolOnlineClient\Request\V3;
use JMS\Serializer\Annotation as Serializer;
class PaymentReceiptRequest
{
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("timestamp")
* @Serializer\Type("string")
*/
private $timestamp;
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("external_id")
* @Serializer\Type("string")
*/
private $externalId;
/**
* @var ServiceRequest
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("service")
* @Serializer\Type("AtolOnlineClient\Request\V3\ServiceRequest")
*/
private $service;
/**
* @var ReceiptRequest
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("receipt")
* @Serializer\Type("AtolOnlineClient\Request\V3\ReceiptRequest")
*/
private $receipt;
public function __construct()
{
$this->timestamp = (new \DateTime())->format('d.m.Y H:i:s');
}
/**
* @return string
*/
public function getTimestamp()
{
return $this->timestamp;
}
/**
* @param string $timestamp
*
* @return $this
*/
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;
return $this;
}
/**
* @return string
*/
public function getExternalId()
{
return $this->externalId;
}
/**
* @param string $externalId
*
* @return $this
*/
public function setExternalId($externalId)
{
$this->externalId = $externalId;
return $this;
}
/**
* @return \AtolOnlineClient\Request\V3\ServiceRequest
*/
public function getService()
{
return $this->service;
}
/**
* @param \AtolOnlineClient\Request\V3\ServiceRequest $service
*
* @return $this
*/
public function setService($service)
{
$this->service = $service;
return $this;
}
/**
* @return ReceiptRequest
*/
public function getReceipt()
{
return $this->receipt;
}
/**
* @param ReceiptRequest $receipt
*
* @return $this
*/
public function setReceipt($receipt)
{
$this->receipt = $receipt;
return $this;
}
}

View File

@ -1,98 +0,0 @@
<?php
namespace AtolOnlineClient\Request\V3;
use JMS\Serializer\Annotation as Serializer;
class ReceiptAttributesRequest
{
/**
* @var string
*
* "enum": [
* "osn",
* "usn_income",
* "usn_income_outcome",
* "envd",
* "esn",
* "patent"
* ]
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("sno")
* @Serializer\Type("string")
*/
private $sno;
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("email")
* @Serializer\Type("string")
*/
private $email;
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("phone")
* @Serializer\Type("string")
*/
private $phone;
/**
* ReceiptAttributesRequest constructor.
* @param string $email
* @param string $phone
*/
public function __construct($email, $phone)
{
$this->email = $email;
if ($email == null) {
$this->email = '';
}
$this->phone = $phone;
if ($phone == null) {
$this->phone = '';
}
}
/**
* @return string
*/
public function getSno()
{
return $this->sno;
}
/**
* @param string $sno
*
* @return $this
*/
public function setSno($sno)
{
$this->sno = $sno;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @return string
*/
public function getPhone()
{
return $this->phone;
}
}

View File

@ -1,163 +0,0 @@
<?php
namespace AtolOnlineClient\Request\V3;
use JMS\Serializer\Annotation as Serializer;
class ReceiptItemRequest
{
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("name")
* @Serializer\Type("string")
*/
private $name;
/**
* @var float
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("price")
* @Serializer\Type("float")
*/
private $price;
/**
* @var integer
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("quantity")
* @Serializer\Type("integer")
*/
private $quantity;
/**
* @var float
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("sum")
* @Serializer\Type("float")
*/
private $sum;
/**
* @var string
*
* "enum": [
* "none",
* "vat0",
* "vat10",
* "vat18",
* "vat110",
* "vat118"
* ]
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("tax")
* @Serializer\Type("string")
*/
private $tax;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return $this
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* @param float $price
*
* @return $this
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* @return integer
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param int $quantity
*
* @return $this
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* @return float
*/
public function getSum()
{
return $this->sum;
}
/**
* @param float $sum
*
* @return $this
*/
public function setSum($sum)
{
$this->sum = $sum;
return $this;
}
/**
* @return string
*/
public function getTax()
{
return $this->tax;
}
/**
* @param string $tax
*
* @return $this
*/
public function setTax($tax)
{
$this->tax = $tax;
return $this;
}
}

View File

@ -1,59 +0,0 @@
<?php
namespace AtolOnlineClient\Request\V3;
use JMS\Serializer\Annotation as Serializer;
class ReceiptPaymentRequest
{
const TYPE_ELECTRON = 1;
const TYPE_PREPAY = 2;
const TYPE_CREDIT = 3;
const TYPE_OTHER = 4;
/**
* @var int
* "enum": 0..9
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("type")
* @Serializer\Type("integer")
*/
private $type;
/**
* @var float
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("sum")
* @Serializer\Type("float")
*/
private $sum;
/**
* @param int $type
* @param float $sum
*/
public function __construct($type, $sum)
{
$this->type = $type;
$this->sum = $sum;
}
/**
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* @return float
*/
public function getSum()
{
return $this->sum;
}
}

View File

@ -1,127 +0,0 @@
<?php
namespace AtolOnlineClient\Request\V3;
use JMS\Serializer\Annotation as Serializer;
class ReceiptRequest
{
/**
* @var ReceiptAttributesRequest
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("attributes")
* @Serializer\Type("AtolOnlineClient\Request\V3\ReceiptAttributesRequest")
*/
private $attributes;
/**
* @var ReceiptItemRequest[]
* "minItems": 1, "maxItems": 100,
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("items")
* @Serializer\Type("array<AtolOnlineClient\Request\V3\ReceiptItemRequest>")
*/
private $items;
/**
* @var float
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("total")
* @Serializer\Type("float")
*/
private $total;
/**
* @var \AtolOnlineClient\Request\V3\ReceiptPaymentRequest[]
* "minItems": 1, "maxItems": 10,
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("payments")
* @Serializer\Type("array<AtolOnlineClient\Request\V3\ReceiptPaymentRequest>")
*/
private $payments;
/**
* @return ReceiptAttributesRequest
*/
public function getAttributes()
{
return $this->attributes;
}
/**
* @param ReceiptAttributesRequest $attributes
*
* @return $this
*/
public function setAttributes($attributes)
{
$this->attributes = $attributes;
return $this;
}
/**
* @return ReceiptItemRequest[]
*/
public function getItems()
{
return $this->items;
}
/**
* @param ReceiptItemRequest[] $items
*
* @return $this
*/
public function setItems($items)
{
$this->items = $items;
return $this;
}
/**
* @return float
*/
public function getTotal()
{
return $this->total;
}
/**
* @param float $total
*
* @return $this
*/
public function setTotal($total)
{
$this->total = $total;
return $this;
}
/**
* @return \AtolOnlineClient\Request\V3\ReceiptPaymentRequest[]
*/
public function getPayments()
{
return $this->payments;
}
/**
* @param \AtolOnlineClient\Request\V3\ReceiptPaymentRequest[] $payments
*
* @return $this
*/
public function setPayments($payments)
{
$this->payments = $payments;
return $this;
}
}

View File

@ -1,106 +0,0 @@
<?php
namespace AtolOnlineClient\Request\V3;
use JMS\Serializer\Annotation as Serializer;
class ServiceRequest
{
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("inn")
* @Serializer\Type("string")
*/
private $inn;
/**
* @var string
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("callback_url")
* @Serializer\Type("string")
*/
private $callbackUrl;
/**
* @var string
* required
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("payment_address")
* @Serializer\Type("string")
*/
private $paymentAddress;
/**
* Service constructor.
* @param string $inn
* @param string $paymentAddress
*/
public function __construct($inn, $paymentAddress)
{
$this->inn = $inn;
$this->paymentAddress = $paymentAddress;
}
/**
* @return string
*/
public function getCallbackUrl()
{
return $this->callbackUrl;
}
/**
* @param string $callbackUrl
*
* @return $this
*/
public function setCallbackUrl($callbackUrl)
{
$this->callbackUrl = $callbackUrl;
return $this;
}
/**
* @return string
*/
public function getInn()
{
return $this->inn;
}
/**
* @param string $inn
*
* @return $this
*/
public function setInn($inn)
{
$this->inn = $inn;
return $this;
}
/**
* @return string
*/
public function getPaymentAddress()
{
return $this->paymentAddress;
}
/**
* @param string $paymentAddress
*
* @return $this
*/
public function setPaymentAddress($paymentAddress)
{
$this->paymentAddress = $paymentAddress;
return $this;
}
}

View File

@ -7,12 +7,12 @@ use JMS\Serializer\Annotation as Serializer;
/**
* В запросе обязательно должно быть заполнено хотя бы одно из полей: email или phone.
* Если заполнены оба поля, ОФД отправит электронный чек только на email.
* @Serializer\AccessType("public_method")
*/
class ClientReceiptRequest
{
/**
* @var string
* required
* @var string|null
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("email")
* @Serializer\Type("string")
@ -20,8 +20,7 @@ class ClientReceiptRequest
private $email;
/**
* @var string
* required
* @var string|null
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("phone")
* @Serializer\Type("string")
@ -30,7 +29,7 @@ class ClientReceiptRequest
/**
* @var string
* @var string|null
*
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("name")
@ -39,7 +38,7 @@ class ClientReceiptRequest
private $name;
/**
* @var string
* @var string|null
*
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("inn")
@ -47,56 +46,72 @@ class ClientReceiptRequest
*/
private $inn;
public function __construct($email, $phone)
public function __construct(string $email = null, string $phone = null)
{
$this->email = $email;
$this->phone = $phone;
}
/**
* @return string
* @return string|null
*/
public function getEmail(): string
public function getEmail(): ?string
{
return $this->email;
}
/**
* @return string
* @param string|null $email
*/
public function getPhone(): string
public function setEmail(?string $email): void
{
$this->email = $email;
}
/**
* @return string|null
*/
public function getPhone(): ?string
{
return $this->phone;
}
/**
* @return string
* @param string|null $phone
*/
public function getName(): string
public function setPhone(?string $phone): void
{
$this->phone = $phone;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @param string|null $name
*/
public function setName(string $name): void
public function setName(?string $name): void
{
$this->name = $name;
}
/**
* @return string
* @return string|null
*/
public function getInn(): string
public function getInn(): ?string
{
return $this->inn;
}
/**
* @param string $inn
* @param string|null $inn
*/
public function setInn(string $inn): void
public function setInn(?string $inn): void
{
$this->inn = $inn;
}

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class CompanyReceiptRequest
{
/**
@ -16,7 +19,7 @@ class CompanyReceiptRequest
private $email;
/**
* @var string
* @var string|null
* Поле необязательно, если у организации один тип налогообложения
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("sno")
@ -59,17 +62,17 @@ class CompanyReceiptRequest
}
/**
* @return string
* @return string|null
*/
public function getSno(): string
public function getSno(): ?string
{
return $this->sno;
}
/**
* @param string $sno
* @param string|null $sno
*/
public function setSno(string $sno): void
public function setSno(?string $sno): void
{
$this->sno = $sno;
}

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class PaymentReceiptRequest
{
/**
@ -44,7 +47,6 @@ class PaymentReceiptRequest
private $service;
public function __construct()
{
$this->timestamp = (new \DateTime())->format('d.m.Y H:i:s');
@ -90,6 +92,14 @@ class PaymentReceiptRequest
return $this->timestamp;
}
/**
* @param string $timestamp
*/
public function setTimestamp(string $timestamp): void
{
$this->timestamp = $timestamp;
}
/**
* @return ServiceRequest
*/

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class ReceiptItemRequest
{
@ -68,7 +71,7 @@ class ReceiptItemRequest
private $sum;
/**
* @var string
* @var string|null
*
* required
* @Serializer\Groups({"set", "get"})
@ -88,7 +91,7 @@ class ReceiptItemRequest
* «partial_payment» частичный расчет и кредит. Частичная оплата предмета расчета в момент его передачи с последующей оплатой в кредит.
* «credit» передача в кредит. Передача предмета расчета без его оплаты в момент его передачи с последующей оплатой в кредит.
* «credit_payment» оплата кредита. Оплата предмета расчета после его передачи с оплатой в кредит (оплата кредита).
* @var string
* @var string|null
*
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("payment_method")
@ -113,7 +116,7 @@ class ReceiptItemRequest
* «composite» составной предмет расчета. О предмете расчета, состоящем из предметов, каждому из которых может быть присвоено значение выше перечисленных признаков.
* «another» иной предмет расчета. О предмете расчета, не относящемуся к выше перечисленным предметам расчета
*
* @var string
* @var string|null
*
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("payment_object")
@ -132,7 +135,7 @@ class ReceiptItemRequest
private $vat;
/**
* @var string
* @var string|null
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("nomenclature_code")
* @Serializer\Type("string")
@ -204,49 +207,49 @@ class ReceiptItemRequest
}
/**
* @return string
* @return string|null
*/
public function getMeasurementUnit(): string
public function getMeasurementUnit(): ?string
{
return $this->measurementUnit;
}
/**
* @param string $measurementUnit
* @param string|null $measurementUnit
*/
public function setMeasurementUnit(string $measurementUnit): void
public function setMeasurementUnit(?string $measurementUnit): void
{
$this->measurementUnit = $measurementUnit;
}
/**
* @return string
* @return string|null
*/
public function getPaymentMethod(): string
public function getPaymentMethod(): ?string
{
return $this->paymentMethod;
}
/**
* @param string $paymentMethod
* @param string|null $paymentMethod
*/
public function setPaymentMethod(string $paymentMethod): void
public function setPaymentMethod(?string $paymentMethod): void
{
$this->paymentMethod = $paymentMethod;
}
/**
* @return string
* @return string|null
*/
public function getPaymentObject(): string
public function getPaymentObject(): ?string
{
return $this->paymentObject;
}
/**
* @param string $paymentObject
* @param string|null $paymentObject
*/
public function setPaymentObject(string $paymentObject): void
public function setPaymentObject(?string $paymentObject): void
{
$this->paymentObject = $paymentObject;
}
@ -268,17 +271,17 @@ class ReceiptItemRequest
}
/**
* @return string
* @return string|null
*/
public function getNomenclatureCode(): string
public function getNomenclatureCode(): ?string
{
return $this->nomenclatureCode;
}
/**
* @param string $nomenclatureCode
* @param string|null $nomenclatureCode
*/
public function setNomenclatureCode(string $nomenclatureCode): void
public function setNomenclatureCode(?string $nomenclatureCode): void
{
$this->nomenclatureCode = $nomenclatureCode;
}

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class ReceiptPaymentRequest
{
const TYPE_ELECTRON = 1;
@ -49,6 +52,14 @@ class ReceiptPaymentRequest
return $this->type;
}
/**
* @param int $type
*/
public function setType(int $type): void
{
$this->type = $type;
}
/**
* @return float
*/
@ -56,4 +67,12 @@ class ReceiptPaymentRequest
{
return $this->sum;
}
/**
* @param float $sum
*/
public function setSum(float $sum): void
{
$this->sum = $sum;
}
}

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class ReceiptRequest
{

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class ServiceRequest
{

View File

@ -4,6 +4,9 @@ namespace AtolOnlineClient\Request\V4;
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\AccessType("public_method")
*/
class VatReceiptRequest
{
/**
@ -12,9 +15,9 @@ class VatReceiptRequest
* "none",
* "vat0",
* "vat10",
* "vat18",
* "vat20",
* "vat110",
* "vat118"
* "vat120"
* ]
*
* @var string
@ -26,8 +29,8 @@ class VatReceiptRequest
private $type;
/**
* @var float
* required
* @var float|null
*
* @Serializer\Groups({"set", "get"})
* @Serializer\SerializedName("sum")
* @Serializer\Type("float")
@ -53,6 +56,14 @@ class VatReceiptRequest
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
/**
* @return float
*/
@ -60,4 +71,12 @@ class VatReceiptRequest
{
return $this->sum;
}
/**
* @param float $sum
*/
public function setSum(float $sum): void
{
$this->sum = $sum;
}
}

View File

@ -4,10 +4,8 @@ namespace AtolOnlineClient\AtolOnlineClient;
use AtolOnlineClient\AtolOnline;
use AtolOnlineClient\AtolOnlineApi;
use AtolOnlineClient\AtolOnlineClient\Traits\PaymentReceiptRequestTrait;
use AtolOnlineClient\Configuration\Connection;
use AtolOnlineClient\Request\V4\PaymentReceiptRequest;
use AtolOnlineClient\Request\V4\ReceiptRequest;
use AtolOnlineClient\Request\V4\ServiceRequest;
use Doctrine\Common\Cache\ArrayCache;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
@ -26,6 +24,8 @@ use Psr\Log\Test\TestLogger;
*/
class AtolOnlineApiTest extends TestCase
{
use PaymentReceiptRequestTrait;
/**
* @return void
* @covers \AtolOnlineClient\AtolOnlineApi::__construct
@ -40,8 +40,6 @@ class AtolOnlineApiTest extends TestCase
$this->assertInstanceOf(AtolOnlineApi::class, $api);
$this->assertSame(AtolOnlineApi::API_VERSION_V3, $api->getVersion());
$api->setVersion(AtolOnlineApi::API_VERSION_V4);
$this->assertSame(AtolOnlineApi::API_VERSION_V4, $api->getVersion());
@ -63,7 +61,7 @@ class AtolOnlineApiTest extends TestCase
new Response(200, [], $this->getReportSuccessReportV4()),
];
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentRecepientRequest());
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentReceiptRequest());
$response = $this->getApi($responses)->sell($request);
@ -81,7 +79,7 @@ class AtolOnlineApiTest extends TestCase
new Response(200, [], $this->getReportSuccessReportV4()),
];
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentRecepientRequest());
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentReceiptRequest());
$response = $this->getApi($responses)->sellRefund($request);
@ -208,34 +206,6 @@ class AtolOnlineApiTest extends TestCase
$this->assertSame('fj45u923j59ju42395iu9423i59243u0', $this->callMethod($api, 'getToken'));
}
/**
* @return void
* @covers \AtolOnlineClient\AtolOnlineApi::getToken
*/
public function testGetTokenSuccessResponseV3(): void
{
$api = $this->getApi([new Response(200, [], $this->getTokenSuccessResponseV3())])->setVersion(AtolOnlineApi::API_VERSION_V3);
$this->assertSame('fj45u923j59ju42395iu9423i59243u0', $this->callMethod($api, 'getToken'));
}
/**
* @return void
* @covers \AtolOnlineClient\AtolOnlineApi::getToken
*/
public function testGetTokenSuccessResponseV3WithCache(): void
{
$cache = new ArrayCache();
$api = $this->getApi([new Response(200, [], $this->getTokenSuccessResponseV3())])->setVersion(AtolOnlineApi::API_VERSION_V3);
$api->setCache($cache);
$this->assertSame('fj45u923j59ju42395iu9423i59243u0', $this->callMethod($api, 'getToken'));
$this->assertTrue($cache->contains($this->callMethod($api, 'getTokenCacheKey')));
$this->assertSame('fj45u923j59ju42395iu9423i59243u0', $this->callMethod($api, 'getToken'));
}
/**
* @return void
* @covers \AtolOnlineClient\AtolOnlineApi::buildUrl
@ -245,7 +215,6 @@ class AtolOnlineApiTest extends TestCase
$args = ['operation' => 'test'];
$this->assertSame('https://online.atol.ru/possystem/v4/group/test', $this->callMethod($this->getApi(), 'buildUrl', $args));
$this->assertSame('https://online.atol.ru/possystem/v3/group/test', $this->callMethod($this->getApi()->setVersion(AtolOnlineApi::API_VERSION_V3), 'buildUrl', $args));
}
/**
@ -257,7 +226,6 @@ class AtolOnlineApiTest extends TestCase
$args = ['operation' => 'test', 'token' => 'test'];
$this->assertSame('https://online.atol.ru/possystem/v4/group/test?token=test', $this->callMethod($this->getApi(), 'buildUrl', $args));
$this->assertSame('https://online.atol.ru/possystem/v3/group/test?tokenid=test', $this->callMethod($this->getApi()->setVersion(AtolOnlineApi::API_VERSION_V3), 'buildUrl', $args));
}
/**
@ -271,7 +239,7 @@ class AtolOnlineApiTest extends TestCase
new Response(200, [], $this->getTokenSuccessResponseV4())
];
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentRecepientRequest());
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentReceiptRequest());
$response = $this->callMethod($this->getApi($responses), 'sendOperationRequest', [
'operation' => 'sell',
@ -294,7 +262,7 @@ class AtolOnlineApiTest extends TestCase
new Response(200, [], $this->getTokenSuccessResponseV4()),
];
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentRecepientRequest());
$request = (new AtolOnline())->serializeOperationRequest($this->getPaymentReceiptRequest());
$api = $this->getApi($responses);
$api->setCache(new ArrayCache());
@ -338,7 +306,6 @@ class AtolOnlineApiTest extends TestCase
public function testGetTokenCacheKey(): void
{
$this->assertSame('crm_fiscal_atol_online_token_68526766e6751745b52ae70b7bd3c6fe_v4', $this->callMethod($this->getApi(), 'getTokenCacheKey'));
$this->assertSame('crm_fiscal_atol_online_token_68526766e6751745b52ae70b7bd3c6fe_v3', $this->callMethod($this->getApi()->setVersion(AtolOnlineApi::API_VERSION_V3), 'getTokenCacheKey'));
}
/**
@ -410,17 +377,6 @@ class AtolOnlineApiTest extends TestCase
return $property->getValue($object);
}
/**
* @return false|string
*/
private function getTokenSuccessResponseV3()
{
return json_encode([
'token' => 'fj45u923j59ju42395iu9423i59243u0',
'code' => 1,
]);
}
/**
* @return false|string
*/
@ -456,24 +412,4 @@ class AtolOnlineApiTest extends TestCase
{
return file_get_contents(__DIR__.'/../fixtures/success_response_v4_3.json');
}
/**
* @return PaymentReceiptRequest
*/
private function getPaymentRecepientRequest(): PaymentReceiptRequest
{
$service = new ServiceRequest();
$service->setCallbackUrl('test.local');
$receipt = new ReceiptRequest();
$receipt->setTotal('100');
/** @var PaymentReceiptRequest $request */
$request = new PaymentReceiptRequest();
$request->setExternalId('test');
$request->setService($service);
$request->setReceipt($receipt);
return $request;
}
}

View File

@ -3,12 +3,10 @@
namespace AtolOnlineClient\Tests;
use AtolOnlineClient\AtolOnline;
use AtolOnlineClient\AtolOnlineClient\Traits\PaymentReceiptRequestTrait;
use AtolOnlineClient\Configuration\Connection;
use AtolOnlineClient\ConfigurationInterface;
use AtolOnlineClient\Exception\InvalidResponseException;
use AtolOnlineClient\Request\V4\PaymentReceiptRequest;
use AtolOnlineClient\Request\V4\ReceiptRequest;
use AtolOnlineClient\Request\V4\ServiceRequest;
use GuzzleHttp\Client;
use JMS\Serializer\Exception\RuntimeException;
use JMS\Serializer\SerializerInterface;
@ -16,6 +14,8 @@ use PHPUnit\Framework\TestCase;
class AtolOnlineTest extends TestCase
{
use PaymentReceiptRequestTrait;
/**
* @var AtolOnline
*/
@ -127,6 +127,7 @@ class AtolOnlineTest extends TestCase
* @param string|null $message
* @param string $html
* @covers \AtolOnlineClient\AtolOnline::createInvalidResponseException
* @covers \AtolOnlineClient\Exception\InvalidResponseException
* @dataProvider dataInvalidResponse
*/
public function testCreateInvalidResponseException(?int $code, ?string $message, string $html): void
@ -144,30 +145,24 @@ class AtolOnlineTest extends TestCase
/**
* @covers \AtolOnlineClient\AtolOnline::serializeOperationRequest
* @covers \AtolOnlineClient\Request\V4\ClientReceiptRequest
* @covers \AtolOnlineClient\Request\V4\CompanyReceiptRequest
* @covers \AtolOnlineClient\Request\V4\PaymentReceiptRequest
* @covers \AtolOnlineClient\Request\V4\ReceiptItemRequest
* @covers \AtolOnlineClient\Request\V4\ReceiptPaymentRequest
* @covers \AtolOnlineClient\Request\V4\ReceiptRequest
* @covers \AtolOnlineClient\Request\V4\ServiceRequest
* @covers \AtolOnlineClient\Request\V4\VatReceiptRequest
*/
public function testSerializeOperationRequest(): void
{
$service = new ServiceRequest();
$service->setCallbackUrl('test.local');
$request = $this->getPaymentReceiptRequest();
$request->setTimestamp('17.07.2019 10:14:22');
$receipt = new ReceiptRequest();
$receipt->setTotal('100');
/** @var PaymentReceiptRequest $paymentReceipt */
$paymentReceipt = new PaymentReceiptRequest();
$reflection = new \ReflectionClass($paymentReceipt);
$property = $reflection->getProperty('timestamp');
$property->setAccessible(true);
$property->setValue($paymentReceipt, 1);
$paymentReceipt->setExternalId('test');
$paymentReceipt->setService($service);
$paymentReceipt->setReceipt($receipt);
$request = $this->atol->serializeOperationRequest($paymentReceipt);
$this->assertEquals('{"external_id":"test","receipt":{"total":100},"timestamp":"1","service":{"callback_url":"test.local"}}', $request);
$this->assertEquals(
'{"external_id":"test","receipt":{"client":{"email":"test@test.local"},"company":{"email":"test@test.local","inn":"11111111","payment_address":"address"},"items":[{"name":"test item","price":100,"quantity":1,"sum":100,"measurement_unit":"kg","payment_method":"advance","payment_object":"agent_commission","vat":{"type":"vat20","sum":20},"nomenclature_code":"00"}],"payments":[{"type":0,"sum":100}],"vats":[{"type":"vat20","sum":20}],"total":100},"timestamp":"17.07.2019 10:14:22","service":{"callback_url":"test.local"}}',
$this->atol->serializeOperationRequest($request)
);
}
/**
@ -214,7 +209,6 @@ class AtolOnlineTest extends TestCase
public function dataErrorResponse(): array
{
return [
['error_response_v3.json'],
['error_response_v4.json']
];
}

View File

@ -52,13 +52,9 @@ class ConnectionTest extends TestCase
* @return void
* @covers \AtolOnlineClient\Configuration\Connection::getVersion
* @covers \AtolOnlineClient\Configuration\Connection::isVersion4
* @covers \AtolOnlineClient\Configuration\Connection::isVersion3
*/
public function testVersion(): void
{
$this->assertEquals(AtolOnlineApi::API_VERSION_V3, $this->connection->getVersion());
$this->assertTrue($this->connection->isVersion3());
$this->connection->version = AtolOnlineApi::API_VERSION_V4;
$this->assertTrue($this->connection->isVersion4());
}

View File

@ -0,0 +1,102 @@
<?php
namespace AtolOnlineClient\AtolOnlineClient\Response;
use AtolOnlineClient\Request\V4\PaymentReceiptRequest;
use JMS\Serializer\SerializerBuilder;
use PHPUnit\Framework\TestCase;
/**
*/
class RequestTest extends TestCase
{
/**
* @return void
* @covers \AtolOnlineClient\Request\V4\ClientReceiptRequest
* @covers \AtolOnlineClient\Request\V4\CompanyReceiptRequest
* @covers \AtolOnlineClient\Request\V4\PaymentReceiptRequest
* @covers \AtolOnlineClient\Request\V4\ReceiptItemRequest
* @covers \AtolOnlineClient\Request\V4\ReceiptPaymentRequest
* @covers \AtolOnlineClient\Request\V4\ReceiptRequest
* @covers \AtolOnlineClient\Request\V4\ServiceRequest
* @covers \AtolOnlineClient\Request\V4\VatReceiptRequest
*/
public function testRequest(): void
{
$serializer = SerializerBuilder::create()->build();
$request = '{
"external_id": "17052917561851307",
"receipt": {
"client": {
"name": "name",
"email": "kkt@kkt.ru",
"phone": "88002000600",
"inn": "111111111"
},
"company": {
"email": "chek@romashka.ru",
"sno": "osn",
"inn": "1234567891",
"payment_address": "http://magazin.ru/"
},
"items": [
{
"name": "колбаса Клинский Брауншвейгская с/к в/с ",
"price": 1000,
"quantity": 0.3,
"sum": 300,
"measurement_unit": "кг",
"payment_method": "full_payment",
"payment_object": "commodity",
"vat": {
"type": "vat18"
}
},
{
"name": "яйцоОкскоекуриноеС0 белое",
"price": 100,
"quantity": 1,
"sum": 100,
"measurement_unit": "Упаковка10 шт.",
"payment_method": "full_payment",
"payment_object": "commodity",
"vat": {
"type": "vat10"
}
}
],
"payments": [
{
"type": 1,
"sum": 400
}
],
"vats": [
{
"type": "vat18",
"sum": 45.76
},
{
"type": "vat10",
"sum": 9.09
}
],
"total": 400
},
"service": {
"callback_url": "http://testtest"
},
"timestamp": "01.02.1713:45:00"
}';
/** @var PaymentReceiptRequest $request */
$request = $serializer->deserialize(
$request,
PaymentReceiptRequest::class,
'json'
);
$this->assertSame('17052917561851307', $request->getExternalId());
}
}

View File

@ -47,6 +47,7 @@ class ResponseTest extends TestCase
"external_id": "TRF10601_1",
"callback_url": ""
}';
/** @var OperationResponse $response */
$response = $serializer->deserialize(
$response,
OperationResponse::class,
@ -58,6 +59,6 @@ class ResponseTest extends TestCase
'json'
);
$this->assertTrue(true);
$this->assertSame('4355', $response->getUuid());
}
}

View File

@ -0,0 +1,58 @@
<?php
namespace AtolOnlineClient\AtolOnlineClient\Traits;
use AtolOnlineClient\Request\V4\ClientReceiptRequest;
use AtolOnlineClient\Request\V4\CompanyReceiptRequest;
use AtolOnlineClient\Request\V4\PaymentReceiptRequest;
use AtolOnlineClient\Request\V4\ReceiptItemRequest;
use AtolOnlineClient\Request\V4\ReceiptPaymentRequest;
use AtolOnlineClient\Request\V4\ReceiptRequest;
use AtolOnlineClient\Request\V4\ServiceRequest;
use AtolOnlineClient\Request\V4\VatReceiptRequest;
trait PaymentReceiptRequestTrait
{
/**
* @return PaymentReceiptRequest
*/
protected function getPaymentReceiptRequest(): PaymentReceiptRequest
{
$service = new ServiceRequest();
$service->setCallbackUrl('test.local');
$client = new ClientReceiptRequest('test@test.local');
$company = new CompanyReceiptRequest();
$company->setEmail('test@test.local');
$company->setInn('11111111');
$company->setPaymentAddress('address');
$item = new ReceiptItemRequest();
$item->setName('test item');
$item->setPrice(100);
$item->setQuantity(1);
$item->setSum(100);
$item->setMeasurementUnit('kg');
$item->setPaymentMethod(ReceiptItemRequest::PAYMENT_METHOD_ADVANCE);
$item->setPaymentObject(ReceiptItemRequest::PAYMENT_OBJECT_AGENT_COMMISSION);
$item->setVat(new VatReceiptRequest('vat20', 20));
$item->setNomenclatureCode('00');
$receipt = new ReceiptRequest();
$receipt->setTotal('100');
$receipt->setClient($client);
$receipt->setCompany($company);
$receipt->setItems([$item]);
$receipt->setPayments([new ReceiptPaymentRequest(0, 100)]);
$receipt->setVats([new VatReceiptRequest('vat20', 20)]);
/** @var PaymentReceiptRequest $request */
$request = new PaymentReceiptRequest();
$request->setExternalId('test');
$request->setService($service);
$request->setReceipt($receipt);
return $request;
}
}