diff --git a/.gitignore b/.gitignore index e2a1faa..ca05913 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ Homestead.json .env*.local .vercel next-env.d.ts + diff --git a/LICENSE.md b/LICENSE.md index 1272de8..bffa737 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Ismo Vuorinen +Copyright (c) 2024 Ismo Vuorinen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e38027 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Business Data Fetcher + +This is an API client to Finnish Patent and Registration +Office's (PRH) Business Information System (BIS). + +Use it to get company data from the Business Information System by Business ID. + +## Installation + +```bash +composer install ivuorinen/business-data-fetcher +``` + +## Usage example + +```php +getBusinessInformation('1639413-9'); + print_r($results); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + var_dump($e); +} +``` + +## Data source + +All models are transcribed from PRH Open Data portal. You can find the examples +and models descriptions, among other details and live API query tool following +this link: https://avoindata.prh.fi/ytj_en.html + +## Notice of Liability + +The data provided by the API is subject to change without warning and the author(s) +of this library are providing this without compensation and cannot be held responsible. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d6a8fac --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "ivuorinen/business-data-fetcher", + "description": "Library to fetch finnish business data", + "type": "library", + "license": "MIT", + "require": { + "php": "^8", + "guzzlehttp/guzzle": "7.4.5", + "spatie/data-transfer-object": "^3.9" + }, + "autoload": { + "psr-4": { + "Ivuorinen\\BusinessDataFetcher\\": "src/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..380a928 --- /dev/null +++ b/composer.lock @@ -0,0 +1,675 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "c05d6b9041609af52741a534c1dfc404", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "7.4.5", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", + "reference": "1dd98b0564cb3f6bd16ce683cb755f94c10fbd82", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5", + "guzzlehttp/psr7": "^1.9 || ^2.4", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-curl": "*", + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.4-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.4.5" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2022-06-20T22:16:13+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "1.5.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "67ab6e18aaa14d753cc148911d273f6e6cb6721e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/67ab6e18aaa14d753cc148911d273f6e6cb6721e", + "reference": "67ab6e18aaa14d753cc148911d273f6e6cb6721e", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.5.3" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2023-05-21T12:31:43+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.7.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2024-07-18T11:15:46+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory" + }, + "time": "2024-04-15T12:06:14+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "spatie/data-transfer-object", + "version": "3.9.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/data-transfer-object.git", + "reference": "1df0906c4e9e3aebd6c0506fd82c8b7d5548c1c8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/data-transfer-object/zipball/1df0906c4e9e3aebd6c0506fd82c8b7d5548c1c8", + "reference": "1df0906c4e9e3aebd6c0506fd82c8b7d5548c1c8", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "illuminate/collections": "^8.36", + "jetbrains/phpstorm-attributes": "^1.0", + "larapack/dd": "^1.1", + "phpunit/phpunit": "^9.5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\DataTransferObject\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brent Roose", + "email": "brent@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Data transfer objects with batteries included", + "homepage": "https://github.com/spatie/data-transfer-object", + "keywords": [ + "data-transfer-object", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/data-transfer-object/issues", + "source": "https://github.com/spatie/data-transfer-object/tree/3.9.1" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "abandoned": "spatie/laravel-data", + "time": "2022-09-16T13:34:38+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-04-18T09:32:20+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": "^8" + }, + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/example.php b/example.php new file mode 100644 index 0000000..28938a8 --- /dev/null +++ b/example.php @@ -0,0 +1,11 @@ +getBusinessInformation('1639413-9'); + print_r($results); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { + var_dump($e); +} diff --git a/gen/models.txt b/gen/models.txt new file mode 100644 index 0000000..10aec05 --- /dev/null +++ b/gen/models.txt @@ -0,0 +1,122 @@ +BisCompanyDetails { + names (Array[BisCompanyName]): Primary company name and translations + auxiliaryNames (Array[BisCompanyName], optional): Auxiliary company name and translations + addresses (Array[BisAddress], optional): Company's street and postal addresses + companyForms (Array[BisCompanyForm], optional): Company form and translations + liquidations (Array[BisCompanyLiquidation], optional): Bankruptcy, liquidation or restructuring proceedings + businessLines (Array[BisCompanyBusinessLine], optional): Company's lines of business and translations + languages (Array[BisCompanyLanguage], optional): Company's language(s) + registeredOffices (Array[BisCompanyRegisteredOffice], optional): Company's place of registered office and its translations + contactDetails (Array[BisCompanyContactDetail], optional): Company's contact details and translations + registeredEntries (Array[BisCompanyRegisteredEntry], optional): Company's registered entries + businessIdChanges (Array[BisCompanyBusinessIdChange], optional): Company's Business ID changes + businessId (string): Business ID + registrationDate (string): Date of registration + companyForm (string, optional): Company form + detailsUri (string, optional): A URI for more details, if details aren't already included + name (string): Primary company name +} + +BisCompanyName { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + order (integer): Zero for primary company name, other for translations of the primary company name and auxiliary company names + version (integer): One for current version and >1 for historical company names + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + name (string): Company name + language (string, optional): Two letter language code +} + +BisAddress { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + version (integer): One for current version and >1 for historical addresses + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + careOf (string, optional): Care of address + street (string, optional): Street address + postCode (string, optional): ZIP code + city (string, optional): City of address + language (string, optional): Two letter language code + type (integer): Type of address, 1 for street address, 2 for postal address + country (string, optional): Two letter country code +} + +BisCompanyForm { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + version (integer): One for current version and >1 for historical company forms + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + name (string): Name of company form + language (string, optional): Two letter language code + type (string): Type of company form +} + +BisCompanyLiquidation { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + version (integer): One for current version and >1 for historical company forms + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + name (string): Bankruptcy, liquidation or restructuring proceedings + language (string, optional): Two letter language code + type (string): Type of liquidation +} + +BisCompanyBusinessLine { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + order (integer): Zero for main line of business, positive for others + version (integer): One for current version and >1 for historical lines of business + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + name (string): Name of line of business + language (string, optional): Two letter language code +} + +BisCompanyLanguage { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + version (integer): One for current version and >1 for historical languages + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + name (string): Name of language + language (string, optional): Two letter language code +} + +BisCompanyRegisteredOffice { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + order (integer): Zero for primary place of registered office, positive for others + version (integer): One for current version and >1 for historical places of registered office + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + name (string): Name of place of registered office + language (string, optional): Two letter language code +} + +BisCompanyContactDetail { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + version (integer): One for current version and >1 for historical contact details + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + language (string, optional): Two letter language code + value (string): Value of contact detail + type (string): Type of contact detail +} + +BisCompanyRegisteredEntry { + description (string): Description of entry + status (integer): Zero for common entries, one for ‘Unregistered’ and two for ‘Registered’ + registrationDate (string): Date of registration + endDate (string, optional): Ending date of registration + register (integer): One for Trade Register, two for Register of Foundations, three for Register of Associations, four for Tax Administration, five for Prepayment Register, six for VAT Register, seven for Employer Register and eight for register of bodies liable for tax on insurance premiums + language (string, optional): Two letter language code + authority (integer): One for Tax Administration, two for Finnish Patent and Registration Office and three for Population Register +} + +BisCompanyBusinessIdChange { + source (integer, optional): Zero for common, one for Finnish Patent and Registration Office, two for Tax Administration or three for Business Information System + description (string): Description of reason + reason (string): Reason code + changeDate (string, optional): Date of Business ID change + change (integer): 2 = Business ID removal,3 = Combining of double IDs,5 = ID changed,44 = Fusion,45 = Operator continuing VAT activities,46 = Relation to predecessor,47 = Division,48 = Bankruptcy relationship,49 = Operations continued by a private trader,57 = Partial division,DIF = Division,FUU = Fusion + oldBusinessId (string): Old Business ID + newBusinessId (string): New Business ID + language (string, optional): Two letter language code +} diff --git a/gen/parser.php b/gen/parser.php new file mode 100644 index 0000000..457aa7d --- /dev/null +++ b/gen/parser.php @@ -0,0 +1,56 @@ + [ + 'name' => trim($name), + 'type' => trim($type), + 'docs' => trim($docs), + ], + ]; + }, $f ?? []); + + $f = array_merge(...$f); + + return $f; + }, + $fields +); + +$classes = array_combine($names, $fields); + +print_r($classes); diff --git a/src/BusinessDataFetcher.php b/src/BusinessDataFetcher.php new file mode 100644 index 0000000..e926ed9 --- /dev/null +++ b/src/BusinessDataFetcher.php @@ -0,0 +1,93 @@ +httpClient = new Client([ + 'base_uri' => 'https://avoindata.prh.fi', + 'timeout' => 2, + ]); + } + + /** + * Fetch Business Information. + * + * @param string $businessId + * + * @return array $response_data + * @throws \Exception|\GuzzleHttp\Exception\GuzzleException + */ + public function getBusinessInformation(string $businessId): array + { + // Set request variables + $requestUrl = '/bis/v1'; + $response_data = []; + + // Get the business data + try { + $uri = $requestUrl . '/' . $businessId; + $response = $this->httpClient->get($uri); + + if ($response->getStatusCode() !== 200) { + throw new ApiResponseErrorException( + $response->getReasonPhrase(), + $response->getStatusCode() + ); + } + + $response_data = $this->parse_response($response); + } catch (RequestException $exception) { + throw new ApiResponseErrorException( + $exception->getMessage(), + $exception->getCode(), + $exception + ); + } + + return $response_data; + } + + /** + * @param \Psr\Http\Message\ResponseInterface $response + * + * @return array + * @throws \JsonException + * @throws \Spatie\DataTransferObject\Exceptions\UnknownProperties + */ + public function parse_response(\Psr\Http\Message\ResponseInterface $response): array + { + $data = json_decode( + $response->getBody()->getContents(), + true, + 512, + JSON_THROW_ON_ERROR + ); + + $results = []; + + foreach ($data['results'] as $result) { + $results[] = new BisCompanyDetails($result); + } + + return $results; + } +} diff --git a/src/Dto/BisAddress.php b/src/Dto/BisAddress.php new file mode 100644 index 0000000..f2c4f64 --- /dev/null +++ b/src/Dto/BisAddress.php @@ -0,0 +1,83 @@ +1 for historical company names + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate = ''; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate = null; + /** + * Care of address (c/o) + * + * @var string|null + */ + public ?string $careOf; + /** + * Street address + * + * @var string|null + */ + public ?string $street; + /** + * ZIP code + * + * @var string|null + */ + public ?string $postCode; + /** + * City of address + * + * @var string|null + */ + public ?string $city; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language; + /** + * Type of address, 1 for street address, 2 for postal address + * + * @var int + */ + public int $type; + /** + * Two-letter country code + * + * @var string|null + */ + public ?string $country; +} diff --git a/src/Dto/BisCompanyBusinessIdChange.php b/src/Dto/BisCompanyBusinessIdChange.php new file mode 100644 index 0000000..59b14c8 --- /dev/null +++ b/src/Dto/BisCompanyBusinessIdChange.php @@ -0,0 +1,34 @@ +1 for historical lines of business + * - registrationDate (string): Date of registration + * - endDate (string, optional): Ending date of registration + * - name (string): Name of line of business + * - language (string, optional): Two letter language code + */ +class BisCompanyBusinessLine extends DataTransferObject +{ + use HasSource; + + /** + * Order + * + * Zero for primary company name, + * other for translations of the primary company name + * and auxiliary company names + * + * @var int + */ + public int $order; + /** + * One for current version and >1 for historical company names + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate = ''; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate = null; + /** + * Name of line of business + * + * @var string + */ + public string $name; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language = null; +} diff --git a/src/Dto/BisCompanyContactDetail.php b/src/Dto/BisCompanyContactDetail.php new file mode 100644 index 0000000..040ea20 --- /dev/null +++ b/src/Dto/BisCompanyContactDetail.php @@ -0,0 +1,51 @@ +1 for historical contact details + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate; + /** + * Two letter language code + * + * @var string + */ + public string $language; + /** + * Value of contact detail + * + * @var string + */ + public string $value; + /** + * Type of contact detail + * + * @var string + */ + public string $type; +} diff --git a/src/Dto/BisCompanyDetails.php b/src/Dto/BisCompanyDetails.php new file mode 100644 index 0000000..dd9f176 --- /dev/null +++ b/src/Dto/BisCompanyDetails.php @@ -0,0 +1,132 @@ +1 for historical company forms + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate; + /** + * Name of company form + * + * @var string + */ + public string $name; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language; + /** + * Type of company form. + * + * Note: According to spec, this shouldn't be nullable, + * but payloads show otherwise. + * + * @var string|null + */ + public ?string $type; +} diff --git a/src/Dto/BisCompanyLanguage.php b/src/Dto/BisCompanyLanguage.php new file mode 100644 index 0000000..5142630 --- /dev/null +++ b/src/Dto/BisCompanyLanguage.php @@ -0,0 +1,45 @@ +1 for historical company names + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate = ''; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate = null; + /** + * Company name + * + * @var string + */ + public string $name; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language = null; +} diff --git a/src/Dto/BisCompanyLiquidation.php b/src/Dto/BisCompanyLiquidation.php new file mode 100644 index 0000000..31d86a1 --- /dev/null +++ b/src/Dto/BisCompanyLiquidation.php @@ -0,0 +1,64 @@ +1 for historical company forms + * - registrationDate (string): Date of registration + * - endDate (string, optional): Ending date of registration + * - name (string): Bankruptcy, liquidation or restructuring proceedings + * - language (string, optional): Two letter language code + * - type (string): Type of liquidation + */ +class BisCompanyLiquidation extends DataTransferObject +{ + use HasSource; + + /** + * Order + * + * Zero for primary company name, + * other for translations of the primary company name + * and auxiliary company names + * + * @var int + */ + public int $order; + /** + * One for current version and >1 for historical company names + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate = ''; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate = null; + /** + * Bankruptcy, liquidation or restructuring proceedings + * + * @var string + */ + public string $name; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language = null; + + public string $type; +} diff --git a/src/Dto/BisCompanyName.php b/src/Dto/BisCompanyName.php new file mode 100644 index 0000000..0863b8d --- /dev/null +++ b/src/Dto/BisCompanyName.php @@ -0,0 +1,55 @@ +1 for historical company names + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate = ''; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate = null; + /** + * Company name + * + * @var string + */ + public string $name; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language = null; +} diff --git a/src/Dto/BisCompanyRegisteredEntry.php b/src/Dto/BisCompanyRegisteredEntry.php new file mode 100644 index 0000000..858b528 --- /dev/null +++ b/src/Dto/BisCompanyRegisteredEntry.php @@ -0,0 +1,108 @@ +status) { + 0 => 'Common', + 1 => 'Unregistered', + 2 => 'Registered', + default => throw new UnexpectedValueException('Unexpected value: ' . $this->status) + }; + } + + public function getRegisterText(): string + { + return match ($this->register) { + 1 => 'Trade Register', + 2 => 'Register of Foundations', + 3 => 'Register of Associations', + 4 => 'Tax Administration', + 5 => 'Prepayment Register', + 6 => 'VAT Register', + 7 => 'Employer Register', + 8 => 'register of bodies liable for tax on insurance premiums', + default => throw new UnexpectedValueException('Unexpected value: ' . $this->register), + }; + } + + public function getAuthorityText(): string + { + return match ($this->authority) { + 1 => 'Tax Administration', + 2 => 'Finnish Patent and Registration Office', + 3 => 'Population Register', + default => throw new UnexpectedValueException('Unexpected value: ' . $this->authority), + }; + } +} diff --git a/src/Dto/BisCompanyRegisteredOffice.php b/src/Dto/BisCompanyRegisteredOffice.php new file mode 100644 index 0000000..1ae2845 --- /dev/null +++ b/src/Dto/BisCompanyRegisteredOffice.php @@ -0,0 +1,51 @@ +1 for historical places of registered office + * + * @var int + */ + public int $version; + /** + * Date of registration + * + * @var string + */ + public string $registrationDate; + /** + * Ending date of registration + * + * @var string|null + */ + public ?string $endDate; + /** + * Name of place of registered office + * + * @var string + */ + public string $name; + /** + * Two letter language code + * + * @var string|null + */ + public ?string $language; +} diff --git a/src/Exceptions/ApiResponseErrorException.php b/src/Exceptions/ApiResponseErrorException.php new file mode 100644 index 0000000..7799919 --- /dev/null +++ b/src/Exceptions/ApiResponseErrorException.php @@ -0,0 +1,5 @@ +source) { + 0 => 'common', + 1 => 'Finnish Patent and Registration Office', + 2 => 'Tax Administration', + 3 => 'Business Information System', + default => '', + }; + } +}