ddeboer/vatin-bundle

Symfony2 bundle for the VATIN library

Installs: 1 868

Dependents: 0

Stars: 6

Watchers: 2

Forks: 2

Open Issues: 1

Language: PHP

1.0 2013-09-26 15:36 UTC

README

Build Status Latest Stable Version

A Symfony2 bundle for the VATIN library.

Installation

This library is available on Packagist:

$ composer require ddeboer/vatin-bundle:@stable

Then add the bundle to your application:

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

Usage

Validate number format

Use the validator to validate a property on your models. For instance using annotations:

use Ddeboer\VatinBundle\Validator\Constraints\Vatin;

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

Symfony’s validator will now check whether $vatNumber has a valid VAT number format. For more information, see Symfony’s documentation.

Validate number existence

Additionally, you can check whether the VAT number is in use:

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

The validator will now check the VAT number against the VAT Information Exchange System (VIES) SOAP web service.

Using the services directly

You can also use this bundle’s services directly. Validate a VAT number’s format:

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

Additionally check whether the VAT number is in use:

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

To interact with the VIES webservice:

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

More information

For more information, see the VATIN library’s documentation.