Skip to content

Commit

Permalink
Ares: support new API
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Sep 12, 2023
1 parent ca8ca21 commit 1df6d2f
Show file tree
Hide file tree
Showing 67 changed files with 8,428 additions and 2,940 deletions.
Binary file added .doc/payment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.doc export-ignore
changelog.md export-ignore
tests export-ignore
phpstan.neon export-ignore
README.md export-ignore
example export-ignore
21 changes: 21 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Static Analysis (only informative)

on:
push:
branches:
- master

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
- run: composer phpstan -- --no-progress
continue-on-error: true # is only informative
49 changes: 32 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,36 @@ jobs:
name: output
path: tests/**/output

lowest_dependencies:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.0', '8.1', '8.2']
name: PHP Lowest Dependencies ${{ matrix.php }}
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, simplexml, json
coverage: none

# code_coverage:
# name: Code Coverage
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: shivammathur/setup-php@v2
# with:
# php-version: 8.0
# extensions: json, mbstring, tokenizer, fileinfo
# coverage: none
#
# - run: composer install --no-progress --prefer-dist
# - run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
# - run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
# - env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
- run: composer tests

code_coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
- run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
- run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
- env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
composer.lock
/**/output/
/vendor/
/AresRestApi-verejne.json
/coverage.html
54 changes: 34 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Ares

