Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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
16 changes: 8 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<testsuites>
<testsuite name="API Anaf Tests Suite">
<directory>./tests/</directory>
Expand Down
24 changes: 16 additions & 8 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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}");
}

Expand All @@ -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'];
Expand Down
8 changes: 4 additions & 4 deletions tests/Integrations/FlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions tests/Unit/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}