dmt-software / eu-vat-validation
VIES VAT Validation client
Installs: 14 091
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- dmt-software/command-bus-validator: ^1.0
- dmt-software/http-client-middleware: ^0.1.3 | ^1.0 | ^2.0
- dmt-software/jms-soap-serializer: ^2.1
Requires (Dev)
- guzzlehttp/guzzle: ^7.4
- phpunit/phpunit: ^8.5 | ^9.5
Suggests
- guzzlehttp/guzzle: for PSR-18 client implementation
- guzzlehttp/psr7: for PSR-17 message factor implementation
README
This package contains a client to consume the EU VIES Vat soap-service.
Please keep in mind that there is a disclaimer for using the VAT service. This also applies to using this package.
Install
composer require dmt-software/eu-vat-validation
Usage
<?php use DMT\CommandBus\Validator\ValidationException; use DMT\Soap\Serializer\SoapFaultException; use DMT\VatServiceEu\ClientBuilder; use DMT\VatServiceEu\Request\CheckVat; use DMT\VatServiceEu\Response\CheckVatResponse; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; try { $request = new CheckVat(); $request->setCountryCode('NL'); $request->setVatNumber('804888644B01'); /** @var ClientInterface $client */ /** @var RequestFactoryInterface $requestFactory */ $client = ClientBuilder::create($client, $requestFactory)->build(); /** @var CheckVatResponse $response */ $response = $client->execute($request); if ($response->isValid()) { // some business logic ... } } catch (ValidationException $exception) { // input was incorrect foreach ($exception->getViolations() as $violation) { print $violation->getMessage(); } } catch (SoapFaultException $exception) { // service returned an error print $exception->getMessage(); }