Skip to content

Commit 618894a

Browse files
committed
Ares: support new API
1 parent ca8ca21 commit 618894a

File tree

88 files changed

+9156
-3060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+9156
-3060
lines changed

.doc/payment.png

2.75 KB
Loading

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
.github export-ignore
22
.gitattributes export-ignore
33
.gitignore export-ignore
4+
.doc export-ignore
45
changelog.md export-ignore
56
tests export-ignore
67
phpstan.neon export-ignore
78
README.md export-ignore
9+
example export-ignore

.github/workflows/static-analysis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Static Analysis (only informative)
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
phpstan:
10+
name: PHPStan
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: 8.0
17+
coverage: none
18+
19+
- run: composer install --no-progress --prefer-dist
20+
- run: composer phpstan -- --no-progress
21+
continue-on-error: true # is only informative

.github/workflows/tests.yml

+32-17
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,36 @@ jobs:
2828
name: output
2929
path: tests/**/output
3030

31+
lowest_dependencies:
32+
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
php: ['8.0', '8.1', '8.2']
36+
name: PHP Lowest Dependencies ${{ matrix.php }}
37+
steps:
38+
- uses: actions/checkout@v3
39+
- uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: ${{ matrix.php }}
42+
extensions: curl, simplexml, json
43+
coverage: none
3144

32-
# code_coverage:
33-
# name: Code Coverage
34-
# runs-on: ubuntu-latest
35-
# steps:
36-
# - uses: actions/checkout@v3
37-
# - uses: shivammathur/setup-php@v2
38-
# with:
39-
# php-version: 8.0
40-
# extensions: json, mbstring, tokenizer, fileinfo
41-
# coverage: none
42-
#
43-
# - run: composer install --no-progress --prefer-dist
44-
# - run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
45-
# - run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
46-
# - env:
47-
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48-
# run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
45+
- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
46+
- run: composer tests
47+
48+
code_coverage:
49+
name: Code Coverage
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v3
53+
- uses: shivammathur/setup-php@v2
54+
with:
55+
php-version: 8.0
56+
coverage: none
57+
58+
- run: composer install --no-progress --prefer-dist
59+
- run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
60+
- run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
61+
- env:
62+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: php php-coveralls.phar --verbose --config tests/.coveralls.yml

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
composer.lock
22
/**/output/
33
/vendor/
4+
/AresRestApi-verejne.json
5+
/coverage.html

README.md

