PHP code example of dragonbe / vies

1. Go to this page and download the library: Download dragonbe/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/ */

    

dragonbe / vies example snippets




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


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

    echo 'Service is not available at the moment, please try again later.' . PHP_EOL;
    exit(1);
}

$vies = new Vies();
$options = [
    'proxy_host' => '127.0.0.1',
    'proxy_port' => '8888',
];
$vies->setOptions($options);

$heartBeat = new \DragonBe\Vies\HeartBeat('tcp://' . $options['proxy_host'], $options['proxy_port']);
$vies->setHeartBeat($heartBeat);

$isAlive = $vies->getHeartBeat()->isAlive();

$vatResult = $vies->validateVat(
    'BE',           // Trader country code 
    '0203430576',   // Trader VAT ID
    'BE',           // Requester country code 
    '0811231190'    // Requester VAT ID
);

$vatResult = $vies->validateVat(
    'BE',                 // Trader country code 
    '0203430576',         // Trader VAT ID
    'BE',                 // Requester country code 
    '0811231190'          // Requester VAT ID
    'B-Rail',             // Trader name
    'NV',                 // Trader company type
    'Frankrijkstraat 65', // Trader street address
    '1060',               // Trader postcode
    'Sint-Gillis'         // Trader city
);

echo ($vatResult->isValid() ? 'Valid' : 'Not valid') . PHP_EOL;

// Result: Valid

echo 'Identifier: ' . $vatResult->getIdentifier() . PHP_EOL;

// Result: Identifier: WAPIAAAAWaXGj4Ra

echo 'Date and time: ' . $vatResult->getRequestDate()->format('r') . PHP_EOL;

// Result: Date and time: Sat, 31 Aug 2019 00:00:00 +0200

echo 'Company name: ' . $vatResult->getName() . PHP_EOL;

// Result: Company name: NV OR NATIONALE MAATSCHAPPIJ DER BELGISCHE SPOORWEGEN

echo 'Company address: ' . $vatResult->getAddress() . PHP_EOL;

// Result: Company address: FRANKRIJKSTRAAT 56
           1060 SINT-GILLIS (BIJ-BRUSSEL)

echo 'Trader name match: ' . $vatResult->getNameMatch() . PHP_EOL;

// Result: Trader name match:

echo 'Trader company type match: ' . $vatResult->getCompanyTypeMatch() . PHP_EOL;

// Result: Trader company type match:

echo 'Trader street match: ' . $vatResult->getStreetMatch() . PHP_EOL;

// Result: Trader street match:

echo 'Trader postcode match: ' . $vatResult->getPostcodeMatch() . PHP_EOL;

// Result: Trader postcode match:

echo 'Trader city match: ' . $vatResult->getCityMatch() . PHP_EOL;

// Result: Trader city match:



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

me' => 'B-Rail',
   'trader_company_type' => 'NV',
   'trader_street' => 'Frankrijkstraat 65',
   'trader_postcode' => '1060',
   'trader_city' => 'Sint-Gillis',
];

try {
    $vatResult = $vies->validateVat(
        $company['country_code'],        // Trader country code
        $company['vat_id'],              // Trader VAT ID
        'BE',                            // Requester country code (your country code)
        '0811231190',                    // Requester VAT ID (your VAT ID)
        $company['trader_name'],         // Trader name
        $company['trader_company_type'], // Trader company type
        $company['trader_street'],       // Trader street address
        $company['trader_postcode'],     // Trader postcode
        $company['trader_city']          // Trader city
    );
} catch (ViesException $viesException) {
    echo 'Cannot process VAT validation: ' . $viesException->getMessage();
    exit (2);
} catch (ViesServiceException $viesServiceException) {
    echo 'Cannot process VAT validation: ' . $viesServiceException->getMessage();
    exit (2);
}

echo ($vatResult->isValid() ? 'Valid' : 'Not valid') . PHP_EOL;
echo 'Identifier: ' . $vatResult->getIdentifier() . PHP_EOL;
echo 'Date and time: ' . $vatResult->getRequestDate()->format('d/m/Y H:i') . PHP_EOL;
echo 'Company name: ' . $vatResult->getName() . PHP_EOL;
echo 'Company address: ' . $vatResult->getAddress() . PHP_EOL;

echo 'Trader name match: ' . $vatResult->getNameMatch() . PHP_EOL;
echo 'Trader company type match: ' . $vatResult->getCompanyTypeMatch() . PHP_EOL;
echo 'Trader street match: ' . $vatResult->getStreetMatch() . PHP_EOL;
echo 'Trader postcode match: ' . $vatResult->getPostcodeMatch() . PHP_EOL;
echo 'Trader city match: ' . $vatResult->getCityMatch() . PHP_EOL;
echo PHP_EOL;