1. Go to this page and download the library: Download znojil/vies library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
znojil / vies example snippets
use Znojil\Vies\Client;
use Znojil\Vies\Enum\Country;
use Znojil\Vies\Request\CheckVatNumberRequest;
$client = new Client;
$result = $client->send(new CheckVatNumberRequest(Country::CzechRepublic, '12345674'));
$result->valid; // true
$result->name; // 'Example s.r.o.'
$result->address; // "Příkladná 1234/5\nPRAHA 1 - NOVÉ MĚSTO\n110 00 PRAHA 1"
$result->requestDate; // DateTimeImmutable
$result->getAddressLines(); // ['Příkladná 1234/5', 'PRAHA 1 - NOVÉ MĚSTO', '110 00 PRAHA 1']
VatNumber::parse('12345674', Country::CzechRepublic); // CZ12345674
VatNumber::parse('CZ12345674', Country::CzechRepublic); // CZ12345674 as well
VatNumber::parse('SK1234567890', Country::CzechRepublic); // throws InvalidArgumentException
$result = $client->send(new CheckVatNumberRequest(
country: Country::CzechRepublic,
vatNumber: '12345674',
requesterCountry: Country::CzechRepublic,
requesterVatNumber: '...', // your own VAT number
traderName: 'Example s.r.o.',
traderCity: 'Praha'
));
$result->traderNameMatch; // ApproximateMatch enum
$result->traderCityMatch; // ApproximateMatch enum
$result->traderStreetMatch; // ApproximateMatch::NotProcessed — not submitted
$result->requestIdentifier; // ?string
use Znojil\Vies\Request\CheckStatusRequest;
$status = $client->send(new CheckStatusRequest);
$status->vow->available; // true — VIES itself is up
foreach($status->countries as $country){
$country->country; // Country enum
$country->availability; // Availability enum
}
use Znojil\Vies\Enum\TestVatNumber;
use Znojil\Vies\Request\CheckVatNumberTestRequest;
$client->send(new CheckVatNumberTestRequest(Country::CzechRepublic, TestVatNumber::Valid));
// CheckedVatNumberDTO with valid = true
$client->send(new CheckVatNumberTestRequest(Country::CzechRepublic, TestVatNumber::MsUnavailable));
// throws ApiException with message 'MS_UNAVAILABLE'
use Znojil\Vies\Client;
use Znojil\Vies\Http\Client as ViesHttpClient;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
class MyCustomHttpClient implements ViesHttpClient{
public function send(string $method, string|UriInterface $uri, array $headers = [], mixed $data = null, array $options = []): ResponseInterface{
// your implementation
}
}
$client = new Client(new MyCustomHttpClient);
use Znojil\Vies\Exception\ApiException;
use Znojil\Vies\Exception\ServerException;
try{
$result = $client->send(new CheckVatNumberRequest(Country::Germany, '123456789'));
}catch(ApiException $e){
echo $e->getMessage(); // MS_UNAVAILABLE
foreach($e->errors as $error){
$error->code; // 'MS_UNAVAILABLE'
$error->message; // ?string — the API leaves it out for most codes
}
}catch(ServerException $e){
// VIES server error (5xx)
$e->getPrevious(); // ?ApiException
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.