Initial commit

This commit is contained in:
2024-08-13 03:11:06 +03:00
parent c095988fb6
commit b66a45202b
23 changed files with 1798 additions and 1 deletions

1
.gitignore vendored
View File

@@ -132,3 +132,4 @@ Homestead.json
.env*.local .env*.local
.vercel .vercel
next-env.d.ts next-env.d.ts

View File

@@ -1,6 +1,6 @@
MIT License 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

38
README.md Normal file
View File

@@ -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
<?php
require_once 'vendor/autoload.php';
$client = new Ivuorinen\BusinessDataFetcher\BusinessDataFetcher();
try {
$results = $client->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.

16
composer.json Normal file
View File

@@ -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/"
}
}
}

675
composer.lock generated Normal file
View File

@@ -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"
}

11
example.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
require_once 'vendor/autoload.php';
$client = new Ivuorinen\BusinessDataFetcher\BusinessDataFetcher();
try {
$results = $client->getBusinessInformation('1639413-9');
print_r($results);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
var_dump($e);
}

122
gen/models.txt Normal file
View File

@@ -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
}

56
gen/parser.php Normal file
View File

@@ -0,0 +1,56 @@
<?php
// Load models.txt that contains https://avoindata.prh.fi/ytj_en.html models.
// Just copy and paste the plaintext Response Class contents to the file and
// run this file: php parser.php
$models = file_get_contents(sprintf(
'%s%2$smodels.txt',
__DIR__,
DIRECTORY_SEPARATOR
));
// Capture the names as one group,
// and blocks inside curly braces as another,
// then combine them later.
preg_match_all('/(\w+)\s\{([\w\W]*?)\}/m', $models, $output_array);
[$all, $names, $fields] = $output_array;
$fields = array_map(
function ($f) {
$f = explode("\n", $f);
$f = array_map('trim', $f);
$f = array_filter($f);
$f = array_map(function ($field) {
[$name_and_type, $docs] = explode(':', $field, 2);
$names_and_types = explode(' ', $name_and_type, 2);
[$name, $type] = $names_and_types;
$type = str_replace(['(', ')'], '', $type);
if (str_contains($type, 'optional')) {
$type = str_replace(['optional', ','], '', $type);
$type = '?' . trim($type);
}
return [
$name => [
'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);

View File

@@ -0,0 +1,93 @@
<?php
namespace Ivuorinen\BusinessDataFetcher;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Ivuorinen\BusinessDataFetcher\Dto\BisCompanyDetails;
use Ivuorinen\BusinessDataFetcher\Exceptions\ApiResponseErrorException;
/**
* Fetches and returns business data from avoindata
*/
class BusinessDataFetcher
{
/**
* @var \GuzzleHttp\Client
*/
private Client $httpClient;
/**
* BusinessDataFetcher constructor.
*/
public function __construct()
{
$this->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;
}
}

83
src/Dto/BisAddress.php Normal file
View File

@@ -0,0 +1,83 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Business Address
*
* - 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
*/
class BisAddress extends DataTransferObject
{
use HasSource;
/**
* 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;
/**
* 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;
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Business ID Change
*
* - 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
*/
class BisCompanyBusinessIdChange extends DataTransferObject
{
use HasSource;
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Business Line
*
* - 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
*/
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;
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Contact Detail
*/
class BisCompanyContactDetail extends DataTransferObject
{
use HasSource;
/**
* One for current version and >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;
}

View File

@@ -0,0 +1,132 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\Casters;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Details
*/
class BisCompanyDetails extends DataTransferObject
{
/**
* Business ID
*
* @var string
*/
public string $businessId;
/**
* Primary company name
*
* @var string
*/
public string $name;
/**
* Date of registration
*
* @var string
*/
public string $registrationDate;
/**
* Company form
*
* @var string|null
*/
public ?string $companyForm = null;
/**
* A URI for more details, if details aren't already included
*
* @var string|null
*/
public ?string $detailsUri = null;
/**
* Primary company name and translations
*
* @var BisCompanyName[] $names
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyName::class)]
public ?array $names = null;
/**
* Auxiliary company name and translations
*
* @var BisCompanyName[] $auxiliaryNames
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyName::class)]
public ?array $auxiliaryNames = null;
/**
* Company's street and postal addresses
*
* @var BisAddress[]|null $addresses
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisAddress::class)]
public ?array $addresses = null;
/**
* Company form and translations
*
* @var BisCompanyForm[]|null $companyForms
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyForm::class)]
public ?array $companyForms = null;
/**
* Bankruptcy, liquidation or restructuring proceedings
*
* @var BisCompanyLiquidation[]|null $liquidations
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyLiquidation::class)]
public ?array $liquidations = null;
/**
* Company's lines of business and translations
*
* @var BisCompanyBusinessLine[]|null $businessLines
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyBusinessLine::class)]
public ?array $businessLines = null;
/**
* Company's language(s)
*
* @var BisCompanyLanguage[]|null $languages
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyLanguage::class)]
public ?array $languages = null;
/**
* Company's place of registered office and its translations
*
* @var BisCompanyRegisteredOffice[]|null $registeredOffices
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyRegisteredOffice::class)]
public ?array $registeredOffices = null;
/**
* Company's contact details and translations
*
* @var BisCompanyContactDetail[]|null $contactDetails
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyContactDetail::class)]
public ?array $contactDetails = null;
/**
* Company's registered entries
*
* @var BisCompanyRegisteredEntry[]|null $registeredEntries
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyRegisteredEntry::class)]
public ?array $registeredEntries = null;
/**
* Company's Business ID changes
*
* @var BisCompanyBusinessIdChange[]|null $businessIdChanges
*/
#[CastWith(Casters\ArrayCaster::class, itemType: BisCompanyBusinessIdChange::class)]
public ?array $businessIdChanges = null;
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Form
*/
class BisCompanyForm extends DataTransferObject
{
use HasSource;
/**
* One for current version and >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;
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Language
*/
class BisCompanyLanguage extends DataTransferObject
{
use HasSource;
/**
* 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;
/**
* Company name
*
* @var string
*/
public string $name;
/**
* Two letter language code
*
* @var string|null
*/
public ?string $language = null;
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Liquidation
*
* - 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
*/
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;
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Name
*/
class BisCompanyName 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;
/**
* Company name
*
* @var string
*/
public string $name;
/**
* Two letter language code
*
* @var string|null
*/
public ?string $language = null;
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Exceptions\UnexpectedValueException;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Registered Entry
*/
class BisCompanyRegisteredEntry extends DataTransferObject
{
/**
* Description of entry
*
* @var string
*/
public string $description;
/**
* Zero for common entries, one for Unregistered and two for Registered
*
* @see getStatusText()
*
* @var int
*/
public int $status;
/**
* Date of registration
*
* @var string
*/
public string $registrationDate;
/**
* Ending date of registration
*
* @var string|null
*/
public ?string $endDate;
/**
* 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
*
* @see getRegisterText()
*
* @var int
*/
public int $register;
/**
* Two letter language code
*
* @var string|null
*/
public ?string $language;
/**
* authority (integer):
* - One for Tax Administration,
* - two for Finnish Patent and Registration Office and
* - three for Population Register
*
* @see getAuthorityText()
*
* @var int
*/
public int $authority;
public function getStatusText(): string
{
// Zero for common entries, one for Unregistered and two for Registered
return match ($this->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),
};
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Dto;
use Ivuorinen\BusinessDataFetcher\Traits\HasSource;
use Spatie\DataTransferObject\DataTransferObject;
/**
* Company Registered Office
*/
class BisCompanyRegisteredOffice extends DataTransferObject
{
use HasSource;
/**
* Zero for primary place of registered office, positive for others
*
* @var int
*/
public int $order;
/**
* One for current version and >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;
}

View File

@@ -0,0 +1,5 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Exceptions;
class ApiResponseErrorException extends \Exception {}

View File

@@ -0,0 +1,5 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Exceptions;
class UnexpectedValueException extends \Exception {}

34
src/Traits/HasSource.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace Ivuorinen\BusinessDataFetcher\Traits;
trait HasSource
{
/**
* Source of the information.
*
* source (integer, optional):
* - Zero for common,
* - one for Finnish Patent and Registration Office,
* - two for Tax Administration or
* - three for Business Information System
*
* Use `getSourceText()` to get the text representation.
*
* @see getSourceText()
*
* @var int|null
*/
public ?int $source;
public function getSourceText(): string
{
return match ($this->source) {
0 => 'common',
1 => 'Finnish Patent and Registration Office',
2 => 'Tax Administration',
3 => 'Business Information System',
default => '',
};
}
}