1. Go to this page and download the library: Download omisai/vies-rest 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\ViesRest\ViesClient;
use Omisai\ViesRest\ViesConfig;
$client = new ViesClient(ViesConfig::test());
$response = $client->checkVat('DE', '100');
var_dump($response->valid); // true for test numbers
use Omisai\ViesRest\Exceptions\ViesValidationException;
use Omisai\ViesRest\ViesClient;
$client = new ViesClient();
try {
$client->checkVat('INVALID', '123');
} catch (ViesValidationException $e) {
echo "Validation error: {$e->getMessage()}\n";
}
use Omisai\ViesRest\Exceptions\ViesApiException;
use Omisai\ViesRest\ViesClient;
$client = new ViesClient();
try {
$client->checkVat('DE', '123456789');
} catch (ViesApiException $e) {
echo "API error: {$e->getMessage()}\n";
echo "Status code: {$e->getStatusCode()}\n";
}
use Omisai\ViesRest\ViesClient;
use Omisai\ViesRest\Http\HttpClientFactoryInterface;
class CustomHttpClientFactory implements HttpClientFactoryInterface
{
public function create(string $baseUrl, array $options = [])
{
// Return a custom adapter implementing HttpClientInterface
}
}
$client = new ViesClient(clientFactory: new CustomHttpClientFactory());
use Omisai\ViesRest\ViesClient;
use Omisai\ViesRest\Validation\VatNumberValidator;
class CustomVatNumberValidator extends VatNumberValidator
{
// Implement custom validation logic
}
$client = new ViesClient(validator: new CustomVatNumberValidator());