PHP code example of ddeboer / vatin-bundle

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

    

ddeboer / vatin-bundle example snippets


// app/AppKernel.php
public function registerBundles()
{
    return [
        ...
        new Ddeboer\VatinBundle\DdeboerVatinBundle(),
        ...
    ];
}

use Ddeboer\VatinBundle\Validator\Constraints\Vatin;

class Company
{
    /**
     * @Vatin
     */
    protected $vatNumber;

    use Ddeboer\VatinBundle\Validator\Constraints\Vatin;

    /**
     * @Vatin(checkExistence=true)
     */
    protected $vatNumber;

use Symfony\Component\Validator\Exception\ValidatorException;

try {
    if ($validator->isValid()) {
        // Happy flow
    }
} catch (ValidatorException $e) {
    // VAT could not be validated because VIES service is unreachable
}

$validator = $container->get('ddeboer_vatin.vatin_validator');
$bool = $validator->isValid('NL123456789B01');

$bool = $validator->isValid('NL123456789B01', true);

$vies = $container->get('ddeboer_vatin.vies.client');
$checkVatResponse = $vies->checkVat('NL', '123456789B01');