From a042d864ae9eee23231ba1dbaf28e7179ac9466a Mon Sep 17 00:00:00 2001 From: marius Date: Mon, 19 May 2025 12:29:05 +0300 Subject: [PATCH 1/4] Update API URL to v9 and adjust CIF limit to 100 --- src/Http.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Http.php b/src/Http.php index 813529f..a4bce02 100644 --- a/src/Http.php +++ b/src/Http.php @@ -7,11 +7,11 @@ class Http { - /** @var string API URL for v8 */ - private const apiURL = 'https://webservicesp.anaf.ro/PlatitorTvaRest/api/v8/ws/tva'; + /** @var string API URL for v9 */ + private const apiURL = 'https://webservicesp.anaf.ro/api/PlatitorTvaRest/v9/tva'; /** @var int Limit for one time call */ - public const CIF_LIMIT = 500; + public const CIF_LIMIT = 100; /** @var int Max. number of retries */ public const RETRIES_LIMIT = 5; @@ -31,7 +31,7 @@ public static function call(array $cifs, int $tryCount = 0) { // Limit maxim numbers of cifs if(count($cifs) >= self::CIF_LIMIT) { - throw new Exceptions\LimitExceeded('You can check one time up to 500 cifs.'); + throw new Exceptions\LimitExceeded('You can check one time up to 100 cifs.'); } // Make request From c968f3e29f04d81ceaf25f31358d7f6fbbebf50d Mon Sep 17 00:00:00 2001 From: marius Date: Mon, 19 May 2025 12:36:12 +0300 Subject: [PATCH 2/4] Enhance error handling in HTTP response processing --- src/Http.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Http.php b/src/Http.php index a4bce02..cfa8105 100644 --- a/src/Http.php +++ b/src/Http.php @@ -53,7 +53,15 @@ public static function call(array $cifs, int $tryCount = 0) curl_close($curl); // Check http code - if (!isset($info['http_code']) || $info['http_code'] !== 200) { + if (!isset($info['http_code'])) { + throw new Exceptions\ResponseFailed("Missing response status code"); + } + + if ($info['http_code'] === 400) { + throw new Exceptions\ResponseFailed("Bad request: {$response}"); + } + + if ($info['http_code'] !== 200) { throw new Exceptions\ResponseFailed("Response status: {$info['http_code']} | Response body: {$response}"); } @@ -71,9 +79,9 @@ public static function call(array $cifs, int $tryCount = 0) throw new Exceptions\ResponseFailed("Json parse error | Response body: {$response}"); } - // Check success stats - if ("SUCCESS" !== $responseData['message'] || 200 !== $responseData['cod']) { - throw new Exceptions\RequestFailed("Response message: {$responseData['message']} | Response body: {$response}"); + // Check if we have the expected structure + if (!isset($responseData['found'])) { + throw new Exceptions\RequestFailed("Invalid response format - missing 'found' field | Response body: {$response}"); } return $responseData['found']; From 019a669c920b3719f376b5cd55882c3a3ff897a1 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 21 May 2025 15:00:21 +0300 Subject: [PATCH 3/4] Update test cases for address validation and adjust CIF limit to 100 --- phpunit.xml.dist | 16 ++++++++-------- tests/Integrations/FlowTest.php | 8 ++++---- tests/Unit/HttpTest.php | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e4565ca..3099c06 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,14 @@ - - + + src/ - - - ./tests - ./vendor - - + + ./tests + ./vendor + + + ./tests/ diff --git a/tests/Integrations/FlowTest.php b/tests/Integrations/FlowTest.php index 075f450..ad761d8 100644 --- a/tests/Integrations/FlowTest.php +++ b/tests/Integrations/FlowTest.php @@ -45,9 +45,9 @@ public function testAddressParser() $anaf->addCif("RO14399840"); $results = $anaf->first(); - $this->assertEquals("Ilfov", $results->getAddress()->getCounty()); - $this->assertEquals("Oraş Voluntari", $results->getAddress()->getCity()); - $this->assertEquals("Şos. Bucureşti Nord", $results->getAddress()->getStreet()); - $this->assertEquals("15-23", $results->getAddress()->getStreetNumber()); + $this->assertEquals("Municipiul Bucureşti", $results->getAddress()->getCounty()); + $this->assertEquals("Sector 2", $results->getAddress()->getCity()); + $this->assertEquals("Gara Herăstrău", $results->getAddress()->getStreet()); + $this->assertEquals("6", $results->getAddress()->getStreetNumber()); } } diff --git a/tests/Unit/HttpTest.php b/tests/Unit/HttpTest.php index ab2dd38..7321077 100644 --- a/tests/Unit/HttpTest.php +++ b/tests/Unit/HttpTest.php @@ -9,8 +9,8 @@ class HttpTest extends TestCase public function testCifLimitException() { $this->expectException(Exceptions\LimitExceeded::class); - $this->expectExceptionMessage("You can check one time up to 500 cifs."); + $this->expectExceptionMessage("You can check one time up to 100 cifs."); - Http::call(array_fill(0, 501, '123456')); + Http::call(array_fill(0, 101, '123456')); } } From 4f65e2e85014012e6a795dd469648cf0b62838f4 Mon Sep 17 00:00:00 2001 From: marius Date: Wed, 21 May 2025 15:12:56 +0300 Subject: [PATCH 4/4] Update README.md to reflect new CUI limit of 100 and API documentation for v9 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1d1bfdb..1c6a3e5 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ $raspuns = $anaf->get(); ``` # Limite -Poti solicita raspuns pentru maxim 500 de CUI-uri simultan cu o rata de 1 request / secunda. +Poti solicita raspuns pentru maxim 100 de CUI-uri simultan cu o rata de 1 request / secunda. # Requirements * PHP >= 7.1 | >= 8 @@ -114,7 +114,7 @@ Poti solicita raspuns pentru maxim 500 de CUI-uri simultan cu o rata de 1 reques # Exceptii: -* Itrack\Anaf\Exceptions\LimitExceeded - Ai depasit limita de 500 de CUI-uri / request; +* Itrack\Anaf\Exceptions\LimitExceeded - Ai depasit limita de 100 de CUI-uri / request; * Itrack\Anaf\Exceptions\ResponseFailed - Raspunsul primit de la ANAF nu este in format JSON, exceptia returneaza body-ul raspunsului pentru a fi verificat manual; * Itrack\Anaf\Exceptions\RequestFailed - Raspunsul primit de la ANAF nu are status de succes, verifica manual raspunsul primit in exceptie. @@ -125,4 +125,4 @@ Versiunea 2 nu este compatibila cu versiunea 3, daca aveti o implementare veche, [![Contribuitori](https://contributors-img.firebaseapp.com/image?repo=itrack/anaf)](https://github.com/itrack/anaf/graphs/contributors) # Linkuri utile -https://webservicesp.anaf.ro/PlatitorTvaRest/api/v8/ +https://static.anaf.ro/static/10/Anaf/Informatii_R/Servicii_web/doc_WS_V9.txt