PHP code example of dmt-software / eu-vat-validation
1. Go to this page and download the library: Download dmt-software/eu-vat-validation 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/ */
dmt-software / eu-vat-validation example snippets
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();
}