ddeboer / vatin-bundle
Symfony bundle for the VATIN library
Installs: 674 825
Dependents: 0
Suggesters: 0
Security: 0
Stars: 28
Watchers: 7
Forks: 12
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=8.1
- ddeboer/vatin: ^3.0
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
- symfony/validator: ^6.4 || ^7.0
Requires (Dev)
- ext-soap: *
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^10.5
- rector/rector: ^2.0
- roave/security-advisories: dev-latest
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/yaml: ^6.4 || ^7.0
README
A Symfony bundle for the VATIN library.
Installation
This library is available on Packagist:
composer require ddeboer/vatin-bundle
Then add the bundle to your application:
// app/AppKernel.php public function registerBundles() { return [ ... new Ddeboer\VatinBundle\DdeboerVatinBundle(), ... ]; }
Usage
Validate number format
Use the validator to validate a property on your models.
use Ddeboer\VatinBundle\Validator\Constraints\Vatin; class Company { #[Vatin] protected string $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:
use Ddeboer\VatinBundle\Validator\Constraints\Vatin; #[Vatin(checkExistence=true)] protected string $vatNumber;
The validator will now check the VAT number against the VAT Information Exchange System (VIES) SOAP web service. This service’s availability is rather unreliable, so it’s a good idea to catch the case where it’s unreachable:
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 }
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.