Skip to content
/ vies Public
forked from DragonBe/vies

Component using the European Commission (EC) VAT Information Exchange System (VIES) to verify and validate VAT registration numbers in the EU, using PHP and Composer.

License

Notifications You must be signed in to change notification settings

mclemme/vies

 
 

Repository files navigation

VIES

Component using the European Commission (EC) VAT Information Exchange System (VIES) to verify and validate VAT registration numbers in the EU, using PHP and Composer.

The Vies class provides functionality to make a SOAP call to VIES and returns an object CheckVatResponse containing the following information:

  • Country code (string): a 2-character notation of the country code
  • VAT registration number (string): contains the complete registration number without the country code
  • Date of request (DateTime): the date when the request was made
  • Valid (boolean): flag indicating the registration number was valid (TRUE) or not (FALSE)
  • Name (string): registered company name (if provided by EC member state)
  • Address (string): registered company address (if provided by EC member state)

Stated on the European Commission website:

To make an intra-Community supply without charging VAT, you should ensure that the person to whom you are supplying the goods is a taxable person in another Member State, and that the goods in question have left, or will leave your Member State to another MS. VAT-number should also be in the invoice.

More information at http://ec.europa.eu/taxation_customs/vies/faqvies.do#item16

Travis-CI Build status SensioLabs Insights CodeClimate Analysis CodeClimate CodeCoverage CodeShip CI Build Status

Installation

This project is on Packagist!

To install the latest stable version use composer require dragonbe/vies.

To install specifically a version (e.g. 1.0.4), just add it to the command above, for example composer require dragonbe/vies:1.0.4

Usage

<?php

use DragonBe\Vies\Vies;
use DragonBe\Vies\ViesException;
use DragonBe\Vies\ViesServiceException;

require_once dirname(__DIR__) . '/vendor/autoload.php';

$vies = new Vies();

if (false === $vies->getHeartBeat()->isAlive()) {

    echo 'Service is not available at the moment, please try again later.' . PHP_EOL;

} else {

    $vatNumberProvider = [
        [
            'BE' => '0811231190',       // valid
            'HR' => '20649144807'
        ],
        [
            'BE' => '1234567890',       // invalid
            'ES' => '9999999999',
        ],
        [
            'AA' => '1234567890',       // invalid country code
            'NO' => '1234567890'
        ],
    ];

    foreach ($vatNumberProvider as $vatNumbers) {

        foreach ($vatNumbers as $countryCode => $vatNumber) {

            echo 'Validating ' . $countryCode . $vatNumber . '... ';

            try {
                $result = $vies->validateVat($countryCode, $vatNumber); // - Validation routine worked as expected.
                echo ($result->isValid()) ? 'Valid' : 'Invalid';        //
            } catch (ViesServiceException $e) {                         // - Recoverable exception.
                echo $e->getMessage();                                  //   There is probably a temporary problem with back-end VIES service.
            } catch (ViesException $e) {                                // - Unrecoverable exception.
                echo $e->getMessage();                                  //   Invalid country code etc.
            }

            echo PHP_EOL;

        }
    }
}

Licence

DragonBe\Vies is released under the MIT Licence. See the bundled LICENSE file for details.

About

Component using the European Commission (EC) VAT Information Exchange System (VIES) to verify and validate VAT registration numbers in the EU, using PHP and Composer.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%