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

клиент для атол онлайн

This commit is contained in:
Alexey Chelnakov 2018-06-20 11:27:16 +03:00
parent 246da86c1b
commit 665b56f58a
11 changed files with 292 additions and 634 deletions

View File

@ -12,7 +12,7 @@
"require": { "require": {
"php": ">=7.1", "php": ">=7.1",
"ext-curl": "*", "ext-curl": "*",
"guzzlehttp/guzzle": "~6.0", "guzzle/guzzle": "~3.7",
"jms/serializer-bundle": "~0.12", "jms/serializer-bundle": "~0.12",
"symfony/validator": "2.8.*" "symfony/validator": "2.8.*"
}, },

263
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4a04eaf2c87d2a5efd3a17846d459114", "content-hash": "ff17ded3eeddcaca1b29f17e298ed1d7",
"packages": [ "packages": [
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -203,44 +203,70 @@
"time": "2014-09-09T13:34:57+00:00" "time": "2014-09-09T13:34:57+00:00"
}, },
{ {
"name": "guzzlehttp/guzzle", "name": "guzzle/guzzle",
"version": "6.3.3", "version": "v3.9.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/guzzle/guzzle.git", "url": "https://github.com/guzzle/guzzle3.git",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"guzzlehttp/promises": "^1.0", "ext-curl": "*",
"guzzlehttp/psr7": "^1.4", "php": ">=5.3.3",
"php": ">=5.5" "symfony/event-dispatcher": "~2.1"
},
"replace": {
"guzzle/batch": "self.version",
"guzzle/cache": "self.version",
"guzzle/common": "self.version",
"guzzle/http": "self.version",
"guzzle/inflection": "self.version",
"guzzle/iterator": "self.version",
"guzzle/log": "self.version",
"guzzle/parser": "self.version",
"guzzle/plugin": "self.version",
"guzzle/plugin-async": "self.version",
"guzzle/plugin-backoff": "self.version",
"guzzle/plugin-cache": "self.version",
"guzzle/plugin-cookie": "self.version",
"guzzle/plugin-curlauth": "self.version",
"guzzle/plugin-error-response": "self.version",
"guzzle/plugin-history": "self.version",
"guzzle/plugin-log": "self.version",
"guzzle/plugin-md5": "self.version",
"guzzle/plugin-mock": "self.version",
"guzzle/plugin-oauth": "self.version",
"guzzle/service": "self.version",
"guzzle/stream": "self.version"
}, },
"require-dev": { "require-dev": {
"ext-curl": "*", "doctrine/cache": "~1.3",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "monolog/monolog": "~1.0",
"psr/log": "^1.0" "phpunit/phpunit": "3.7.*",
"psr/log": "~1.0",
"symfony/class-loader": "~2.1",
"zendframework/zend-cache": "2.*,<2.3",
"zendframework/zend-log": "2.*,<2.3"
}, },
"suggest": { "suggest": {
"psr/log": "Required for using the Log middleware" "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "6.3-dev" "dev-master": "3.9-dev"
} }
}, },
"autoload": { "autoload": {
"files": [ "psr-0": {
"src/functions_include.php" "Guzzle": "src/",
], "Guzzle\\Tests": "tests/"
"psr-4": {
"GuzzleHttp\\": "src/"
} }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@ -252,9 +278,13 @@
"name": "Michael Dowling", "name": "Michael Dowling",
"email": "mtdowling@gmail.com", "email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling" "homepage": "https://github.com/mtdowling"
},
{
"name": "Guzzle Community",
"homepage": "https://github.com/guzzle/guzzle/contributors"
} }
], ],
"description": "Guzzle is a PHP HTTP client library", "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
"homepage": "http://guzzlephp.org/", "homepage": "http://guzzlephp.org/",
"keywords": [ "keywords": [
"client", "client",
@ -265,123 +295,8 @@
"rest", "rest",
"web service" "web service"
], ],
"time": "2018-04-22T15:46:56+00:00" "abandoned": "guzzlehttp/guzzle",
}, "time": "2015-03-18T18:23:50+00:00"
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
}, },
{ {
"name": "ircmaxell/password-compat", "name": "ircmaxell/password-compat",
@ -798,56 +713,6 @@
], ],
"time": "2015-07-25T16:39:46+00:00" "time": "2015-07-25T16:39:46+00:00"
}, },
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{ {
"name": "psr/log", "name": "psr/log",
"version": "1.0.2", "version": "1.0.2",
@ -1185,27 +1050,27 @@
}, },
{ {
"name": "symfony/event-dispatcher", "name": "symfony/event-dispatcher",
"version": "v3.0.9", "version": "v2.8.41",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/event-dispatcher.git", "url": "https://github.com/symfony/event-dispatcher.git",
"reference": "54da3ff63dec3c9c0e32ec3f95a7d94ef64baa00" "reference": "9b69aad7d4c086dc94ebade2d5eb9145da5dac8c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/54da3ff63dec3c9c0e32ec3f95a7d94ef64baa00", "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9b69aad7d4c086dc94ebade2d5eb9145da5dac8c",
"reference": "54da3ff63dec3c9c0e32ec3f95a7d94ef64baa00", "reference": "9b69aad7d4c086dc94ebade2d5eb9145da5dac8c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.5.9" "php": ">=5.3.9"
}, },
"require-dev": { "require-dev": {
"psr/log": "~1.0", "psr/log": "~1.0",
"symfony/config": "~2.8|~3.0", "symfony/config": "^2.0.5|~3.0.0",
"symfony/dependency-injection": "~2.8|~3.0", "symfony/dependency-injection": "~2.6|~3.0.0",
"symfony/expression-language": "~2.8|~3.0", "symfony/expression-language": "~2.6|~3.0.0",
"symfony/stopwatch": "~2.8|~3.0" "symfony/stopwatch": "~2.3|~3.0.0"
}, },
"suggest": { "suggest": {
"symfony/dependency-injection": "", "symfony/dependency-injection": "",
@ -1214,7 +1079,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.0-dev" "dev-master": "2.8-dev"
} }
}, },
"autoload": { "autoload": {
@ -1241,7 +1106,7 @@
], ],
"description": "Symfony EventDispatcher Component", "description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2016-07-19T10:44:15+00:00" "time": "2018-04-06T07:35:03+00:00"
}, },
{ {
"name": "symfony/filesystem", "name": "symfony/filesystem",

24
phpunit.xml.dist Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "true"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "vendor/autoload.php" >
<testsuites>
<testsuite name="php">
<directory>./tests/*/Tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -4,7 +4,9 @@ namespace AtolOnlineClient;
use AtolOnlineClient\Configuration\Connection; use AtolOnlineClient\Configuration\Connection;
use AtolOnlineClient\Response\OperationResponse; use AtolOnlineClient\Response\OperationResponse;
use Guzzle\Http\Client;
use JMS\Serializer\DeserializationContext; use JMS\Serializer\DeserializationContext;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder; use JMS\Serializer\SerializerBuilder;
class AtolOnline class AtolOnline
@ -12,6 +14,9 @@ class AtolOnline
private $serializer; private $serializer;
/** @var AtolOnlineApi */
private $api;
public function __construct() public function __construct()
{ {
$this->serializer = SerializerBuilder::create()->build(); $this->serializer = SerializerBuilder::create()->build();
@ -32,14 +37,44 @@ class AtolOnline
); );
} }
public function deserializeCheckStatusResponse($response)
{
return $this->serializer->deserialize(
$response,
OperationResponse::class,
'json',
DeserializationContext::create()->setGroups(['get'])
);
}
public function serializeOperationRequest($request)
{
return $this->serializer->serialize(
$request,
'json',
SerializationContext::create()->setGroups(['set'])
);
}
/** /**
* @param $client * @param $client
* @param Connection $connection * @param Connection $connection
* @param $isDebug
* @return AtolOnlineApi * @return AtolOnlineApi
*/ */
public function getApi($client, Connection $connection, $isDebug) public function createApi(Client $client, Connection $connection)
{ {
return new AtolOnlineApi($client, $connection, $isDebug); if (!$this->api) {
$this->api = new AtolOnlineApi($client, $connection);
}
return $this->api;
}
/**
* @return AtolOnlineApi
*/
public function getApi()
{
return $this->api;
} }
} }