+37-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Ares
2-
31
[![Downloads this Month](https://img.shields.io/packagist/dm/h4kuna/ares.svg)](https://packagist.org/packages/h4kuna/ares)
42
[![Latest Stable Version](https://poser.pugx.org/h4kuna/ares/v/stable?format=flat)](https://packagist.org/packages/h4kuna/ares)
53
[![Coverage Status](https://coveralls.io/repos/github/h4kuna/ares/badge.svg?branch=master)](https://coveralls.io/github/h4kuna/ares?branch=master)
@@ -8,54 +6,72 @@
86

97
More information about versions is in [changelog](changelog.md).
108

9+
## Support development by QR code
10+
11+
Use QR code or sponsor button where is link on my revolut.
12+
13+
Thank you :)
14+
15+
![QR payment](./.doc/payment.png)
16+
17+
1118
## Installation to project
1219

1320
The best way to install h4kuna/ares is using Composer:
21+
1422
```sh
15-
$ composer require h4kuna/ares
23+
composer require h4kuna/ares
1624
```
1725

1826
Download information about customer via his IN.
1927

20-
## Example
28+
## ARES
29+
30+
[Homepage](https://ares.gov.cz/) and official [ARES documentation](https://www.mfcr.cz/assets/attachments/2023-08-01_ARES-Technicka-dokumentace-Katalog-verejnych-sluzeb.pdf). And json [API](https://www.mfcr.cz/assets/attachments/2023-08-01_AresRestApi-verejne.json)
2131

22-
Load data by one identification number
32+
Load data by one identification number.
2333

2434
```php
25-
$ares = (new h4kuna\Ares\AresFactory())->create();
35+
use h4kuna\Ares;
36+
$ares = (new Ares\AresFactory())->create();
2637
try {
2738
$response = $ares->loadBasic('87744473');
28-
/* @var $response h4kuna\Ares\Basic\Data */
39+
/* @var $response Ares\Ares\Core\Data */
2940
var_dump($response);
30-
} catch (h4kuna\Ares\Exceptions\IdentificationNumberNotFoundException $e) {
41+
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
3142
// log identification number, why is bad? Or make nothing.
43+
} catch (Ares\Exceptions\ServerResponseException $e) {
44+
// no response from server or broken json
3245
}
3346
```
3447

35-
Load data by many identification numbers
48+
Load data by many identification numbers. Limit by ARES service is set to 100 items, but library chunk it and check duplicity.
3649

3750
```php
38-
/** @var h4kuna\Ares\Ares $ares */
39-
$numbers = ['25596641', '26713250', '27082440', '11111111'];
40-
$res = $ares->loadBasicMulti($numbers);
51+
use h4kuna\Ares;
52+
/** @var Ares\Ares $ares */
53+
$numbers = ['one' => '25596641', 'two' => '26713250', 'three' => '27082440', 'four' => '11111111'];
4154

42-
if ($res[$ares::RESULT_FAILED] !== []) {
43-
var_dump($res[$ares::RESULT_FAILED]);
44-
}
45-
46-
foreach ($res[$ares::RESULT_SUCCESS] as $r) {
47-
var_dump($r->company);
55+
try {
56+
foreach ($ares->loadBasicMulti($numbers) as $name => $r) {
57+
var_dump($name, $r->company);
58+
}
59+
} catch (Ares\Exceptions\ServerResponseException $e) {
60+
// no response from server or broken json
4861
}
4962
```
5063

51-
## Data Box
64+
## Data Box (datavá schánka)
65+
66+
[Manual](https://www.mojedatovaschranka.cz/sds/p/download/sds_webove_sluzby.pdf#view=Fit)
5267

5368
```php
54-
/** @var h4kuna\Ares\Ares $ares */
69+
use h4kuna\Ares;
70+
/** @var Ares\Ares $ares */
5571
try {
5672
$response = $ares->loadDataBox('87744473');
5773
var_dump($response->ISDS);
58-
} catch (h4kuna\Ares\Exceptions\ConnectionException $e) {
74+
} catch (h4kuna\Ares\Exceptions\ServerResponseException $e) {
5975
// catch error
6076
}
6177
```

bin/adis

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
use h4kuna\Ares;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$TIN = trim($argv[1] ?? 'CZ27082440');
9+
10+
$adis = (new Ares\AresFactory())->create()->getAdis();
11+
12+
$subject = $adis->statusBusinessSubject($TIN);
13+
14+
dump($subject);
15+
dump('Nalezen', $subject->exists);
16+
dump('Je spolehlivý plátce', $subject->reliable);
17+
dump('Je plátce DPH', $subject->isVatPayer);

bin/endpoints

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
use h4kuna\Ares;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$IN = trim($argv[1] ?? '27082440');
9+
10+
$ares = (new Ares\AresFactory())->create();
11+
try {
12+
$response = $ares->loadBasic($IN);
13+
/* @var $response Ares\Ares\Core\Data */
14+
$response->original = null;
15+
dump($response);
16+
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
17+
dumpe($e->getMessage());
18+
// log identification number, why is bad? Or make nothing.
19+
} catch (Ares\Exceptions\ServerResponseException $e) {
20+
// no response from server or broken json
21+
dumpe($e->getMessage());
22+
}
23+
24+
foreach ($response->sources as $name => $exists) {
25+
if ($exists !== true || Ares\Ares\Helper::endpointExists($name) === false) {
26+
continue;
27+
}
28+
dump(Ares\Ares\Helper::prepareUrl($name, $IN));
29+
30+
try {
31+
$result = $ares->getAresClient()->useEndpoint($name, $IN);
32+
dump($result);
33+
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
34+
// log identification number, why is bad? Or make nothing.
35+
} catch (Ares\Exceptions\ServerResponseException $e) {
36+
// no response from server or broken json
37+
}
38+
}

bin/legal-form

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
use h4kuna\Ares;
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
$ares = (new Ares\AresFactory())->create();
9+
$result = $ares->getAresClient()->searchEndpoint(Ares\Ares\Sources::DIAL, [
10+
'kodCiselniku' => 'PravniForma',
11+
'zdrojCiselniku' => 'res',
12+
])->ciselniky[0]->polozkyCiselniku;
13+
14+
foreach ($result as $item) {
15+
dump($item);
16+
}

changelog.md

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
1-
v2.0.0
2-
======
1+
# v3.0.0
2+
3+
- podpora nového API ARES2
4+
- v [bin](./bin) jsou spustitelné ukázky, jak se dostat na číselníky a jak na ostatní endpointy
5+
- pro IČO je vyžadován formát \d{8}, pokud je kratší, knihovna sama doplní nuly zleva
6+
- očekávám že se změní url API, pro tento případ je připravená `public static h4kuna\Ares\Ares\Helper::$baseUrl`, kterou lze nahradit, bez nutnosti vyčkávat na nový release
7+
- podobně lze dopnit nebo upravit url adresy endpointů
8+
- php 8.0+
9+
10+
### Třidy
11+
12+
- h4kuna\Ares\Ares
13+
- metoda `loadBasic()` stále vrací [Data](./src/Ares/Core/Data.php)
14+
- metoda `loadBasicMulti()`
15+
- nově vrací Generator nikoliv pole
16+
- vrací jen existující záznamy, třída Error byla smazána, nemá náhradu
17+
- počet IČO není omezen, interně se rozdělí na dávky po 100, záznamech a ještě před tím se odeberou duplicity, při iteraci duplicity zůstanou, jen objekty budou mít stejné reference
18+
- bylo zachováno pojmenování, vstupem je `['foo' => 123456]`, název `foo` bude jako klíč při iteraci
19+
20+
21+
- h4kuna\Ares\Ares\Core\Data
22+
- zmizela metoda `psu()` bez náhrady, podobné informace jsou ve vlastnosti `$sources`
23+
- zmizela metoda `isGroupVat()`, skupinové DPH nelze zjistit. Co se týče správnosti DIČ, [chystá se náprava](https://github.com/h4kuna/ares/issues/30#issuecomment-1719170527)
24+
- odstraněné vlastnosti `$court`, `$file_number`, `$court_all` jsou dostupné na jiném endpointu, `Sources::SERVICE_VR`
25+
- ~~DIČ je nově bez prefixu `CZ`~~, vlastnost `$tin` z důvodu zpětné kompatibility, prefix nese, ~~nová vlastnost `$vat_id` prefix nemá~~, vlastnost jsem odebral, `CZ` opět přidali
26+
- vlastnost `$created` je podle mě momentálně rozbitá, pro [Alzu](https://ares.gov.cz/ekonomicke-subjekty-v-be/rest/ekonomicke-subjekty/27082440) datumVzniku vrací `2023-09-04`, v registru ekonomických subjektů vrací [2003-08-26](https://ares.gov.cz/ekonomicke-subjekty-v-be/rest/ekonomicke-subjekty-res/27082440) (nahlášeno)
27+
- byl změněn namespace pro `h4kuna\Ares\Basic\Data`, ale [aliases.php](./src/aliases.php) zajistí zpětnou kompatibilitu a bude hlásit aby jste si třídu přejmnovali, nicméně stará třída bude fungovat
28+
- už není možnost do metody `toArray()` předat vlastní pole pro úpravu mapování
29+
- přidané vlastnosti `$country` a `$country_code`
30+
31+
- h4kuna\Ares\Exceptions\ConnectionException
32+
- nastavena jako deprecated, zpětně funkční
33+
- nahrazena h4kuna\Ares\Exceptions\ServerResponseException
34+
35+
### Závěrem
36+
37+
`Ares::loadBasic()` pokud si pohlídáte s jakými vlastnostmi pracujete a nebudou tam ty smazané, tak je to zpětně kompatibilní. Vstup je zpětně kompatibilní.
38+
39+
`Ares::loadBasicMulti()` je potřeba vzít v potaz že to je zpětně nekompatibilní a nově se vrací Generator. Vstup je zpětně kompatibilní.
40+
41+
Přidal jsem ADIS, služba která ověří zda se jedná o plátce DPH, identifikovanou osobu nebo neplátce DPH. U plátce vrátí, zda se jedná o spolehlivého plátce DPH. Ukázka je v [bin/adis](./bin/adis).
42+
43+
### Chování validace pomocí ADIS
44+
45+
| | ARES | ADIS (Data::$adis::$exists) | Data::$vat_payer | Data::$tin | Spolehlivý plátce DPH Data::$adis::$reliable |
46+
|----------------------|-----------|-----------------------------|------------------|------------|----------------------------------------------|
47+
| Plátce DPH | vrací DIČ | Existuje (true) | true | vyplněno | true/false |
48+
| Skupinové DPH | vrátí DIČ | Neexistuje (false) | true | null | null |
49+
| Identifikovaná osoba | vrátí DIČ | Existuje (true) | false | vyplněno | null |
50+
| neplátce | null | null | false | null | null |
51+
52+
# v2.0.0
53+
354
- remove support php < 7.4
455
- serialized date use RFC3339 instead of ISO8601, because ISO is deprecated by php
556
- removed method Ares::getData()
@@ -10,19 +61,18 @@ v2.0.0
1061
- prepared AresFactory::create() for instance Ares class
1162
- Data::$tin is null if value is Skupinove_DPH
1263

13-
v1.4.0
14-
======
64+
# v1.4.0
65+
1566
- remove support php < 7.1
1667
- exceptions move to files -> one class is one file and change namespace
1768

69+
# v1.3.0
1870

19-
v1.3.0
20-
======
2171
- remove support for php 5.5
2272
- add Factory provide new instances Guzzle, Data, DataProvider
2373

24-
v1.2.0
25-
======
74+
# v1.2.0
75+
2676
- interface IData was removed
2777
- change data keys:
2878
- person -> is_person
@@ -33,15 +83,15 @@ v1.2.0
3383
- class Data extends Messenger
3484
- class Data suggest property
3585

36-
v1.1.3
37-
======
86+
# v1.1.3
87+
3888
- method Ares::loadData throw IdentificationNumberNotFoundException if find nothing
3989
- rename InNotFoundExceptions -> IdentificationNumberNotFoundException
4090
- rename vat_pay -> vat_payer and interface IData
4191
- try download exists item if is faild try download item with non-exists parameter
4292

43-
v1.1.2
44-
======
93+
# v1.1.2
94+
4595
- method Ares::loadData throw InNotFoundExceptions if find nothing
4696
- attribute vat_pay in Data is bool instanceof empty string and string 1
4797
- attribute created in Data is Datetime instanceof ISO date

0 commit comments

Comments
 (0)