1. Go to this page and download the library: Download omisai/vies-soap 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/ */
use Omisai\ViesSoap\ViesClient;
use Omisai\ViesSoap\ViesConfig;
$client = new ViesClient(ViesConfig::test());
$response = $client->checkVat('DE', '100'); // Test VAT number
var_dump($response->valid); // true for test numbers
use Omisai\ViesSoap\ViesConfig;
// Production environment (default)
$config = ViesConfig::production();
// Test environment
$config = ViesConfig::test();
// Custom WSDL URL
$config = new ViesConfig('https://custom-vies-service.com/service.wsdl');
// With SOAP options
$config = ViesConfig::production([
'connection_timeout' => 30,
'trace' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
]);
use Omisai\ViesSoap\DTO\CheckVatApproxRequest;
$request = new CheckVatApproxRequest(
countryCode: 'NL',
vatNumber: '123456789B01',
traderName: 'Example B.V.',
traderStreet: 'Main Street 123',
traderPostcode: '1234AB',
traderCity: 'Amsterdam',
requesterCountryCode: 'DE', // Optional: Your own VAT country
requesterVatNumber: '123456789', // Optional: Your own VAT number
);
$response = $client->checkVatApprox($request);
echo "Valid: " . ($response->valid ? 'Yes' : 'No') . "\n";
echo "Request ID: {$response->requestIdentifier}\n";
echo "Name Match: {$response->traderNameMatch}\n";
echo "Address Match: {$response->traderStreetMatch}\n";
use Omisai\ViesSoap\Enum\EuropeanUnionCountry;
// Check if a country code is valid
$isValid = EuropeanUnionCountry::isEuropeanUnionCountryCode('DE'); // true
$isValid = EuropeanUnionCountry::isEuropeanUnionCountryCode('US'); // false
// Get all supported countries
$countries = EuropeanUnionCountry::cases();
foreach ($countries as $country) {
echo "{$country->name}: {$country->value}\n";
}
use Omisai\ViesSoap\Exceptions\ViesValidationException;
use Omisai\ViesSoap\ViesClient;
$client = new ViesClient();
try {
$response = $client->checkVat('INVALID', '123');
} catch (ViesValidationException $e) {
echo "Validation error: {$e->getMessage()}\n";
// Handle invalid country code or VAT number format
}
use Omisai\ViesSoap\Exceptions\ViesSoapException;
use Omisai\ViesSoap\ViesClient;
$client = new ViesClient();
try {
$response = $client->checkVat('DE', '123456789');
} catch (ViesSoapException $e) {
echo "SOAP error: {$e->getMessage()}\n";
echo "Fault code: {$e->getFaultCode()}\n";
echo "Fault string: {$e->getFaultString()}\n";
// Handle service unavailability, invalid requests, etc.
}
use Omisai\ViesSoap\ViesClient;
use Omisai\ViesSoap\Soap\SoapClientFactoryInterface;
class CustomSoapClientFactory implements SoapClientFactoryInterface
{
// Implement your custom factory
}
$client = new ViesClient(
clientFactory: new CustomSoapClientFactory()
);
use Omisai\ViesSoap\ViesClient;
use Omisai\ViesSoap\Validation\VatNumberValidator;
class CustomVatNumberValidator extends VatNumberValidator
{
// Implement custom validation logic
}
$client = new ViesClient(
validator: new CustomVatNumberValidator()
);
use Omisai\ViesSoap\ViesClient;
use Tests\Support\FakeSoapClient;
use Tests\Support\FakeSoapClientFactory;
// Create a fake SOAP response
$soapResponse = (object) [
'countryCode' => 'DE',
'vatNumber' => '123456789',
'requestDate' => '2024-01-01',
'valid' => true,
'name' => 'Test Company GmbH',
'address' => 'Test Street 123, 12345 Test City',
];
$fakeClient = new FakeSoapClient($soapResponse);
$client = new ViesClient(
clientFactory: new FakeSoapClientFactory($fakeClient)
);
$response = $client->checkVat('DE', '123456789');
// Response will contain the fake data
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.