View File

@ -3,10 +3,12 @@
namespace AtolOnlineClient; namespace AtolOnlineClient;
use AtolOnlineClient\Configuration\Connection; use AtolOnlineClient\Configuration\Connection;
use Doctrine\Common\Cache\CacheProvider; use Doctrine\Common\Cache\Cache;
use GuzzleHttp\Client;
use Guzzle\Http\Client;
use Guzzle\Http\Message\Response;
use GuzzleHttp\Exception\BadResponseException; use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Psr7\Response;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class AtolOnlineApi class AtolOnlineApi
@ -18,8 +20,7 @@ class AtolOnlineApi
const TOKEN_CACHE_KEY = 'crm_fiscal_atol_online_token'; const TOKEN_CACHE_KEY = 'crm_fiscal_atol_online_token';
const TOKEN_CACHE_TIME = 60 * 60 * 24; const TOKEN_CACHE_TIME = 60 * 60 * 24;
// private $baseApiUrl = 'https://online.atol.ru/possystem'; private $baseApiUrl = 'https://online.atol.ru/possystem';
private $baseApiUrl = 'https://testonline.atol.ru/possystem';
private $login; private $login;
private $pass; private $pass;
@ -32,7 +33,7 @@ class AtolOnlineApi
private $logger; private $logger;
/** /**
* @var CacheProvider * @var Cache
*/ */
private $cache; private $cache;
@ -51,22 +52,25 @@ class AtolOnlineApi
*/ */
private $attemptsCheckStatus; private $attemptsCheckStatus;
/** @var string */
private $version; private $version;
/** /**
* @param Client $client * @param Client $client
* @param Connection $connectionConfig * @param Connection $connectionConfig
* @param bool $debug
*/ */
public function __construct(Client $client, Connection $connectionConfig, $debug = false) public function __construct(Client $client, Connection $connectionConfig)
{ {
$this->client = $client; $this->client = $client;
$this->login = $connectionConfig->login; $this->login = $connectionConfig->login;
$this->pass = $connectionConfig->pass; $this->pass = $connectionConfig->pass;
$this->groupCode = $connectionConfig->group; $this->groupCode = $connectionConfig->group;
$this->version = $connectionConfig->version; $this->version = $connectionConfig->version;
$this->debug = $debug; $this->debug = $connectionConfig->isDebug();
$this->attempts = 0; $this->attempts = 0;
if ($connectionConfig->isTestMode()) {
$this->baseApiUrl = 'https://testonline.atol.ru/possystem';
}
} }
/** /**
@ -136,9 +140,9 @@ class AtolOnlineApi
} }
/** /**
* @param CacheProvider $cache * @param Cache $cache
*/ */
public function setCache(CacheProvider $cache) public function setCache(Cache $cache)
{ {
$this->cache = $cache; $this->cache = $cache;
} }

