From bbc1bf93c992e7314c95878563a152237e580f90 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 21:22:32 +0300 Subject: [PATCH 01/14] update php --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e6773ad..769b3b9 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": ">=5.3.0" + "php": ">=8.0" }, "require-dev": { "phpunit/phpunit": "~4.4" From d6a339637ddd7c5ee34c82ab8f9182318c9a8d47 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 21:26:09 +0300 Subject: [PATCH 02/14] add structure --- src/{Delivery => Controllers/Api/v1}/NovaPoshtaApi2.php | 4 ++-- src/{Delivery => Controllers/Api/v1}/NovaPoshtaApi2Areas.php | 0 tests/NovaPoshtaApi2Test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/{Delivery => Controllers/Api/v1}/NovaPoshtaApi2.php (99%) rename src/{Delivery => Controllers/Api/v1}/NovaPoshtaApi2Areas.php (100%) diff --git a/src/Delivery/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php similarity index 99% rename from src/Delivery/NovaPoshtaApi2.php rename to src/Controllers/Api/v1/NovaPoshtaApi2.php index d56035d..39ced82 100644 --- a/src/Delivery/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -1,6 +1,6 @@ areas) and $this->areas = (include dirname(__FILE__).'/NovaPoshtaApi2Areas.php'); + empty($this->areas) and $this->areas = (include dirname(__FILE__) . '/NovaPoshtaApi2Areas.php'); $data = $this->findArea($this->areas, $findByString, $ref); // Error $error = array(); diff --git a/src/Delivery/NovaPoshtaApi2Areas.php b/src/Controllers/Api/v1/NovaPoshtaApi2Areas.php similarity index 100% rename from src/Delivery/NovaPoshtaApi2Areas.php rename to src/Controllers/Api/v1/NovaPoshtaApi2Areas.php diff --git a/tests/NovaPoshtaApi2Test.php b/tests/NovaPoshtaApi2Test.php index f276302..12aab99 100755 --- a/tests/NovaPoshtaApi2Test.php +++ b/tests/NovaPoshtaApi2Test.php @@ -2,7 +2,7 @@ namespace LisDev\Tests; -use LisDev\Delivery\NovaPoshtaApi2; +use LisDev\Controllers\NovaPoshtaApi2; /** * phpUnit test class. From e8f154010dd9963f251860fd6dd514ba124c782a Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 21:58:37 +0300 Subject: [PATCH 03/14] add models, services --- composer.json | 4 +- src/Controllers/Api/v1/NovaPoshtaApi2.php | 142 ---------------------- src/Models/Address.php | 8 ++ src/Models/Common.php | 8 ++ src/Models/ContactPerson.php | 8 ++ src/Models/CounterParty.php | 8 ++ src/Models/InternetDocument.php | 8 ++ src/Models/Model.php | 54 ++++++++ src/Services/ConnectionService.php | 11 ++ src/Services/OutputService.php | 30 +++++ src/Services/RequestService.php | 101 +++++++++++++++ 11 files changed, 239 insertions(+), 143 deletions(-) create mode 100644 src/Models/Address.php create mode 100644 src/Models/Common.php create mode 100644 src/Models/ContactPerson.php create mode 100644 src/Models/CounterParty.php create mode 100644 src/Models/InternetDocument.php create mode 100644 src/Models/Model.php create mode 100644 src/Services/ConnectionService.php create mode 100644 src/Services/OutputService.php create mode 100644 src/Services/RequestService.php diff --git a/composer.json b/composer.json index 769b3b9..f9a304e 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,9 @@ } ], "require": { - "php": ">=8.0" + "php": ">=8.0", + "ext-simplexml": "*", + "ext-curl": "*" }, "require-dev": { "phpunit/phpunit": "~4.4" diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index 39ced82..0f2b383 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -30,16 +30,6 @@ class NovaPoshtaApi2 */ protected $throwErrors = false; - /** - * @var string Format of returned data - array, json, xml - */ - protected $format = 'array'; - - /** - * @var string Language of response - */ - protected $language = 'ru'; - /** * @var string Connection type (curl | file_get_contents) */ @@ -224,92 +214,6 @@ private function prepare($data) return $data; } - /** - * Converts array to xml. - * - * @param array $array - * @param \SimpleXMLElement|bool $xml - */ - private function array2xml(array $array, $xml = false) - { - (false === $xml) and $xml = new \SimpleXMLElement(''); - foreach ($array as $key => $value) { - if (is_numeric($key)) { - $key = 'item'; - } - if (is_array($value)) { - $this->array2xml($value, $xml->addChild($key)); - } else { - $xml->addChild($key, $value); - } - } - return $xml->asXML(); - } - - /** - * Make request to NovaPoshta API. - * - * @param string $model Model name - * @param string $method Method name - * @param array $params Required params - */ - private function request($model, $method, $params = null) - { - // Get required URL - $url = 'xml' == $this->format - ? self::API_URI.'/xml/' - : self::API_URI.'/json/'; - - $data = array( - 'apiKey' => $this->key, - 'modelName' => $model, - 'calledMethod' => $method, - 'language' => $this->language, - 'methodProperties' => $params, - ); - $result = array(); - // Convert data to neccessary format - $post = 'xml' == $this->format - ? $this->array2xml($data) - : json_encode($data); - - if ('curl' == $this->getConnectionType()) { - $ch = curl_init($url); - if (is_resource($ch)) { - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: '.('xml' == $this->format ? 'text/xml' : 'application/json'))); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - - if ($this->timeout > 0) { - curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); - } - - $result = curl_exec($ch); - curl_close($ch); - } - } else { - $httpOptions = array( - 'method' => 'POST', - 'header' => "Content-type: application/x-www-form-urlencoded;\r\n", - 'content' => $post, - ); - - if ($this->timeout > 0) { - $httpOptions['timeout'] = $this->timeout; - } - - $result = file_get_contents($url, false, stream_context_create(array( - 'http' => $httpOptions, - ))); - } - - return $this->prepare($result); - } - /** * Set current model and empties method and params properties. * @@ -686,52 +590,6 @@ public function __call($method, $arguments) } } - /** - * Delete method of current model. - * - * @param array $params - * - * @return mixed - */ - public function delete($params) - { - return $this->request($this->model, 'delete', $params); - } - - /** - * Update method of current model - * Required params: - * For ContactPerson model: Ref, CounterpartyRef, FirstName (ukr), MiddleName, LastName, Phone (format 0xxxxxxxxx) - * For Counterparty model: Ref, CounterpartyProperty (Recipient|Sender), CityRef, CounterpartyType (Organization, PrivatePerson), - * FirstName (or name of organization), MiddleName, LastName, Phone (0xxxxxxxxx), OwnershipForm (if Organization). - * - * @param array $params - * - * @return mixed - */ - public function update($params) - { - return $this->request($this->model, 'update', $params); - } - - /** - * Save method of current model - * Required params: - * For ContactPerson model (only for Organization API key, for PrivatePerson error will be returned): - * CounterpartyRef, FirstName (ukr), MiddleName, LastName, Phone (format 0xxxxxxxxx) - * For Counterparty model: - * CounterpartyProperty (Recipient|Sender), CityRef, CounterpartyType (Organization, PrivatePerson), - * FirstName (or name of organization), MiddleName, LastName, Phone (0xxxxxxxxx), OwnershipForm (if Organization). - * - * @param array $params - * - * @return mixed - */ - public function save($params) - { - return $this->request($this->model, 'save', $params); - } - /** * getCounterparties() function of model Counterparty. * diff --git a/src/Models/Address.php b/src/Models/Address.php new file mode 100644 index 0000000..7550a86 --- /dev/null +++ b/src/Models/Address.php @@ -0,0 +1,8 @@ +request($this->model, 'save', $params); + } + + /** + * Update method of current model + * Required params: + * For ContactPerson model: Ref, CounterpartyRef, FirstName (ukr), MiddleName, LastName, Phone (format 0xxxxxxxxx) + * For Counterparty model: Ref, CounterpartyProperty (Recipient|Sender), CityRef, CounterpartyType (Organization, PrivatePerson), + * FirstName (or name of organization), MiddleName, LastName, Phone (0xxxxxxxxx), OwnershipForm (if Organization). + * + * @param array $params + * + * @return mixed + */ + public function update($params) + { + return $this->request($this->model, 'update', $params); + } + + /** + * Delete method of current model. + * + * @param array $params + * + * @return mixed + */ + public function delete($params) + { + return $this->request($this->model, 'delete', $params); + } +} \ No newline at end of file diff --git a/src/Services/ConnectionService.php b/src/Services/ConnectionService.php new file mode 100644 index 0000000..fd8ccd5 --- /dev/null +++ b/src/Services/ConnectionService.php @@ -0,0 +1,11 @@ +'); + foreach ($array as $key => $value) { + if (is_numeric($key)) { + $key = 'item'; + } + if (is_array($value)) { + $this->array2xml($value, $xml->addChild($key)); + } else { + $xml->addChild($key, $value); + } + } + return $xml->asXML(); + } + + +} \ No newline at end of file diff --git a/src/Services/RequestService.php b/src/Services/RequestService.php new file mode 100644 index 0000000..c79b91a --- /dev/null +++ b/src/Services/RequestService.php @@ -0,0 +1,101 @@ +outputService = new OutputService(); + } + + private function request(Model $model, string $method, array $params = null) + { + // Get required URL + $url = 'xml' == $this->format + ? self::API_URI.'/xml/' + : self::API_URI.'/json/'; + + $data = array( + 'apiKey' => $this->key, + 'modelName' => $model, + 'calledMethod' => $method, + 'language' => $this->language, + 'methodProperties' => $params, + ); + $result = array(); + // Convert data to neccessary format + $post = 'xml' == $this->format + ? $this->outputService->array2xml($data) + : json_encode($data); + + if ('curl' == $this->getConnectionType()) { + $ch = curl_init($url); + if (is_resource($ch)) { + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: '.('xml' == $this->format ? 'text/xml' : 'application/json'))); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + + if ($this->timeout > 0) { + curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); + } + + $result = curl_exec($ch); + curl_close($ch); + } + } else { + $httpOptions = array( + 'method' => 'POST', + 'header' => "Content-type: application/x-www-form-urlencoded;\r\n", + 'content' => $post, + ); + + if ($this->timeout > 0) { + $httpOptions['timeout'] = $this->timeout; + } + + $result = file_get_contents($url, false, stream_context_create(array( + 'http' => $httpOptions, + ))); + } + + return $this->prepare($result); + } +} \ No newline at end of file From 1bc6399f765a6f4e1c44461e18e48995bc3672cb Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 22:09:01 +0300 Subject: [PATCH 04/14] add model interface, services --- src/Controllers/Api/v1/NovaPoshtaApi2.php | 23 --------------------- src/Interfaces/ModelInterface.php | 12 +++++++++++ src/Models/Address.php | 2 +- src/Models/Common.php | 2 +- src/Models/ContactPerson.php | 2 +- src/Models/CounterParty.php | 2 +- src/Models/InternetDocument.php | 2 +- src/Models/Model.php | 10 +++++---- src/Services/ConnectionService.php | 25 +++++++++++++++++++++++ 9 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 src/Interfaces/ModelInterface.php diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index 0f2b383..405a03b 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -101,29 +101,6 @@ public function getKey() return $this->key; } - /** - * Setter for $connectionType property. - * - * @param string $connectionType Connection type (curl | file_get_contents) - * - * @return $this - */ - public function setConnectionType($connectionType) - { - $this->connectionType = $connectionType; - return $this; - } - - /** - * Getter for $connectionType property. - * - * @return string - */ - public function getConnectionType() - { - return $this->connectionType; - } - /** * @param int $timeout * diff --git a/src/Interfaces/ModelInterface.php b/src/Interfaces/ModelInterface.php new file mode 100644 index 0000000..67dc98d --- /dev/null +++ b/src/Interfaces/ModelInterface.php @@ -0,0 +1,12 @@ +request($this->model, 'save', $params); } @@ -35,7 +37,7 @@ public function save($params) * * @return mixed */ - public function update($params) + public function update(array $params): Model { return $this->request($this->model, 'update', $params); } @@ -47,7 +49,7 @@ public function update($params) * * @return mixed */ - public function delete($params) + public function delete(array $params): string { return $this->request($this->model, 'delete', $params); } diff --git a/src/Services/ConnectionService.php b/src/Services/ConnectionService.php index fd8ccd5..c40453b 100644 --- a/src/Services/ConnectionService.php +++ b/src/Services/ConnectionService.php @@ -2,10 +2,35 @@ namespace LisDev\Services; +use LisDev\Controllers\NovaPoshtaApi2; + class ConnectionService { /** * @var string Connection type (curl | file_get_contents) */ protected string $connectionType = 'curl'; + + /** + * Getter for $connectionType property. + * + * @return string + */ + public function getConnectionType(): string + { + return $this->connectionType; + } + + /** + * Setter for $connectionType property. + * + * @param string $connectionType Connection type (curl | file_get_contents) + * + * @return $this + */ + public function setConnectionType(string $connectionType): ConnectionService + { + $this->connectionType = $connectionType; + return $this; + } } \ No newline at end of file From e572c60c76e8f71ea1f76fe0b042fee83a0e56a6 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 22:45:26 +0300 Subject: [PATCH 05/14] add model interface, services --- .../Api/v1/NovaPoshtaApi.php} | 63 +++++--- src/Controllers/Api/v1/NovaPoshtaApi2.php | 151 ------------------ src/Services/FormatService.php | 32 ++++ src/Services/LanguageService.php | 36 +++++ src/Services/PreparationDataService.php | 36 +++++ src/Services/WarehouseService.php | 53 ++++++ 6 files changed, 197 insertions(+), 174 deletions(-) rename src/{Services/RequestService.php => Controllers/Api/v1/NovaPoshtaApi.php} (65%) create mode 100644 src/Services/FormatService.php create mode 100644 src/Services/LanguageService.php create mode 100644 src/Services/PreparationDataService.php create mode 100644 src/Services/WarehouseService.php diff --git a/src/Services/RequestService.php b/src/Controllers/Api/v1/NovaPoshtaApi.php similarity index 65% rename from src/Services/RequestService.php rename to src/Controllers/Api/v1/NovaPoshtaApi.php index c79b91a..57f4f55 100644 --- a/src/Services/RequestService.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi.php @@ -2,9 +2,10 @@ namespace LisDev\Services; +use LisDev\Controllers\NovaPoshtaApi2; use LisDev\Models\Model; -class RequestService +class NovaPoshtaApi { const API_URI = 'https://api.novaposhta.ua/v2.0'; @@ -17,35 +18,31 @@ class RequestService */ protected string $key; - /** - * @var string Format of returned data - array, json, xml - */ - protected string $format = 'array'; + /** @var int Connection timeout (in seconds) */ + protected int $timeout = 0; - /** - * @var string Language of response - */ - protected string $language = 'ru'; protected OutputService $outputService; - - /** - * Make request to NovaPoshta API. - * - * @param Model $model Model name - * @param string $method Method name - * @param array|null $params Required params - * @return mixed - */ + private ConnectionService $connectionService; + private PreparationDataService $preparationDataService; + private LanguageService $languageService; + private FormatService $formatService; public function __construct() { $this->outputService = new OutputService(); + $this->connectionService = new ConnectionService(); + $this->preparationDataService = new PreparationDataService(); + $this->languageService = new LanguageService(); + $this->formatService = new FormatService(); } + /** + * @throws \Exception + */ private function request(Model $model, string $method, array $params = null) { // Get required URL - $url = 'xml' == $this->format + $url = 'xml' == $this->formatService->getFormat() ? self::API_URI.'/xml/' : self::API_URI.'/json/'; @@ -53,16 +50,16 @@ private function request(Model $model, string $method, array $params = null) 'apiKey' => $this->key, 'modelName' => $model, 'calledMethod' => $method, - 'language' => $this->language, + 'language' => $this->languageService->getLanguage(), 'methodProperties' => $params, ); $result = array(); // Convert data to neccessary format - $post = 'xml' == $this->format + $post = 'xml' == $this->formatService->getFormat() ? $this->outputService->array2xml($data) : json_encode($data); - if ('curl' == $this->getConnectionType()) { + if ('curl' == $this->connectionService->getConnectionType()) { $ch = curl_init($url); if (is_resource($ch)) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -96,6 +93,26 @@ private function request(Model $model, string $method, array $params = null) ))); } - return $this->prepare($result); + return $this->preparationDataService->prepare($result); + } + + /** + * @param int $timeout + * + * @return $this + */ + public function setTimeout(int $timeout): NovaPoshtaApi + { + $this->timeout = (int)$timeout; + + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; } } \ No newline at end of file diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index 405a03b..d0ea81e 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -30,34 +30,11 @@ class NovaPoshtaApi2 */ protected $throwErrors = false; - /** - * @var string Connection type (curl | file_get_contents) - */ - protected $connectionType = 'curl'; - - /** @var int Connection timeout (in seconds) */ - protected $timeout = 0; /** * @var string Areas (loaded from file, because there is no so function in NovaPoshta API 2.0) */ protected $areas = ''; - - /** - * @var string Set current model for methods save(), update(), delete() - */ - protected $model = 'Common'; - - /** - * @var string Set method of current model - */ - protected $method = ''; - - /** - * @var array Set params of current method of current model - */ - protected $params = array(); - /** * Default constructor. * @@ -101,95 +78,6 @@ public function getKey() return $this->key; } - /** - * @param int $timeout - * - * @return $this - */ - public function setTimeout($timeout) - { - $this->timeout = (int)$timeout; - - return $this; - } - - /** - * @return int - */ - public function getTimeout() - { - return $this->timeout; - } - - /** - * Setter for language property. - * - * @param string $language - * - * @return NovaPoshtaApi2 - */ - public function setLanguage($language) - { - $this->language = $language; - return $this; - } - - /** - * Getter for language property. - * - * @return string - */ - public function getLanguage() - { - return $this->language; - } - - /** - * Setter for format property. - * - * @param string $format Format of returned data by methods (json, xml, array) - * - * @return NovaPoshtaApi2 - */ - public function setFormat($format) - { - $this->format = $format; - return $this; - } - - /** - * Getter for format property. - * - * @return string - */ - public function getFormat() - { - return $this->format; - } - - /** - * Prepare data before return it. - * - * @param string|array $data - * - * @return mixed - */ - private function prepare($data) - { - // Returns array - if ('array' == $this->format) { - $result = is_array($data) - ? $data - : json_decode($data, true); - // If error exists, throw Exception - if ($this->throwErrors and array_key_exists('errors', $result) and $result['errors']) { - throw new \Exception(is_array($result['errors']) ? implode("\n", $result['errors']) : $result['errors']); - } - return $result; - } - // Returns json or xml document - return $data; - } /** * Set current model and empties method and params properties. @@ -324,45 +212,6 @@ public function findNearestWarehouse($searchStringArray) )); } - /** - * Get one warehouse by city name and warehouse's description. - * - * @param string $cityRef ID of city - * @param string $description Description like in getted by getWarehouses() - * - * @return mixed - */ - public function getWarehouse($cityRef, $description = '') - { - $warehouses = $this->getWarehouses($cityRef); - $error = array(); - $data = array(); - if (is_array($warehouses['data'])) { - $data = $warehouses['data'][0]; - if (count($warehouses['data']) > 1 && $description) { - foreach ($warehouses['data'] as $warehouse) { - if (false !== mb_stripos($warehouse['Description'], $description) - or false !== mb_stripos($warehouse['DescriptionRu'], $description)) { - $data = $warehouse; - break; - } - } - } - } - // Error - (!$data) and $error = 'Warehouse was not found'; - // Return data in same format like NovaPoshta API - return $this->prepare( - array( - 'success' => empty($error), - 'data' => array($data), - 'errors' => (array) $error, - 'warnings' => array(), - 'info' => array(), - ) - ); - } - /** * Get streets list by city and/or search string. * diff --git a/src/Services/FormatService.php b/src/Services/FormatService.php new file mode 100644 index 0000000..283658f --- /dev/null +++ b/src/Services/FormatService.php @@ -0,0 +1,32 @@ +format = $format; + return $this; + } + + /** + * Getter for format property. + * + * @return string + */ + public function getFormat(): string + { + return $this->format; + } +} \ No newline at end of file diff --git a/src/Services/LanguageService.php b/src/Services/LanguageService.php new file mode 100644 index 0000000..77cb1e1 --- /dev/null +++ b/src/Services/LanguageService.php @@ -0,0 +1,36 @@ +language = $language; + return $this; + } + + /** + * Getter for language property. + * + * @return string + */ + public function getLanguage(): string + { + return $this->language; + } +} \ No newline at end of file diff --git a/src/Services/PreparationDataService.php b/src/Services/PreparationDataService.php new file mode 100644 index 0000000..ecbca0f --- /dev/null +++ b/src/Services/PreparationDataService.php @@ -0,0 +1,36 @@ +format) { + $result = is_array($data) + ? $data + : json_decode($data, true); + // If error exists, throw Exception + if ($this->throwErrors and array_key_exists('errors', $result) and $result['errors']) { + throw new \Exception(is_array($result['errors']) ? implode("\n", $result['errors']) : $result['errors']); + } + return $result; + } + // Returns json or xml document + return $data; + } +} \ No newline at end of file diff --git a/src/Services/WarehouseService.php b/src/Services/WarehouseService.php new file mode 100644 index 0000000..e183a40 --- /dev/null +++ b/src/Services/WarehouseService.php @@ -0,0 +1,53 @@ +preparationDataService = new PreparationDataService(); + } + + /** + * Get one warehouse by city name and warehouse's description. + * + * @param string $cityRef ID of city + * @param string $description Description like in getted by getWarehouses() + * + * @return mixed + * @throws \Exception + */ + public function getWarehouse($cityRef, $description = '') + { + $warehouses = $this->getWarehouses($cityRef); + $error = array(); + $data = array(); + if (is_array($warehouses['data'])) { + $data = $warehouses['data'][0]; + if (count($warehouses['data']) > 1 && $description) { + foreach ($warehouses['data'] as $warehouse) { + if (false !== mb_stripos($warehouse['Description'], $description) + or false !== mb_stripos($warehouse['DescriptionRu'], $description)) { + $data = $warehouse; + break; + } + } + } + } + // Error + (!$data) and $error = 'Warehouse was not found'; + // Return data in same format like NovaPoshta API + return $this->preparationDataService->prepare( + array( + 'success' => empty($error), + 'data' => array($data), + 'errors' => (array) $error, + 'warnings' => array(), + 'info' => array(), + ) + ); + } +} \ No newline at end of file From e1c2cb966143abd63404fc01886b6823de6bb802 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 22:59:57 +0300 Subject: [PATCH 06/14] fix service --- composer.json | 2 +- src/{Services => Common}/FormatService.php | 2 +- src/{Services => Common}/LanguageService.php | 4 +--- src/Common/PrintMarkingType.php | 13 +++++++++++++ .../{NovaPoshtaApi.php => NovaPoshtaApiClient.php} | 10 ++++++---- src/Interfaces/NovaPoshtaApiClientInterface.php | 10 ++++++++++ src/Models/TrackingDocument.php | 8 ++++++++ 7 files changed, 40 insertions(+), 9 deletions(-) rename src/{Services => Common}/FormatService.php (95%) rename src/{Services => Common}/LanguageService.php (89%) create mode 100644 src/Common/PrintMarkingType.php rename src/Controllers/Api/v1/{NovaPoshtaApi.php => NovaPoshtaApiClient.php} (90%) create mode 100644 src/Interfaces/NovaPoshtaApiClientInterface.php create mode 100644 src/Models/TrackingDocument.php diff --git a/composer.json b/composer.json index f9a304e..10ede50 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-simplexml": "*", "ext-curl": "*" }, diff --git a/src/Services/FormatService.php b/src/Common/FormatService.php similarity index 95% rename from src/Services/FormatService.php rename to src/Common/FormatService.php index 283658f..607a26f 100644 --- a/src/Services/FormatService.php +++ b/src/Common/FormatService.php @@ -1,6 +1,6 @@ formatService->getFormat() @@ -101,7 +103,7 @@ private function request(Model $model, string $method, array $params = null) * * @return $this */ - public function setTimeout(int $timeout): NovaPoshtaApi + public function setTimeout(int $timeout): NovaPoshtaApiClient { $this->timeout = (int)$timeout; diff --git a/src/Interfaces/NovaPoshtaApiClientInterface.php b/src/Interfaces/NovaPoshtaApiClientInterface.php new file mode 100644 index 0000000..d626ac7 --- /dev/null +++ b/src/Interfaces/NovaPoshtaApiClientInterface.php @@ -0,0 +1,10 @@ + Date: Sun, 24 Apr 2022 23:13:09 +0300 Subject: [PATCH 07/14] add model interface, services --- src/Controllers/Api/v1/NovaPoshtaApi2.php | 79 --------------------- src/Services/GenerateReportService.php | 27 ++++++++ src/Services/PrintLinksService.php | 83 +++++++++++++++++++++++ 3 files changed, 110 insertions(+), 79 deletions(-) create mode 100644 src/Services/GenerateReportService.php create mode 100644 src/Services/PrintLinksService.php diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index d0ea81e..31538db 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -579,19 +579,6 @@ public function getDocument($ref) )); } - /** - * Generetes report by Document refs. - * - * @param array $params Params like getDocumentList with requiered keys - * 'Type' => [xls, csv], 'DocumentRefs' => [] - * - * @return mixed - */ - public function generateReport($params) - { - return $this->request('InternetDocument', 'generateReport', $params); - } - /** * Check required fields for new InternetDocument and set defaults. * @@ -730,70 +717,4 @@ public function newInternetDocument($sender, $recipient, $params) // Creating new Internet Document return $this->model('InternetDocument')->save($paramsInternetDocument); } - - /** - * Get only link on internet document for printing. - * - * @param string $method Called method of NovaPoshta API - * @param array $documentRefs Array of Documents IDs - * @param string $type (html_link|pdf_link) - * - * @return mixed - */ - protected function printGetLink($method, $documentRefs, $type) - { - $data = 'https://my.novaposhta.ua/orders/'.$method.'/orders[]/'.implode(',', $documentRefs) - .'/type/'.str_replace('_link', '', $type) - .'/apiKey/'.$this->key; - // Return data in same format like NovaPoshta API - return $this->prepare( - array( - 'success' => true, - 'data' => array($data), - 'errors' => array(), - 'warnings' => array(), - 'info' => array(), - ) - ); - } - - /** - * printDocument method of InternetDocument model. - * - * @param array|string $documentRefs Array of Documents IDs - * @param string $type (pdf|html|html_link|pdf_link) - * - * @return mixed - */ - public function printDocument($documentRefs, $type = 'html') - { - $documentRefs = (array) $documentRefs; - // If needs link - if ('html_link' == $type or 'pdf_link' == $type) { - return $this->printGetLink('printDocument', $documentRefs, $type); - } - // If needs data - return $this->request('InternetDocument', 'printDocument', array('DocumentRefs' => $documentRefs, 'Type' => $type)); - } - - /** - * printMarkings method of InternetDocument model. - * - * @param array|string $documentRefs Array of Documents IDs - * @param string $type (pdf|new_pdf|new_html|old_html|html_link|pdf_link) - * - * @return mixed - */ - public function printMarkings($documentRefs, $type = 'new_html', $size = '85x85') - { - $documentRefs = (array) $documentRefs; - $documentSize = $size === '85x85' ? '85x85' : '100x100'; - $method = 'printMarking'.$documentSize; - // If needs link - if ('html_link' == $type or 'pdf_link' == $type) { - return $this->printGetLink($method, $documentRefs, $type); - } - // If needs data - return $this->request('InternetDocument', $method, array('DocumentRefs' => $documentRefs, 'Type' => $type)); - } } diff --git a/src/Services/GenerateReportService.php b/src/Services/GenerateReportService.php new file mode 100644 index 0000000..fee05b7 --- /dev/null +++ b/src/Services/GenerateReportService.php @@ -0,0 +1,27 @@ +novaPoshtaApiClient = new NovaPoshtaApiClient(); + } + + /** + * Generetes report by Document refs. + * + * @param array $params Params like getDocumentList with requiered keys + * 'Type' => [xls, csv], 'DocumentRefs' => [] + * + * @return mixed + * @throws \Exception + */ + public function generateReport($params) + { + return $this->novaPoshtaApiClient->request('InternetDocument', 'generateReport', $params); + } +} \ No newline at end of file diff --git a/src/Services/PrintLinksService.php b/src/Services/PrintLinksService.php new file mode 100644 index 0000000..7c67b3c --- /dev/null +++ b/src/Services/PrintLinksService.php @@ -0,0 +1,83 @@ +preparationDataService = new PreparationDataService(); + $this->novaPoshtaApiClient = new NovaPoshtaApiClient(); + } + + /** + * Get only link on internet document for printing. + * + * @param string $method Called method of NovaPoshta API + * @param array $documentRefs Array of Documents IDs + * @param string $type (html_link|pdf_link) + * + * @return mixed + */ + protected function printGetLink($method, $documentRefs, $type) + { + $data = 'https://my.novaposhta.ua/orders/'.$method.'/orders[]/'.implode(',', $documentRefs) + .'/type/'.str_replace('_link', '', $type) + .'/apiKey/'.$this->key; + // Return data in same format like NovaPoshta API + return $this->preparationDataService->prepare( + array( + 'success' => true, + 'data' => array($data), + 'errors' => array(), + 'warnings' => array(), + 'info' => array(), + ) + ); + } + + /** + * printDocument method of InternetDocument model. + * + * @param array|string $documentRefs Array of Documents IDs + * @param string|PrintMarkingType $type (pdf|html|html_link|pdf_link) + * + * @return mixed + */ + public function printDocument($documentRefs, string|PrintMarkingType $type = PrintMarkingType::HtmlLink) + { + $documentRefs = (array) $documentRefs; + // If needs link + if (PrintMarkingType::HtmlLink == $type || PrintMarkingType::PdfLink == $type) { + return $this->printGetLink('printDocument', $documentRefs, $type); + } + // If needs data + return $this->request('InternetDocument', 'printDocument', array('DocumentRefs' => $documentRefs, 'Type' => $type)); + } + + /** + * printMarkings method of InternetDocument model. + * + * @param array|string $documentRefs Array of Documents IDs + * @param string|PrintMarkingType $type (pdf|new_pdf|new_html|old_html|html_link|pdf_link) + * + * @return mixed + */ + public function printMarkings($documentRefs, string|PrintMarkingType $type = PrintMarkingType::NewHtml, $size = '85x85') + { + $documentRefs = (array) $documentRefs; + $documentSize = $size === '85x85' ? '85x85' : '100x100'; + $method = 'printMarking'.$documentSize; + // If needs link + if ('html_link' == $type or 'pdf_link' == $type) { + return $this->printGetLink($method, $documentRefs, $type); + } + // If needs data + return $this->novaPoshtaApiClient->request('InternetDocument', $method, array('DocumentRefs' => $documentRefs, 'Type' => $type)); + } +} \ No newline at end of file From bd8128b825ae1a114465e76791bfd88ba5bf4e73 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 23:15:58 +0300 Subject: [PATCH 08/14] add areas class --- src/Common/ListAreas.php | 153 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/Common/ListAreas.php diff --git a/src/Common/ListAreas.php b/src/Common/ListAreas.php new file mode 100644 index 0000000..198115e --- /dev/null +++ b/src/Common/ListAreas.php @@ -0,0 +1,153 @@ + [ + 'Description' => 'Вінниця', + 'DescriptionRu' => 'Винница', + 'Area' => 'Вінницька', + 'AreaRu' => 'Винницкая', + ], + '7150812b-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Дніпропетровськ', + 'DescriptionRu' => 'Днепропетровск', + 'Area' => 'Дніпропетровська', + 'AreaRu' => 'Днепропетровская', + ], + '7150812c-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Донецьк', + 'DescriptionRu' => 'Донецк', + 'Area' => 'Донецька', + 'AreaRu' => 'Донецкая', + ], + '7150812d-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Житомир', + 'DescriptionRu' => 'Житомир', + 'Area' => 'Житомирська', + 'AreaRu' => 'Житомирская', + ], + '7150812f-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Запоріжжя', + 'DescriptionRu' => 'Запорожье', + 'Area' => 'Запорізька', + 'AreaRu' => 'Запорожская', + ], + '71508130-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Івано-Франківськ', + 'DescriptionRu' => 'Ивано-Франковск', + 'Area' => 'Івано-Франківська', + 'AreaRu' => 'Ивано-Франковская', + ], + '71508131-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Київ', + 'DescriptionRu' => 'Киев', + 'Area' => 'Київська', + 'AreaRu' => 'Киевская', + ], + '71508132-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Кіровоград', + 'DescriptionRu' => 'Кировоград', + 'Area' => 'Кіровоградська', + 'AreaRu' => 'Кировоградская', + ], + '71508133-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Луганськ', + 'DescriptionRu' => 'Луганск', + 'Area' => 'Луганська', + 'AreaRu' => 'Луганская', + ], + '7150812a-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Луцьк', + 'DescriptionRu' => 'Луцк', + 'Area' => 'Волинська', + 'AreaRu' => 'Волынская', + ], + '71508134-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Львів', + 'DescriptionRu' => 'Львов', + 'Area' => 'Львівська', + 'AreaRu' => 'Львовская', + ], + '71508135-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Миколаїв', + 'DescriptionRu' => 'Николаев', + 'Area' => 'Миколаївська', + 'AreaRu' => 'Николаевская', + ], + '71508136-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Одеса', + 'DescriptionRu' => 'Одесса', + 'Area' => 'Одеська', + 'AreaRu' => 'Одесская', + ], + '71508137-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Полтава', + 'DescriptionRu' => 'Полтава', + 'Area' => 'Полтавська', + 'AreaRu' => 'Полтавская', + ], + '71508138-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Рівне', + 'DescriptionRu' => 'Ровно', + 'Area' => 'Рівненська', + 'AreaRu' => 'Ровненская', + ], + '71508139-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Суми', + 'DescriptionRu' => 'Сумы', + 'Area' => 'Сумська', + 'AreaRu' => 'Сумская', + ], + '7150813a-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Тернопіль', + 'DescriptionRu' => 'Тернополь', + 'Area' => 'Тернопільська', + 'AreaRu' => 'Тернопольская', + ], + '7150812e-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Ужгород', + 'DescriptionRu' => 'Ужгород', + 'Area' => 'Закарпатська', + 'AreaRu' => 'Закарпатская', + ], + '7150813b-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Харків', + 'DescriptionRu' => 'Харьков', + 'Area' => 'Харківська', + 'AreaRu' => 'Харьковская', + ], + '7150813c-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Херсон', + 'DescriptionRu' => 'Херсон', + 'Area' => 'Херсонська', + 'AreaRu' => 'Херсонская', + ], + '7150813d-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Хмельницький', + 'DescriptionRu' => 'Хмельницкий', + 'Area' => 'Хмельницька', + 'AreaRu' => 'Хмельницкая', + ], + '7150813e-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Черкаси', + 'DescriptionRu' => 'Черкассы', + 'Area' => 'Черкаська', + 'AreaRu' => 'Черкасская', + ], + '71508140-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Чернігів', + 'DescriptionRu' => 'Чернигов', + 'Area' => 'Чернігівська', + 'AreaRu' => 'Черниговская', + ], + '7150813f-9b87-11de-822f-000c2965ae0e' => [ + 'Description' => 'Чернівці', + 'DescriptionRu' => 'Черновцы', + 'Area' => 'Чернівецька', + 'AreaRu' => 'Черновицкая', + ], + ]; +} \ No newline at end of file From 1585c056fc9fc68e11c79ac0fea9bd44f64e40ba Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 23:20:27 +0300 Subject: [PATCH 09/14] fix service --- src/Controllers/Api/v1/NovaPoshtaApi2.php | 14 ---------- .../Api/v1/NovaPoshtaApiClient.php | 2 +- .../NovaPoshtaApiClientInterface.php | 2 +- src/Services/TrackingDocumentService.php | 27 +++++++++++++++++++ 4 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/Services/TrackingDocumentService.php diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index 31538db..c9d9d34 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -139,20 +139,6 @@ public function execute() return $this->request($this->model, $this->method, $this->params); } - /** - * Get tracking information by track number. - * - * @param string $track Track number - * - * @return mixed - */ - public function documentsTracking($track) - { - $params = array('Documents' => array(array('DocumentNumber' => $track))); - - return $this->request('TrackingDocument', 'getStatusDocuments', $params); - } - /** * Get cities of company NovaPoshta. * diff --git a/src/Controllers/Api/v1/NovaPoshtaApiClient.php b/src/Controllers/Api/v1/NovaPoshtaApiClient.php index 4e6e679..5cfd94c 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApiClient.php +++ b/src/Controllers/Api/v1/NovaPoshtaApiClient.php @@ -41,7 +41,7 @@ public function __construct() /** * @throws \Exception */ - public function request(Model $model, string $method, array $params = null) + public function request(string $model, string $method, array $params = null) { // Get required URL $url = 'xml' == $this->formatService->getFormat() diff --git a/src/Interfaces/NovaPoshtaApiClientInterface.php b/src/Interfaces/NovaPoshtaApiClientInterface.php index d626ac7..ee5155c 100644 --- a/src/Interfaces/NovaPoshtaApiClientInterface.php +++ b/src/Interfaces/NovaPoshtaApiClientInterface.php @@ -6,5 +6,5 @@ interface NovaPoshtaApiClientInterface { - public function request(Model $model, string $method, array $params = null); + public function request(string $model, string $method, array $params = null); } \ No newline at end of file diff --git a/src/Services/TrackingDocumentService.php b/src/Services/TrackingDocumentService.php new file mode 100644 index 0000000..7a6448a --- /dev/null +++ b/src/Services/TrackingDocumentService.php @@ -0,0 +1,27 @@ +novaPoshtaApiClient = new NovaPoshtaApiClient(); + } + + /**` + * Get tracking information by track number. + * + * @param string $track Track number + * + * @return mixed + */ + public function documentsTracking($track) + { + $params = array('Documents' => array(array('DocumentNumber' => $track))); + + return $this->novaPoshtaApiClient->request('TrackingDocument', 'getStatusDocuments', $params); + } +} \ No newline at end of file From d080a1ca9ceda5f43ee94c7fb42e8275afa6e9aa Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 23:27:33 +0300 Subject: [PATCH 10/14] add exception --- src/Exception/ArgumentException.php | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/Exception/ArgumentException.php diff --git a/src/Exception/ArgumentException.php b/src/Exception/ArgumentException.php new file mode 100644 index 0000000..b4373a0 --- /dev/null +++ b/src/Exception/ArgumentException.php @@ -0,0 +1,8 @@ + Date: Sun, 24 Apr 2022 23:31:47 +0300 Subject: [PATCH 11/14] add document service --- src/Controllers/Api/v1/NovaPoshtaApi2.php | 79 ------------------- src/Services/InternetDocumentService.php | 93 +++++++++++++++++++++++ 2 files changed, 93 insertions(+), 79 deletions(-) create mode 100644 src/Services/InternetDocumentService.php diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index c9d9d34..f09a1de 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -486,85 +486,6 @@ public function getCounterpartyByEDRPOU($edrpou, $cityRef) return $this->request('Counterparty', 'getCounterpartyByEDRPOU', array('EDRPOU' => $edrpou, 'cityRef' => $cityRef)); } - /** - * Get price of delivery between two cities. - * - * @param string $citySender City ID - * @param string $cityRecipient City ID - * @param string $serviceType (DoorsDoors|DoorsWarehouse|WarehouseWarehouse|WarehouseDoors) - * @param float $weight - * @param float $cost - * - * @return mixed - */ - public function getDocumentPrice($citySender, $cityRecipient, $serviceType, $weight, $cost) - { - return $this->request('InternetDocument', 'getDocumentPrice', array( - 'CitySender' => $citySender, - 'CityRecipient' => $cityRecipient, - 'ServiceType' => $serviceType, - 'Weight' => $weight, - 'Cost' => $cost, - )); - } - - /** - * Get approximately date of delivery between two cities. - * - * @param string $citySender City ID - * @param string $cityRecipient City ID - * @param string $serviceType (DoorsDoors|DoorsWarehouse|WarehouseWarehouse|WarehouseDoors) - * @param string $dateTime Date of shipping - * - * @return mixed - */ - public function getDocumentDeliveryDate($citySender, $cityRecipient, $serviceType, $dateTime) - { - return $this->request('InternetDocument', 'getDocumentDeliveryDate', array( - 'CitySender' => $citySender, - 'CityRecipient' => $cityRecipient, - 'ServiceType' => $serviceType, - 'DateTime' => $dateTime, - )); - } - - /** - * Get documents list. - * - * @param array $params List of params - * Not required keys: - * 'Ref', 'IntDocNumber', 'InfoRegClientBarcodes', 'DeliveryDateTime', 'RecipientDateTime', - * 'CreateTime', 'SenderRef', 'RecipientRef', 'WeightFrom', 'WeightTo', - * 'CostFrom', 'CostTo', 'SeatsAmountFrom', 'SeatsAmountTo', 'CostOnSiteFrom', - * 'CostOnSiteTo', 'StateIds', 'ScanSheetRef', 'DateTime', 'DateTimeFrom', - * 'RecipientDateTime', 'isAfterpayment', 'Page', 'OrderField => - * [ - * IntDocNumber, DateTime, Weight, Cost, SeatsAmount, CostOnSite, - * CreateTime, EstimatedDeliveryDate, StateId, InfoRegClientBarcodes, RecipientDateTime - * ], - * 'OrderDirection' => [DESC, ASC], 'ScanSheetRef' - * - * @return mixed - */ - public function getDocumentList($params = null) - { - return $this->request('InternetDocument', 'getDocumentList', $params ? $params : null); - } - - /** - * Get document info by ID. - * - * @param string $ref Document ID - * - * @return mixed - */ - public function getDocument($ref) - { - return $this->request('InternetDocument', 'getDocument', array( - 'Ref' => $ref, - )); - } - /** * Check required fields for new InternetDocument and set defaults. * diff --git a/src/Services/InternetDocumentService.php b/src/Services/InternetDocumentService.php new file mode 100644 index 0000000..c1e694e --- /dev/null +++ b/src/Services/InternetDocumentService.php @@ -0,0 +1,93 @@ +novaPoshtaApiClient = new NovaPoshtaApiClient(); + } + + /** + * Get price of delivery between two cities. + * + * @param string $citySender City ID + * @param string $cityRecipient City ID + * @param string $serviceType (DoorsDoors|DoorsWarehouse|WarehouseWarehouse|WarehouseDoors) + * @param float $weight + * @param float $cost + * + * @return mixed + * @throws \Exception + */ + public function getDocumentPrice($citySender, $cityRecipient, $serviceType, $weight, $cost) + { + return $this->novaPoshtaApiClient->request('InternetDocument', 'getDocumentPrice', array( + 'CitySender' => $citySender, + 'CityRecipient' => $cityRecipient, + 'ServiceType' => $serviceType, + 'Weight' => $weight, + 'Cost' => $cost, + )); + } + + /** + * Get approximately date of delivery between two cities. + * + * @param string $citySender City ID + * @param string $cityRecipient City ID + * @param string $serviceType (DoorsDoors|DoorsWarehouse|WarehouseWarehouse|WarehouseDoors) + * @param string $dateTime Date of shipping + * + * @return mixed + */ + public function getDocumentDeliveryDate($citySender, $cityRecipient, $serviceType, $dateTime) + { + return $this->novaPoshtaApiClient->request('InternetDocument', 'getDocumentDeliveryDate', array( + 'CitySender' => $citySender, + 'CityRecipient' => $cityRecipient, + 'ServiceType' => $serviceType, + 'DateTime' => $dateTime, + )); + } + + /** + * Get documents list. + * + * @param array $params List of params + * Not required keys: + * 'Ref', 'IntDocNumber', 'InfoRegClientBarcodes', 'DeliveryDateTime', 'RecipientDateTime', + * 'CreateTime', 'SenderRef', 'RecipientRef', 'WeightFrom', 'WeightTo', + * 'CostFrom', 'CostTo', 'SeatsAmountFrom', 'SeatsAmountTo', 'CostOnSiteFrom', + * 'CostOnSiteTo', 'StateIds', 'ScanSheetRef', 'DateTime', 'DateTimeFrom', + * 'RecipientDateTime', 'isAfterpayment', 'Page', 'OrderField => + * [ + * IntDocNumber, DateTime, Weight, Cost, SeatsAmount, CostOnSite, + * CreateTime, EstimatedDeliveryDate, StateId, InfoRegClientBarcodes, RecipientDateTime + * ], + * 'OrderDirection' => [DESC, ASC], 'ScanSheetRef' + * + * @return mixed + */ + public function getDocumentList($params = null) + { + return $this->novaPoshtaApiClient->request('InternetDocument', 'getDocumentList', $params ? $params : null); + } + + /** + * Get document info by ID. + * + * @param string $ref Document ID + * + * @return mixed + */ + public function getDocument($ref) + { + return $this->novaPoshtaApiClient->request('InternetDocument', 'getDocument', array( + 'Ref' => $ref, + )); + } +} \ No newline at end of file From 5ce09fb1f127edc9320a116972bdbaf12aa73805 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 23:39:59 +0300 Subject: [PATCH 12/14] add address service --- src/Common/{FormatService.php => Format.php} | 4 +- .../{LanguageService.php => Language.php} | 6 +- src/Controllers/Api/v1/NovaPoshtaApi2.php | 226 ---------------- .../Api/v1/NovaPoshtaApiClient.php | 12 +- src/Services/AddressService.php | 242 ++++++++++++++++++ src/Services/WarehouseService.php | 53 ---- 6 files changed, 253 insertions(+), 290 deletions(-) rename src/Common/{FormatService.php => Format.php} (87%) rename src/Common/{LanguageService.php => Language.php} (79%) create mode 100644 src/Services/AddressService.php delete mode 100644 src/Services/WarehouseService.php diff --git a/src/Common/FormatService.php b/src/Common/Format.php similarity index 87% rename from src/Common/FormatService.php rename to src/Common/Format.php index 607a26f..5c1a536 100644 --- a/src/Common/FormatService.php +++ b/src/Common/Format.php @@ -4,7 +4,7 @@ use LisDev\Controllers\NovaPoshtaApi2; -class FormatService +class Format { public string $format; /** @@ -14,7 +14,7 @@ class FormatService * * @return NovaPoshtaApi2 */ - public function setFormat($format): FormatService + public function setFormat($format): Format { $this->format = $format; return $this; diff --git a/src/Common/LanguageService.php b/src/Common/Language.php similarity index 79% rename from src/Common/LanguageService.php rename to src/Common/Language.php index c9c4ae9..e3def7a 100644 --- a/src/Common/LanguageService.php +++ b/src/Common/Language.php @@ -2,7 +2,7 @@ namespace LisDev\Common; -class LanguageService +class Language { /** * @var string Language of response @@ -14,9 +14,9 @@ class LanguageService * * @param string $language * - * @return LanguageService + * @return Language */ - public function setLanguage(string $language): LanguageService + public function setLanguage(string $language): Language { $this->language = $language; return $this; diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index f09a1de..703e771 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -139,233 +139,7 @@ public function execute() return $this->request($this->model, $this->method, $this->params); } - /** - * Get cities of company NovaPoshta. - * - * @param int $page Num of page - * @param string $findByString Find city by russian or ukrainian word - * @param string $ref ID of city - * - * @return mixed - */ - public function getCities($page = 0, $findByString = '', $ref = '') - { - return $this->request('Address', 'getCities', array( - 'Page' => $page, - 'FindByString' => $findByString, - 'Ref' => $ref, - )); - } - - /** - * Get warehouses by city. - * - * @param string $cityRef ID of city - * @param int $page - * - * @return mixed - */ - public function getWarehouses($cityRef, $page = 0) - { - return $this->request('Address', 'getWarehouses', array( - 'CityRef' => $cityRef, - 'Page' => $page, - )); - } - - /** - * Get warehouse types. - * - * @return mixed - */ - public function getWarehouseTypes() - { - return $this->request('Address', 'getWarehouseTypes'); - } - - /** - * Get 5 nearest warehouses by array of strings. - * - * @param array $searchStringArray - * - * @return mixed - */ - public function findNearestWarehouse($searchStringArray) - { - $searchStringArray = (array) $searchStringArray; - return $this->request('Address', 'findNearestWarehouse', array( - 'SearchStringArray' => $searchStringArray, - )); - } - - /** - * Get streets list by city and/or search string. - * - * @param string $cityRef ID of city - * @param string $findByString - * @param int $page - * - * @return mixed - */ - public function getStreet($cityRef, $findByString = '', $page = 0) - { - return $this->request('Address', 'getStreet', array( - 'FindByString' => $findByString, - 'CityRef' => $cityRef, - 'Page' => $page, - )); - } - - /** - * Find current area in list of areas. - * - * @param array $areas List of arias, getted from file - * @param string $findByString Area name - * @param string $ref Area Ref ID - * - * @return array - */ - protected function findArea(array $areas, $findByString = '', $ref = '') - { - $data = array(); - if (!$findByString and !$ref) { - return $data; - } - // Try to find current region - foreach ($areas as $key => $area) { - // Is current area found by string or by key - $found = $findByString - ? ((false !== mb_stripos($area['Description'], $findByString)) - or (false !== mb_stripos($area['DescriptionRu'], $findByString)) - or (false !== mb_stripos($area['Area'], $findByString)) - or (false !== mb_stripos($area['AreaRu'], $findByString))) - : ($key == $ref); - if ($found) { - $area['Ref'] = $key; - $data[] = $area; - break; - } - } - return $data; - } - - /** - * Get area by name or by ID. - * - * @param string $findByString Find area by russian or ukrainian word - * @param string $ref Get area by ID - * - * @return array - */ - public function getArea($findByString = '', $ref = '') - { - // Load areas list from file - empty($this->areas) and $this->areas = (include dirname(__FILE__) . '/NovaPoshtaApi2Areas.php'); - $data = $this->findArea($this->areas, $findByString, $ref); - // Error - $error = array(); - empty($data) and $error = array('Area was not found'); - // Return data in same format like NovaPoshta API - return $this->prepare( - array( - 'success' => empty($error), - 'data' => $data, - 'errors' => $error, - 'warnings' => array(), - 'info' => array(), - ) - ); - } - - /** - * Get areas list by city and/or search string. - * - * @param string $ref ID of area - * @param int $page - * - * @return mixed - */ - public function getAreas($ref = '', $page = 0) - { - return $this->request('Address', 'getAreas', array( - 'Ref' => $ref, - 'Page' => $page, - )); - } - - /** - * Find city from list by name of region. - * - * @param array $cities Array from query getCities to NovaPoshta - * @param string $areaName - * - * @return array - */ - protected function findCityByRegion($cities, $areaName) - { - $data = array(); - $areaRef = ''; - // Get region id - $area = $this->getArea($areaName); - $area['success'] and $areaRef = $area['data'][0]['Ref']; - if ($areaRef and is_array($cities['data'])) { - foreach ($cities['data'] as $city) { - if ($city['Area'] == $areaRef) { - $data[] = $city; - } - } - } - return $data; - } - /** - * Get city by name and region (if it needs). - * - * @param string $cityName City's name - * @param string $areaName Region's name - * @param string $warehouseDescription Warehouse description to identiry needed city (if it more than 1 in the area) - * - * @return array Cities's data Can be returned more than 1 city with the same name - */ - public function getCity($cityName, $areaName = '', $warehouseDescription = '') - { - // Get cities by name - $cities = $this->getCities(0, $cityName); - $data = array(); - if (is_array($cities) && is_array($cities['data'])) { - // If cities more then one, calculate current by area name - $data = (count($cities['data']) > 1) - ? $this->findCityByRegion($cities, $areaName) - : array($cities['data'][0]); - } - // Try to identify city by one of warehouses descriptions - if (count($data) > 1 && $warehouseDescription) { - foreach ($data as $cityData) { - $warehouseData = $this->getWarehouse($cityData['Ref'], $warehouseDescription); - $warehouseDescriptions = array( - $warehouseData['data'][0]['Description'], - $warehouseData['data'][0]['DescriptionRu'] - ); - if (in_array($warehouseDescription, $warehouseDescriptions)) { - $data = array($cityData); - break; - } - } - } - // Error - $error = array(); - (!$data) and $error = array('City was not found'); - // Return data in same format like NovaPoshta API - return $this->prepare( - array( - 'success' => empty($error), - 'data' => $data, - 'errors' => $error, - 'warnings' => array(), - 'info' => array(), - ) - ); - } /** * Magic method of calling functions (uses for calling Common Model of NovaPoshta API). diff --git a/src/Controllers/Api/v1/NovaPoshtaApiClient.php b/src/Controllers/Api/v1/NovaPoshtaApiClient.php index 5cfd94c..b226b63 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApiClient.php +++ b/src/Controllers/Api/v1/NovaPoshtaApiClient.php @@ -2,8 +2,8 @@ namespace LisDev\Services; -use LisDev\Common\FormatService; -use LisDev\Common\LanguageService; +use LisDev\Common\Format; +use LisDev\Common\Language; use LisDev\Interfaces\NovaPoshtaApiClientInterface; use LisDev\Models\Model; @@ -26,16 +26,16 @@ class NovaPoshtaApiClient implements NovaPoshtaApiClientInterface protected OutputService $outputService; private ConnectionService $connectionService; private PreparationDataService $preparationDataService; - private LanguageService $languageService; - private FormatService $formatService; + private Language $languageService; + private Format $formatService; public function __construct() { $this->outputService = new OutputService(); $this->connectionService = new ConnectionService(); $this->preparationDataService = new PreparationDataService(); - $this->languageService = new LanguageService(); - $this->formatService = new FormatService(); + $this->languageService = new Language(); + $this->formatService = new Format(); } /** diff --git a/src/Services/AddressService.php b/src/Services/AddressService.php new file mode 100644 index 0000000..7d799bc --- /dev/null +++ b/src/Services/AddressService.php @@ -0,0 +1,242 @@ +preparationDataService = new PreparationDataService(); + $this->novaPoshtaApiClient = new NovaPoshtaApiClient(); + } + /** + * Get cities of company NovaPoshta. + * + * @param int $page Num of page + * @param string $findByString Find city by russian or ukrainian word + * @param string $ref ID of city + * + * @return mixed + */ + public function getCities($page = 0, $findByString = '', $ref = '') + { + return $this->novaPoshtaApiClient->request('Address', 'getCities', array( + 'Page' => $page, + 'FindByString' => $findByString, + 'Ref' => $ref, + )); + } + + /** + * Get warehouses by city. + * + * @param string $cityRef ID of city + * @param int $page + * + * @return mixed + */ + public function getWarehouses($cityRef, $page = 0) + { + return $this->novaPoshtaApiClient->request('Address', 'getWarehouses', array( + 'CityRef' => $cityRef, + 'Page' => $page, + )); + } + + /** + * Get warehouse types. + * + * @return mixed + */ + public function getWarehouseTypes() + { + return $this->novaPoshtaApiClient->request('Address', 'getWarehouseTypes'); + } + + /** + * Get 5 nearest warehouses by array of strings. + * + * @param array $searchStringArray + * + * @return mixed + */ + public function findNearestWarehouse($searchStringArray) + { + $searchStringArray = (array) $searchStringArray; + return $this->novaPoshtaApiClient->request('Address', 'findNearestWarehouse', array( + 'SearchStringArray' => $searchStringArray, + )); + } + + /** + * Get streets list by city and/or search string. + * + * @param string $cityRef ID of city + * @param string $findByString + * @param int $page + * + * @return mixed + */ + public function getStreet($cityRef, $findByString = '', $page = 0) + { + return $this->novaPoshtaApiClient->request('Address', 'getStreet', array( + 'FindByString' => $findByString, + 'CityRef' => $cityRef, + 'Page' => $page, + )); + } + + /** + * Find current area in list of areas. + * + * @param array $areas List of arias, getted from file + * @param string $findByString Area name + * @param string $ref Area Ref ID + * + * @return array + */ + protected function findArea(array $areas, $findByString = '', $ref = '') + { + $data = array(); + if (!$findByString and !$ref) { + return $data; + } + // Try to find current region + foreach ($areas as $key => $area) { + // Is current area found by string or by key + $found = $findByString + ? ((false !== mb_stripos($area['Description'], $findByString)) + or (false !== mb_stripos($area['DescriptionRu'], $findByString)) + or (false !== mb_stripos($area['Area'], $findByString)) + or (false !== mb_stripos($area['AreaRu'], $findByString))) + : ($key == $ref); + if ($found) { + $area['Ref'] = $key; + $data[] = $area; + break; + } + } + return $data; + } + + /** + * Get area by name or by ID. + * + * @param string $findByString Find area by russian or ukrainian word + * @param string $ref Get area by ID + * + * @return array + */ + public function getArea($findByString = '', $ref = '') + { + // Load areas list from file + empty($this->areas) and $this->areas = (include dirname(__FILE__) . '/NovaPoshtaApi2Areas.php'); + $data = $this->findArea($this->areas, $findByString, $ref); + // Error + $error = array(); + empty($data) and $error = array('Area was not found'); + // Return data in same format like NovaPoshta API + return $this->preparationDataService->prepare( + array( + 'success' => empty($error), + 'data' => $data, + 'errors' => $error, + 'warnings' => array(), + 'info' => array(), + ) + ); + } + + /** + * Get areas list by city and/or search string. + * + * @param string $ref ID of area + * @param int $page + * + * @return mixed + */ + public function getAreas($ref = '', $page = 0) + { + return $this->novaPoshtaApiClient->request('Address', 'getAreas', array( + 'Ref' => $ref, + 'Page' => $page, + )); + } + + /** + * Find city from list by name of region. + * + * @param array $cities Array from query getCities to NovaPoshta + * @param string $areaName + * + * @return array + */ + protected function findCityByRegion($cities, $areaName) + { + $data = array(); + $areaRef = ''; + // Get region id + $area = $this->getArea($areaName); + $area['success'] and $areaRef = $area['data'][0]['Ref']; + if ($areaRef and is_array($cities['data'])) { + foreach ($cities['data'] as $city) { + if ($city['Area'] == $areaRef) { + $data[] = $city; + } + } + } + return $data; + } + + /** + * Get city by name and region (if it needs). + * + * @param string $cityName City's name + * @param string $areaName Region's name + * @param string $warehouseDescription Warehouse description to identiry needed city (if it more than 1 in the area) + * + * @return array Cities's data Can be returned more than 1 city with the same name + */ + public function getCity($cityName, $areaName = '', $warehouseDescription = '') + { + // Get cities by name + $cities = $this->getCities(0, $cityName); + $data = array(); + if (is_array($cities) && is_array($cities['data'])) { + // If cities more then one, calculate current by area name + $data = (count($cities['data']) > 1) + ? $this->findCityByRegion($cities, $areaName) + : array($cities['data'][0]); + } + // Try to identify city by one of warehouses descriptions + if (count($data) > 1 && $warehouseDescription) { + foreach ($data as $cityData) { + $warehouseData = $this->getWarehouse($cityData['Ref'], $warehouseDescription); + $warehouseDescriptions = array( + $warehouseData['data'][0]['Description'], + $warehouseData['data'][0]['DescriptionRu'] + ); + if (in_array($warehouseDescription, $warehouseDescriptions)) { + $data = array($cityData); + break; + } + } + } + // Error + $error = array(); + (!$data) and $error = array('City was not found'); + // Return data in same format like NovaPoshta API + return $this->preparationDataService->prepare( + array( + 'success' => empty($error), + 'data' => $data, + 'errors' => $error, + 'warnings' => array(), + 'info' => array(), + ) + ); + } +} \ No newline at end of file diff --git a/src/Services/WarehouseService.php b/src/Services/WarehouseService.php deleted file mode 100644 index e183a40..0000000 --- a/src/Services/WarehouseService.php +++ /dev/null @@ -1,53 +0,0 @@ -preparationDataService = new PreparationDataService(); - } - - /** - * Get one warehouse by city name and warehouse's description. - * - * @param string $cityRef ID of city - * @param string $description Description like in getted by getWarehouses() - * - * @return mixed - * @throws \Exception - */ - public function getWarehouse($cityRef, $description = '') - { - $warehouses = $this->getWarehouses($cityRef); - $error = array(); - $data = array(); - if (is_array($warehouses['data'])) { - $data = $warehouses['data'][0]; - if (count($warehouses['data']) > 1 && $description) { - foreach ($warehouses['data'] as $warehouse) { - if (false !== mb_stripos($warehouse['Description'], $description) - or false !== mb_stripos($warehouse['DescriptionRu'], $description)) { - $data = $warehouse; - break; - } - } - } - } - // Error - (!$data) and $error = 'Warehouse was not found'; - // Return data in same format like NovaPoshta API - return $this->preparationDataService->prepare( - array( - 'success' => empty($error), - 'data' => array($data), - 'errors' => (array) $error, - 'warnings' => array(), - 'info' => array(), - ) - ); - } -} \ No newline at end of file From a6142cc3a167cb482de091e1545a156136be19b2 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 24 Apr 2022 23:45:53 +0300 Subject: [PATCH 13/14] add model counter party service --- README.md | 6 ++- README.ua.md | 6 ++- src/Controllers/Api/v1/NovaPoshtaApi2.php | 50 ------------------ src/Services/AddressService.php | 1 + src/Services/CounterPartyService.php | 62 +++++++++++++++++++++++ src/Services/PrintLinksService.php | 1 + 6 files changed, 72 insertions(+), 54 deletions(-) create mode 100644 src/Services/CounterPartyService.php diff --git a/README.md b/README.md index 8b3459d..e5c16dd 100644 --- a/README.md +++ b/README.md @@ -58,12 +58,14 @@ require '/src/Delivery/NovaPoshtaApi2.php'; ## Создание экземпляра класса Класс по умолчанию находится в namespace `\LisDev\Delivery`. При создании экземпляра класса необходимо или использовать Full Qualified Class Name: + ```php -$np = new \LisDev\Delivery\NovaPoshtaApi2('Ваш_ключ_API_2.0'); +$np = new \LisDev\Controllers\NovaPoshtaApi2('Ваш_ключ_API_2.0'); ``` или указать используемый namespace в секции use: + ```php -use LisDev\Delivery\NovaPoshtaApi2; +use LisDev\Controllers\NovaPoshtaApi2; ... $np = new NovaPoshtaApi2('Ваш_ключ_API_2.0'); ``` diff --git a/README.ua.md b/README.ua.md index 61b3cde..d6290df 100644 --- a/README.ua.md +++ b/README.ua.md @@ -58,12 +58,14 @@ require '/src/Delivery/NovaPoshtaApi2.php'; ## Створення екземпляру класа Клас знаходиться в namespace `\LisDev\Delivery`. При створенні екземпляру класу необхідно або використовувати Full Qualified Class Name: + ```php -$np = new \LisDev\Delivery\NovaPoshtaApi2('Ваш_ключ_API_2.0'); +$np = new \LisDev\Controllers\NovaPoshtaApi2('Ваш_ключ_API_2.0'); ``` або вказати namespace що використовується у секції use: + ```php -use LisDev\Delivery\NovaPoshtaApi2; +use LisDev\Controllers\NovaPoshtaApi2; ... $np = new NovaPoshtaApi2('Ваш_ключ_API_2.0'); ``` diff --git a/src/Controllers/Api/v1/NovaPoshtaApi2.php b/src/Controllers/Api/v1/NovaPoshtaApi2.php index 703e771..dc005fd 100644 --- a/src/Controllers/Api/v1/NovaPoshtaApi2.php +++ b/src/Controllers/Api/v1/NovaPoshtaApi2.php @@ -210,56 +210,6 @@ public function cloneLoyaltyCounterpartySender($cityRef) return $this->request('Counterparty', 'cloneLoyaltyCounterpartySender', array('CityRef' => $cityRef)); } - /** - * getCounterpartyContactPersons() function of model Counterparty. - * - * @param string $ref Counterparty ref - * - * @return mixed - */ - public function getCounterpartyContactPersons($ref) - { - return $this->request('Counterparty', 'getCounterpartyContactPersons', array('Ref' => $ref)); - } - - /** - * getCounterpartyAddresses() function of model Counterparty. - * - * @param string $ref Counterparty ref - * @param int $page - * - * @return mixed - */ - public function getCounterpartyAddresses($ref, $page = 0) - { - return $this->request('Counterparty', 'getCounterpartyAddresses', array('Ref' => $ref, 'Page' => $page)); - } - - /** - * getCounterpartyOptions() function of model Counterparty. - * - * @param string $ref Counterparty ref - * - * @return mixed - */ - public function getCounterpartyOptions($ref) - { - return $this->request('Counterparty', 'getCounterpartyOptions', array('Ref' => $ref)); - } - - /** - * getCounterpartyByEDRPOU() function of model Counterparty. - * - * @param string $edrpou EDRPOU code - * @param string $cityRef City ID - * - * @return mixed - */ - public function getCounterpartyByEDRPOU($edrpou, $cityRef) - { - return $this->request('Counterparty', 'getCounterpartyByEDRPOU', array('EDRPOU' => $edrpou, 'cityRef' => $cityRef)); - } - /** * Check required fields for new InternetDocument and set defaults. * diff --git a/src/Services/AddressService.php b/src/Services/AddressService.php index 7d799bc..14f186a 100644 --- a/src/Services/AddressService.php +++ b/src/Services/AddressService.php @@ -12,6 +12,7 @@ public function __construct() $this->preparationDataService = new PreparationDataService(); $this->novaPoshtaApiClient = new NovaPoshtaApiClient(); } + /** * Get cities of company NovaPoshta. * diff --git a/src/Services/CounterPartyService.php b/src/Services/CounterPartyService.php new file mode 100644 index 0000000..7a52972 --- /dev/null +++ b/src/Services/CounterPartyService.php @@ -0,0 +1,62 @@ +novaPoshtaApiClient = new NovaPoshtaApiClient(); + } + /** + * getCounterpartyContactPersons() function of model Counterparty. + * + * @param string $ref Counterparty ref + * + * @return mixed + */ + public function getCounterpartyContactPersons($ref) + { + return $this->novaPoshtaApiClient->request('Counterparty', 'getCounterpartyContactPersons', array('Ref' => $ref)); + } + + /** + * getCounterpartyAddresses() function of model Counterparty. + * + * @param string $ref Counterparty ref + * @param int $page + * + * @return mixed + */ + public function getCounterpartyAddresses($ref, $page = 0) + { + return $this->novaPoshtaApiClient->request('Counterparty', 'getCounterpartyAddresses', array('Ref' => $ref, 'Page' => $page)); + } + + /** + * getCounterpartyOptions() function of model Counterparty. + * + * @param string $ref Counterparty ref + * + * @return mixed + */ + public function getCounterpartyOptions($ref) + { + return $this->novaPoshtaApiClient->request('Counterparty', 'getCounterpartyOptions', array('Ref' => $ref)); + } + + /** + * getCounterpartyByEDRPOU() function of model Counterparty. + * + * @param string $edrpou EDRPOU code + * @param string $cityRef City ID + * + * @return mixed + */ + public function getCounterpartyByEDRPOU($edrpou, $cityRef) + { + return $this->novaPoshtaApiClient->request('Counterparty', 'getCounterpartyByEDRPOU', array('EDRPOU' => $edrpou, 'cityRef' => $cityRef)); + } +} \ No newline at end of file diff --git a/src/Services/PrintLinksService.php b/src/Services/PrintLinksService.php index 7c67b3c..3314273 100644 --- a/src/Services/PrintLinksService.php +++ b/src/Services/PrintLinksService.php @@ -6,6 +6,7 @@ class PrintLinksService { + protected $key; private PreparationDataService $preparationDataService; private NovaPoshtaApiClient $novaPoshtaApiClient; From 11acae1304885e4f2530abe349b68043aac04f35 Mon Sep 17 00:00:00 2001 From: VitalyZibulski Date: Sun, 1 May 2022 20:55:42 +0300 Subject: [PATCH 14/14] fixes --- src/Common/Format.php | 4 ++-- src/Services/AddressService.php | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Common/Format.php b/src/Common/Format.php index 5c1a536..78b311a 100644 --- a/src/Common/Format.php +++ b/src/Common/Format.php @@ -6,7 +6,7 @@ class Format { - public string $format; + protected string $format; /** * Setter for format property. * @@ -14,7 +14,7 @@ class Format * * @return NovaPoshtaApi2 */ - public function setFormat($format): Format + public function setFormat(string $format): Format { $this->format = $format; return $this; diff --git a/src/Services/AddressService.php b/src/Services/AddressService.php index 14f186a..805f95e 100644 --- a/src/Services/AddressService.php +++ b/src/Services/AddressService.php @@ -64,9 +64,9 @@ public function getWarehouseTypes() * * @return mixed */ - public function findNearestWarehouse($searchStringArray) + public function findNearestWarehouse(array $searchStringArray) { - $searchStringArray = (array) $searchStringArray; + $searchStringArray = $searchStringArray; return $this->novaPoshtaApiClient->request('Address', 'findNearestWarehouse', array( 'SearchStringArray' => $searchStringArray, )); @@ -107,7 +107,6 @@ protected function findArea(array $areas, $findByString = '', $ref = '') } // Try to find current region foreach ($areas as $key => $area) { - // Is current area found by string or by key $found = $findByString ? ((false !== mb_stripos($area['Description'], $findByString)) or (false !== mb_stripos($area['DescriptionRu'], $findByString))