[![Downloads this Month](https://img.shields.io/packagist/dm/h4kuna/ares.svg)](https://packagist.org/packages/h4kuna/ares)
[![Latest Stable Version](https://poser.pugx.org/h4kuna/ares/v/stable?format=flat)](https://packagist.org/packages/h4kuna/ares)
[![Coverage Status](https://coveralls.io/repos/github/h4kuna/ares/badge.svg?branch=master)](https://coveralls.io/github/h4kuna/ares?branch=master)
Expand All @@ -8,54 +6,70 @@

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

## Support development by QR code

Use QR code or sponsor button where is link on my revolut.

Thank you :)

![QR payment](./.doc/payment.png)


## Installation to project

The best way to install h4kuna/ares is using Composer:

```sh
$ composer require h4kuna/ares
composer require h4kuna/ares
```

Download information about customer via his IN.

## Example
## ARES

Load data by one identification number

```php
$ares = (new h4kuna\Ares\AresFactory())->create();
use h4kuna\Ares;
$ares = (new Ares\AresFactory())->create();
try {
$response = $ares->loadBasic('87744473');
/* @var $response h4kuna\Ares\Basic\Data */
/* @var $response Ares\Ares\Core\Data */
var_dump($response);
} catch (h4kuna\Ares\Exceptions\IdentificationNumberNotFoundException $e) {
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
// log identification number, why is bad? Or make nothing.
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}
```

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

```php
/** @var h4kuna\Ares\Ares $ares */
$numbers = ['25596641', '26713250', '27082440', '11111111'];
$res = $ares->loadBasicMulti($numbers);
use h4kuna\Ares;
/** @var Ares\Ares $ares */
$numbers = ['one' => '25596641', 'two' => '26713250', 'three' => '27082440', 'four' => '11111111'];

if ($res[$ares::RESULT_FAILED] !== []) {
var_dump($res[$ares::RESULT_FAILED]);
}

foreach ($res[$ares::RESULT_SUCCESS] as $r) {
var_dump($r->company);
try {
foreach ($ares->loadBasicMulti($numbers) as $name => $r) {
var_dump($name, $r->company);
}
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}
```

## Data Box
## Data Box (datavá schánka)

[Manual](https://www.mojedatovaschranka.cz/sds/p/download/sds_webove_sluzby.pdf#view=Fit)

```php
/** @var h4kuna\Ares\Ares $ares */
use h4kuna\Ares;
/** @var Ares\Ares $ares */
try {
$response = $ares->loadDataBox('87744473');
var_dump($response->ISDS);
} catch (h4kuna\Ares\Exceptions\ConnectionException $e) {
} catch (h4kuna\Ares\Exceptions\ServerResponseException $e) {
// catch error
}
```
36 changes: 36 additions & 0 deletions bin/endpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use h4kuna\Ares;

require __DIR__ . '/../vendor/autoload.php';

$IN = trim($argv[1] ?? '27082440');

$ares = (new Ares\AresFactory())->create();
try {
$response = $ares->loadBasic($IN);
/* @var $response Ares\Ares\Core\Data */
$response->original = null;
dump($response);
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
// log identification number, why is bad? Or make nothing.
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}

foreach ($response->sources as $name => $exists) {
if ($exists === false || Ares\Ares\Helper::endpointExists($name) === false) {
continue;
}
dump(Ares\Ares\Helper::prepareUrl($name, $IN));

try {
$result = $ares->getAresClient()->useEndpoint($name, $IN);
dump($result);
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
// log identification number, why is bad? Or make nothing.
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}
}
16 changes: 16 additions & 0 deletions bin/legal-form
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use h4kuna\Ares;

require __DIR__ . '/../vendor/autoload.php';

$ares = (new Ares\AresFactory())->create();
$result = $ares->getAresClient()->searchEndpoint(Ares\Ares\Sources::DIAL, [
'kodCiselniku' => 'PravniForma',
'zdrojCiselniku' => 'res',
])->ciselniky[0]->polozkyCiselniku;

foreach ($result as $item) {
dump($item);
}
65 changes: 53 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
v2.0.0
======
# v3.0.0

- podpora nového API ARES2
- v [bin](./bin) jsou spustitelné ukázky, jak se dostat na číselníky a jak na ostatní endpointy
- pro IČO je vyžadován formát \d{8}, pokud je kratší, knihovna sama doplní nuly zleva
- 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
- podobně lze dopnit nebo upravit url adresy endpointů
- php 8.0+

### Třidy

- h4kuna\Ares\Ares
- metoda `loadBasic()` nově vrací [DataInterface](./src/Ares/Core/DataInterface.php) implementace je původní [Data](./src/Ares/Core/Data.php)
- metoda `loadBasicMulti()`
- nově vrací Generator nikoliv pole
- vrací jen existující záznamy, třída Error byla smazána, nemá náhradu
- 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
- bylo zachováno pojmenování, vstupem je `['foo' => 123456]`, název `foo` bude jako klíč při iteraci


- h4kuna\Ares\Ares\Core\Data
- zmizela metoda `psu()` bez náhrady, podobné informace jsou ve vlastnosti `$sources`
- zmizela metoda `isGroupVat()` ARES již vrací DIČ pro skupinové DPH
- odstraněné vlastnosti `$court`, `$file_number`, `$court_all` jsou dostupné na jiném endpointu, `Sources::SERVICE_VR`
- DIČ je nově bez prefixu `CZ`, vlastnost `$tin` z důvodu zpětné kompatibility, prefix nese, nová vlastnost `$vat_id` prefix nemá
- 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)
- původní název `h4kuna\Ares\Basic\Data`, ale je zde [aliases.php](./src/aliases.php) který zajistí zpětnou kompatibilitu a bude hlásit aby jste si třídu přejmnovali, nicméně stará třída bude fungovat
- už není možnost do metody `toArray()` předat vlastní pole pro úpravu mapování, pro změnu entity za vlastní využijte interface [JsonToDataTransformerInterface](./src/Ares/Core/JsonToDataTransformerInterface.php)
- přidané vlastnosti `$country` a `$country_code`


- h4kuna\Ares\Exceptions\ConnectionException
- nastavena jako deprecated, zpětně funkční
- nahrazena h4kuna\Ares\Exceptions\ServerResponseException

### Závěrem

`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í.

`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í.

# v2.0.0

- remove support php < 7.4
- serialized date use RFC3339 instead of ISO8601, because ISO is deprecated by php
- removed method Ares::getData()
Expand All @@ -10,19 +51,19 @@ v2.0.0
- prepared AresFactory::create() for instance Ares class
- Data::$tin is null if value is Skupinove_DPH

v1.4.0
======
# v1.4.0

- remove support php < 7.1
- exceptions move to files -> one class is one file and change namespace


v1.3.0
======
# v1.3.0

- remove support for php 5.5
- add Factory provide new instances Guzzle, Data, DataProvider

v1.2.0
======
# v1.2.0

- interface IData was removed
- change data keys:
- person -> is_person
Expand All @@ -33,15 +74,15 @@ v1.2.0
- class Data extends Messenger
- class Data suggest property

v1.1.3
======
# v1.1.3

- method Ares::loadData throw IdentificationNumberNotFoundException if find nothing
- rename InNotFoundExceptions -> IdentificationNumberNotFoundException
- rename vat_pay -> vat_payer and interface IData
- try download exists item if is faild try download item with non-exists parameter

v1.1.2
======
# v1.1.2

- method Ares::loadData throw InNotFoundExceptions if find nothing
- attribute vat_pay in Data is bool instanceof empty string and string 1
- attribute created in Data is Datetime instanceof ISO date
Expand Down
24 changes: 13 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@
}
],
"autoload": {
"files": [
"src/aliases.php"
],
"psr-4": {
"h4kuna\\Ares\\": "src/"
}
},
"files": [
"src/aliases.php"
]
},
"autoload-dev": {
"psr-4": {
"h4kuna\\Ares\\Tests\\": "tests/src/"
"h4kuna\\Ares\\Tests\\": "tests/src"
}
},
"require": {
"php": ">=8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-simplexml": "*",
"h4kuna/memoize": "^0.1.4",
"nette/utils": "^3.0 || ^4.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 || ^2.0"
"psr/http-factory": "^1.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.5",
Expand All @@ -42,11 +40,15 @@
"tracy/tracy": "^2.9"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"tests": "vendor/bin/tester -s -j 6 --colors 1 -s -C tests/src"
"tests": "vendor/bin/tester -s --colors 1 -s -C tests/src",
"coverage": "vendor/bin/tester --coverage coverage.html --coverage-src src/ --colors 1 -s -C tests/src"
},
"suggest": {
"guzzlehttp/guzzle": "As default implementation for PSR standards."
Expand Down
Loading

0 comments on commit 1df6d2f

Please sign in to comment.