View File

@ -1,290 +0,0 @@
<?php
namespace AtolOnlineClient;
use Guzzle\Http\Client;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Message\Response;
use Intaro\CRMFiscalBundle\FiscalService\AtolOnline\Configuration\Connection;
use Intaro\TaggableCacheBundle\Doctrine\Cache\CacheProvider;
use Psr\Log\LoggerInterface;
class AtolOnlineApiV4
{
const API_VERSION_V4 = 'v4';
const API_VERSION_V3 = 'v3';
const TOKEN_CACHE_KEY = 'crm_fiscal_atol_online_token';
const TOKEN_CACHE_TIME = 60 * 60 * 24;
// private $baseApiUrl = 'https://online.atol.ru/possystem';
private $baseApiUrl = 'https://testonline.atol.ru/possystem';
private $login;
private $pass;
private $groupCode;
private $debug;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var CacheProvider
*/
private $cache;
/**
* @var Client
*/
private $client;
/**
* @var int
*/
private $attempts;
/**
* @var int
*/
private $attemptsCheckStatus;
private $version;
/**
* AtolOnlineApi constructor.
* @param Client $client
* @param Connection $connectionConfig
* @param bool $debug
*/
public function __construct(Client $client, Connection $connectionConfig)
{
$this->client = $client;
$this->login = $connectionConfig->login;
$this->pass = $connectionConfig->pass;
$this->groupCode = $connectionConfig->group;
$this->version = $connectionConfig->version;
$this->debug =
$this->attempts = 0;
}
/**
* Приход
*
* @param $paymentReceiptRequest
* @return string
*/
public function sell($paymentReceiptRequest)
{
if ($response = $this->sendOperationRequest('sell', $paymentReceiptRequest)) {
return $response->getBody()->__toString();
};
}
/**
* Возврат прихода
*
* @param $paymentReceiptRequest
* @return string
*/
public function sellRefund($paymentReceiptRequest)
{
if ($response = $this->sendOperationRequest('sell_refund', $paymentReceiptRequest)) {
return $response->getBody()->__toString();
};
}
/**
* Запрос для проверки статуса
*
* @param $uuid
* @return mixed
*/
public function checkStatus($uuid)
{
$token = $this->getToken();
$url = $this->buildUrl('report/'.$uuid, $token);
$request = $this->client->get($url);
$response = false;
try {
$this->attemptsCheckStatus++;
$response = $request->send();
} catch (BadResponseException $e) {
$this->cache->delete($this->getTokenCacheKey());
$body = json_decode($e->getResponse()->getBody());
if ($this->isTokenExpired($body) && $this->attemptsCheckStatus <= 1) {
return $this->checkStatus($uuid);
}
$this->logDebug($url, $uuid, $e->getResponse());
}
if ($response) {
return $response->getBody()->__toString();
}
return false;
}
/**
* @param $logger
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* @param CacheProvider $cache
*/
public function setCache(CacheProvider $cache)
{
$this->cache = $cache;
}
/**
* @return mixed
*/
public function getVersion()
{
return $this->version;
}
/**
* @param mixed $version
*/
public function setVersion($version): void
{
$this->version = $version;
}
/**
* @return mixed
*/
protected function getToken()
{
$data = [
'login' => $this->login,
'pass' => $this->pass,
];
if ($token = $this->cache->fetch($this->getTokenCacheKey())) {
return $token;
}
$dataJson = json_encode((object)$data, JSON_UNESCAPED_UNICODE);
$url = $this->baseApiUrl
.'/'.$this->getVersion()
.'/getToken';
$request = $this->client->createRequest('POST', $url, null, $dataJson);
$response = false;
try {
$response = $this->client->send($request);
} catch (BadResponseException $e) {
if ($this->logger) {
$this->logger->error($e->getResponse()->getBody());
}
}
if ($response) {
$response = json_decode($response->getBody());
if (isset($response->code) && $response->code == 1 || $response->code == 0) {
$this->cache->save($this->getTokenCacheKey(), $response->token, self::TOKEN_CACHE_TIME);
return $response->token;
}
}
return false;
}
/**
* @param $data
* @return string
*/
protected function getTokenCacheKey()
{
return self::TOKEN_CACHE_KEY.'_'.md5($this->login.$this->pass);
}
/**
* @param string $operation
* @param null $token
* @return string
*/
protected function buildUrl($operation, $token = null)
{
$url = $this->baseApiUrl
.'/'.$this->version
.'/'.$this->groupCode
.'/'.$operation;
if ($token) {
if ($this->version === self::API_VERSION_V4) {
$url .= '?token='.$token;
} elseif ($this->version === self::API_VERSION_V3) {
$url .= '?tokenid='.$token;
}
}
return $url;
}
/**
* @param string $operation
* @param string $data
* @return Response|bool
*/
protected function sendOperationRequest($operation, $data)
{
$token = $this->getToken();
$url = $this->buildUrl($operation, $token);
$request = $this->client->createRequest('POST', $url, null, $data);
$response = false;
try {
$this->attempts++;
$response = $this->client->send($request);
} catch (BadResponseException $e) {
$this->cache->delete($this->getTokenCacheKey());
$body = json_decode($e->getResponse()->getBody());
if ($this->isTokenExpired($body) && $this->attempts <= 1) {
return $this->sendOperationRequest($operation, $data);
}
$this->logDebug($url, $data, $e->getResponse());
}
if ($response) {
$this->logDebug($url, $data, $response);
}
return $response;
}
protected function logDebug($url, $data, Response $response)
{
if ($this->debug && $this->logger) {
$v = "* URL: ".$url;
$v .= "\n * POSTFILEDS: ".$data;
$v .= "\n * RESPONSE HEADERS: ".$response->getRawHeaders();
$v .= "\n * RESPONSE BODY: ".$response->getBody();
$v .= "\n * ATTEMPTS: ".$this->attempts;
$this->logger->debug($v);
}
}
protected function isTokenExpiredCode($code)
{
return in_array($code, [4, 5, 6, 12, 13, 14]);
}
private function isTokenExpired($body)
{
return isset($body->error) && $this->isTokenExpiredCode($body->error->code);
}
}

