Download the PHP package znojil/vies without Composer

On this page you can find all versions of the php package znojil/vies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package vies

Znojil VIES

Latest Stable Version PHP Version Require Tests

A simple and modern PHP library for communicating with the VIES VAT number validation service of the European Commission.

Covers all endpoints of the VIES REST API, with typed DTOs, enums and full PHPStan level max coverage. No API key or registration is needed โ€” VIES is a public service.

๐Ÿš€ Installation

๐Ÿ“– Usage

1. Checking a VAT Number

The VAT number is passed without the country prefix โ€” the country is a separate Country enum argument. To get there from what users type, see Parsing User Input.

Member states are free to withhold the name and address even for a valid number, so name and address are null whenever the service returns no value. Do not treat a missing name as an invalid number โ€” valid is the answer.

The address is free text from the member state's register and its layout differs by member state. getAddressLines() splits it into lines without interpreting them:

To confirm individual address parts, use approximate matching instead of parsing the lines.

2. Parsing User Input

VatNumber::parse() turns a VAT number as people write it into the country and the national part the request expects. It removes spaces, dots and dashes, uppercases the input and splits off the country prefix. GR is accepted for Greece and converted to EL, the code VIES uses.

When the input has no prefix, pass the country. A prefix in the input must then match it, so a form expecting a Czech number rejects a Slovak one:

France is the exception: its numbers may themselves start with two letters, so for France only FR is treated as a prefix โ€” parse('AT123456789', Country::France) gives FRAT123456789, not a mismatch with Austria.

InvalidArgumentException is thrown when the input has no prefix and no country is given, when the prefix is not a supported country (e.g. GB), when the prefix does not match the given country, or when the national part does not match the generic format VIES accepts โ€” 2 to 12 letters, digits, + or *.

parse() does not apply any country specific rules: no length or check digit validation, no zero padding. A number that parses can still be invalid, and only VIES can tell. It works without a client, so it can also be used on its own, e.g. to normalize form input.

3. Approximate Matching

Supplying trader details asks VIES to compare them with the registered ones. To also get a requestIdentifier โ€” the consultation number proving the check was made โ€” supply your own VAT number as the requester:

Fields you do not submit come back as NotProcessed. Matching is advisory: member states differ in how strictly they compare, and Invalid does not by itself mean the VAT number is invalid.

4. Checking Service Status

Worth checking before a batch run โ€” an unavailable member state cannot be validated no matter how many times you ask.

5. Testing Error Handling

VIES provides a test endpoint that returns canned responses, so error handling can be exercised without depending on a member state actually being down:

Each TestVatNumber case other than Valid and Invalid produces the error code of the same name. The responses are abridged โ€” no trader data is returned โ€” which the DTO handles.

6. Using a Custom HTTP Client

By default the library uses znojil/http. You can inject your own implementation as the first argument to the Client constructor. It must implement the Znojil\Vies\Http\Client interface.

$data is encoded according to the Content-Type header (JSON or form); an empty array or null means no content. String keys in $options are transport-agnostic options defined by this library โ€” your implementation must honor them and reject any other string key with an exception. This library does not define any at the moment. Integer keys are raw CURLOPT_* constants โ€” non-cURL implementations must reject them with an exception rather than silently ignore them, so that a consumer never ends up with options that silently don't apply.

โš ๏ธ Error Handling

VIES reports most errors with HTTP status 200 and an error payload rather than with a 4xx/5xx status. The client detects those and throws an exception, so a successful send() always means a real answer.

The client throws exceptions to help you identify the issue:

All exceptions thrown by the library implement the Znojil\Vies\Exception\Exception marker interface, so a single catch can cover them all.

Error Codes

The REST contract does not list the error codes. These are the ones known from the VIES SOAP service definitions; the descriptions come from checkVatService.wsdl:

Code Meaning
INVALID_INPUT the country code is invalid or the VAT number is empty
SERVICE_UNAVAILABLE network or web application error โ€” try again later
MS_UNAVAILABLE the member state application is not replying โ€” try again later
TIMEOUT no reply within the allocated time โ€” try again later
GLOBAL_MAX_CONCURRENT_REQ too many concurrent requests to VIES โ€” try again later
MS_MAX_CONCURRENT_REQ too many concurrent requests to the member state โ€” try again later
INVALID_REQUESTER_INFO no official description
VAT_BLOCKED no official description
IP_BLOCKED no official description
GLOBAL_MAX_CONCURRENT_REQ_TIME no official description
MS_MAX_CONCURRENT_REQ_TIME no official description

Other codes can appear, e.g. VOW-ERR-1 with HTTP 500 for a malformed request.

Fair Use

VIES is a free public service with no published rate limit, but it does throttle: GLOBAL_MAX_CONCURRENT_REQ and MS_MAX_CONCURRENT_REQ are returned when too many requests arrive at once. Validate sequentially, cache results, and back off when you receive these, MS_UNAVAILABLE or TIMEOUT.

๐Ÿ“„ License

This library is open-source software licensed under the MIT license.


All versions of vies with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
znojil/http Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package znojil/vies contains the following files

Loading the files please wait ...