Skip to content

Commit 7a674e1

Browse files
authored
Merge pull request #29 from edrep/upgrade-to-v9
Upgrade to ANAF API v9
2 parents f272c18 + 4f65e2e commit 7a674e1

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ $raspuns = $anaf->get();
104104
```
105105

106106
# Limite
107-
Poti solicita raspuns pentru maxim 500 de CUI-uri simultan cu o rata de 1 request / secunda.
107+
Poti solicita raspuns pentru maxim 100 de CUI-uri simultan cu o rata de 1 request / secunda.
108108

109109
# Requirements
110110
* PHP >= 7.1 | >= 8
@@ -114,7 +114,7 @@ Poti solicita raspuns pentru maxim 500 de CUI-uri simultan cu o rata de 1 reques
114114

115115
# Exceptii:
116116

117-
* Itrack\Anaf\Exceptions\LimitExceeded - Ai depasit limita de 500 de CUI-uri / request;
117+
* Itrack\Anaf\Exceptions\LimitExceeded - Ai depasit limita de 100 de CUI-uri / request;
118118
* Itrack\Anaf\Exceptions\ResponseFailed - Raspunsul primit de la ANAF nu este in format JSON, exceptia returneaza body-ul raspunsului pentru a fi verificat manual;
119119
* Itrack\Anaf\Exceptions\RequestFailed - Raspunsul primit de la ANAF nu are status de succes, verifica manual raspunsul primit in exceptie.
120120

@@ -125,4 +125,4 @@ Versiunea 2 nu este compatibila cu versiunea 3, daca aveti o implementare veche,
125125
[![Contribuitori](https://contributors-img.firebaseapp.com/image?repo=itrack/anaf)](https://github.com/itrack/anaf/graphs/contributors)
126126

127127
# Linkuri utile
128-
https://webservicesp.anaf.ro/PlatitorTvaRest/api/v8/
128+
https://static.anaf.ro/static/10/Anaf/Informatii_R/Servicii_web/doc_WS_V9.txt

phpunit.xml.dist

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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">
3-
<coverage includeUncoveredFiles="true">
4-
<include>
3+
<filter>
4+
<whitelist>
55
<directory suffix=".php">src/</directory>
6-
</include>
7-
<exclude>
8-
<directory>./tests</directory>
9-
<directory>./vendor</directory>
10-
</exclude>
11-
</coverage>
6+
<exclude>
7+
<directory>./tests</directory>
8+
<directory>./vendor</directory>
9+
</exclude>
10+
</whitelist>
11+
</filter>
1212
<testsuites>
1313
<testsuite name="API Anaf Tests Suite">
1414
<directory>./tests/</directory>

src/Http.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
class Http
99
{
10-
/** @var string API URL for v8 */
11-
private const apiURL = 'https://webservicesp.anaf.ro/PlatitorTvaRest/api/v8/ws/tva';
10+
/** @var string API URL for v9 */
11+
private const apiURL = 'https://webservicesp.anaf.ro/api/PlatitorTvaRest/v9/tva';
1212

1313
/** @var int Limit for one time call */
14-
public const CIF_LIMIT = 500;
14+
public const CIF_LIMIT = 100;
1515

1616
/** @var int Max. number of retries */
1717
public const RETRIES_LIMIT = 5;
@@ -31,7 +31,7 @@ public static function call(array $cifs, int $tryCount = 0)
3131
{
3232
// Limit maxim numbers of cifs
3333
if(count($cifs) >= self::CIF_LIMIT) {
34-
throw new Exceptions\LimitExceeded('You can check one time up to 500 cifs.');
34+
throw new Exceptions\LimitExceeded('You can check one time up to 100 cifs.');
3535
}
3636

3737
// Make request
@@ -53,7 +53,15 @@ public static function call(array $cifs, int $tryCount = 0)
5353
curl_close($curl);
5454

5555
// Check http code
56-
if (!isset($info['http_code']) || $info['http_code'] !== 200) {
56+
if (!isset($info['http_code'])) {
57+
throw new Exceptions\ResponseFailed("Missing response status code");
58+
}
59+
60+
if ($info['http_code'] === 400) {
61+
throw new Exceptions\ResponseFailed("Bad request: {$response}");
62+
}
63+
64+
if ($info['http_code'] !== 200) {
5765
throw new Exceptions\ResponseFailed("Response status: {$info['http_code']} | Response body: {$response}");
5866
}
5967

@@ -71,9 +79,9 @@ public static function call(array $cifs, int $tryCount = 0)
7179
throw new Exceptions\ResponseFailed("Json parse error | Response body: {$response}");
7280
}
7381

74-
// Check success stats
75-
if ("SUCCESS" !== $responseData['message'] || 200 !== $responseData['cod']) {
76-
throw new Exceptions\RequestFailed("Response message: {$responseData['message']} | Response body: {$response}");
82+
// Check if we have the expected structure
83+
if (!isset($responseData['found'])) {
84+
throw new Exceptions\RequestFailed("Invalid response format - missing 'found' field | Response body: {$response}");
7785
}
7886

7987
return $responseData['found'];

tests/Integrations/FlowTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public function testAddressParser()
4545
$anaf->addCif("RO14399840");
4646
$results = $anaf->first();
4747

48-
$this->assertEquals("Ilfov", $results->getAddress()->getCounty());
49-
$this->assertEquals("Oraş Voluntari", $results->getAddress()->getCity());
50-
$this->assertEquals("Şos. Bucureşti Nord", $results->getAddress()->getStreet());
51-
$this->assertEquals("15-23", $results->getAddress()->getStreetNumber());
48+
$this->assertEquals("Municipiul Bucureşti", $results->getAddress()->getCounty());
49+
$this->assertEquals("Sector 2", $results->getAddress()->getCity());
50+
$this->assertEquals("Gara Herăstrău", $results->getAddress()->getStreet());
51+
$this->assertEquals("6", $results->getAddress()->getStreetNumber());
5252
}
5353
}

tests/Unit/HttpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class HttpTest extends TestCase
99
public function testCifLimitException()
1010
{
1111
$this->expectException(Exceptions\LimitExceeded::class);
12-
$this->expectExceptionMessage("You can check one time up to 500 cifs.");
12+
$this->expectExceptionMessage("You can check one time up to 100 cifs.");
1313

14-
Http::call(array_fill(0, 501, '123456'));
14+
Http::call(array_fill(0, 101, '123456'));
1515
}
1616
}

0 commit comments

Comments
 (0)