View File

@ -17,12 +17,6 @@ class Configuration implements ConfigurationInterface
/** @var bool */ /** @var bool */
public $debug; public $debug;
/** @var bool */
public $sendEmail;
/** @var bool */
public $sendSms;
/** /**
* @param ClassMetadata $metadata * @param ClassMetadata $metadata
*/ */
@ -32,26 +26,26 @@ class Configuration implements ConfigurationInterface
$metadata->addPropertyConstraint('connections', new Assert\Valid()); $metadata->addPropertyConstraint('connections', new Assert\Valid());
} }
public function loadConnections($connections) // public function loadConnections($connections)
{ // {
if (!$connections) { // if (!$connections) {
return; // return;
} // }
foreach ($connections as $connectionItem) { // foreach ($connections as $connectionItem) {
$connection = new Connection(); // $connection = new Connection();
$connection->login = $connectionItem['login']; // $connection->login = $connectionItem['login'];
$connection->pass = $connectionItem['pass']; // $connection->pass = $connectionItem['pass'];
$connection->group = $connectionItem['group']; // $connection->group = $connectionItem['group'];
// $connection->legalEntity = $connectionItem['legalEntity']; //// $connection->legalEntity = $connectionItem['legalEntity'];
$connection->sno = $connectionItem['sno']; // $connection->sno = $connectionItem['sno'];
$connection->enabled = (bool) $connectionItem['enabled']; // $connection->enabled = (bool) $connectionItem['enabled'];
// $connection->paymentTypes = $connectionItem['paymentTypes']; //// $connection->paymentTypes = $connectionItem['paymentTypes'];
// $connection->paymentStatuses = $connectionItem['paymentStatuses']; //// $connection->paymentStatuses = $connectionItem['paymentStatuses'];
$connection->ofd = $connectionItem['ofd']; // $connection->ofd = $connectionItem['ofd'];
$connection->version = $connectionItem['version']; // $connection->version = $connectionItem['version'];
$this->connections[] = $connection; // $this->connections[] = $connection;
} // }
} // }
/** /**
* @param bool $enabled * @param bool $enabled
@ -61,30 +55,6 @@ class Configuration implements ConfigurationInterface
$this->enabled = (bool) $enabled; $this->enabled = (bool) $enabled;
} }
/**
* @param bool $sendEmail
*
* @return $this
*/
public function setSendEmail($sendEmail)
{
$this->sendEmail = (bool) $sendEmail;
return $this;
}
/**
* @param bool $sendSms
*
* @return $this
*/
public function setSendSms($sendSms)
{
$this->sendSms = (bool) $sendSms;
return $this;
}
/** /**
* @param mixed $debug * @param mixed $debug
*/ */
@ -101,22 +71,6 @@ class Configuration implements ConfigurationInterface
return (bool) $this->enabled; return (bool) $this->enabled;
} }
/**
* @return bool
*/
public function isSendEmail()
{
return (bool) $this->sendEmail;
}
/**
* @return bool
*/
public function isSendSms()
{
return (bool) $this->sendSms;
}
/** /**
* @return mixed * @return mixed
*/ */
@ -124,28 +78,4 @@ class Configuration implements ConfigurationInterface
{ {
return $this->debug; return $this->debug;
} }
/**
* @param LegalEntity $legalentity
* @return bool|Connection
*/
public function getLegalEntityConnection(LegalEntity $legalentity)
{
if (!$this->connections || !$this->enabled) {
return false;
}
foreach ($this->connections as $connection) {
if ($connection->enabled && $connection->legalEntity == $legalentity->getId()) {
return $connection;
}
}
return false;
}
protected function postLoadConfiguration()
{
}
} }

View File

@ -41,9 +41,11 @@ class Connection
self::V4, self::V4,
]; ];
/** @var string */
protected $url; protected $url;
/** @var bool */ /** @var bool */
protected $debug; protected $debug = false;
/** @var string */ /** @var string */
public $login; public $login;
@ -54,15 +56,6 @@ class Connection
/** @var string */ /** @var string */
public $group; public $group;
/** @var int */
public $legalEntity;
/** @var array */
public $paymentTypes;
/** @var array */
public $paymentStatuses;
/** @var boolean */ /** @var boolean */
public $enabled; public $enabled;
@ -75,18 +68,23 @@ class Connection
/** @var string */ /** @var string */
public $version; public $version;
/** @var bool */
public $testMode = false;
/** /**
* @param mixed $url * @return bool
*/ */
public function setUrl($url): void public function isTestMode()
{ {
$this->url = $url; return $this->testMode;
} }
/**
public function __construct() * @param bool $testMode
*/
public function setTestMode(bool $testMode)
{ {
$this->setUrl(''); $this->testMode = $testMode;
} }
/** /**
@ -113,7 +111,6 @@ class Connection
$metadata->addPropertyConstraint('login', new Assert\NotBlank()); $metadata->addPropertyConstraint('login', new Assert\NotBlank());
$metadata->addPropertyConstraint('pass', new Assert\NotBlank()); $metadata->addPropertyConstraint('pass', new Assert\NotBlank());
$metadata->addPropertyConstraint('group', new Assert\NotBlank()); $metadata->addPropertyConstraint('group', new Assert\NotBlank());
$metadata->addPropertyConstraint('legalEntity', new Assert\NotBlank());
$metadata->addPropertyConstraints('sno', [ $metadata->addPropertyConstraints('sno', [
new Assert\Choice([ new Assert\Choice([
'choices' => self::snoTypes, 'choices' => self::snoTypes,
@ -129,8 +126,6 @@ class Connection
'choices' => self::versions, 'choices' => self::versions,
]) ])
]); ]);
$metadata->addPropertyConstraint('paymentTypes', new Assert\NotBlank());
$metadata->addPropertyConstraint('paymentStatuses', new Assert\NotBlank());
} }
/** /**

View File

@ -17,13 +17,13 @@ class OperationResponse
private $uuid; private $uuid;
/** /**
* @var string * @var Error
* *
* @Serializer\Groups({"post", "get"}) * @Serializer\Groups({"post", "get"})
* @Serializer\SerializedName("timestamp") * @Serializer\SerializedName("error")
* @Serializer\Type("string") * @Serializer\Type("AtolOnlineClient\Response\Error")
*/ */
private $timestamp; private $error;
/** /**
* @var string * @var string
@ -36,6 +36,52 @@ class OperationResponse
*/ */
private $status; private $status;
/**
* @var Payload
*
* @Serializer\Groups({"get"})
* @Serializer\SerializedName("payload")
* @Serializer\Type("AtolOnlineClient\Response\Payload")
*/
private $payload;
/**
* @var string
*
* @Serializer\Groups({"post", "get"})
* @Serializer\SerializedName("timestamp")
* @Serializer\Type("string")
*/
private $timestamp;
/**
* @var string
*
* @Serializer\Groups({"get"})
* @Serializer\SerializedName("group_code")
* @Serializer\Type("string")
*/
private $groupCode;
/**
* @var string
*
* @Serializer\Groups({"get"})
* @Serializer\SerializedName("daemon_code")
* @Serializer\Type("string")
*/
private $daemonCode;
/**
* @var string
*
* @Serializer\Groups({"get"})
* @Serializer\SerializedName("device_code")
* @Serializer\Type("string")
*/
private $deviceCode;
/** /**
* @var string * @var string
* *
@ -45,23 +91,7 @@ class OperationResponse
*/ */
private $callbackUrl; private $callbackUrl;
/**
* @var Payload
*
* @Serializer\Groups({"get"})
* @Serializer\SerializedName("payload")
* @Serializer\Type("Intaro\CRMFiscalBundle\FiscalService\AtolOnline\Response\Payload")
*/
private $payload;
/**
* @var Error
*
* @Serializer\Groups({"post", "get"})
* @Serializer\SerializedName("error")
* @Serializer\Type("Intaro\CRMFiscalBundle\FiscalService\AtolOnline\Response\Error")
*/
private $error;
/** /**
* @return string * @return string
@ -182,4 +212,52 @@ class OperationResponse
return $this; return $this;
} }
/**
* @return string
*/
public function getGroupCode()
{
return $this->groupCode;
}
/**
* @param string $groupCode
*/
public function setGroupCode(string $groupCode)
{
$this->groupCode = $groupCode;
}
/**
* @return string
*/
public function getDaemonCode()
{
return $this->daemonCode;
}
/**
* @param string $daemonCode
*/
public function setDaemonCode(string $daemonCode)
{
$this->daemonCode = $daemonCode;
}
/**
* @return string
*/
public function getDeviceCode()
{
return $this->deviceCode;
}
/**
* @param string $deviceCode
*/
public function setDeviceCode(string $deviceCode)
{
$this->deviceCode = $deviceCode;
}
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace AtolOnlineClientResponse; namespace AtolOnlineClient\Response;
use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation as Serializer;

View File

@ -0,0 +1,17 @@
<?php
namespace AtolOnlineClient\Tests;
use AtolOnlineClient\AtolOnline;
use AtolOnlineClient\Configuration;
use PHPUnit\Framework\TestCase;
class AtolOnlineTest extends TestCase
{
public function testCreateConfiguration()
{
$atol = new AtolOnline();
$this->assertInstanceOf(Configuration::class, $atol->createConfiguration());
}
}