1. Go to this page and download the library: Download omisai/laravel-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/ */
omisai / laravel-vies-rest example snippets
...
use Omisai\ViesRest\ViesClient;
use Omisai\ViesRest\Enum\EuropeanUnionCountry;
class ExampleController extends Controller
{
public function __construct(
private ViesClient $viesClient,
) {}
public function checkVat(Request $request)
{
$countryCode = $request->input('country_code');
$vatNumber = $request->input('vat_number');
$isValidCountryCode = EuropeanUnionCountry::validateCountryCode($countryCode);
if (!$isValidCountryCode) {
return response()->json(['error' => 'Invalid country code'], 400);
}
$response = $this->viesClient->checkVat($countryCode, $vatNumber);
return response()->json([
'valid' => $response->valid,
'name' => $response->name,
'address' => $response->address,
]);
}
}
// In a controller, service, or route closure
$client = app(ViesClient::class);
$response = $client->checkVat('DE', '123456789');
use Omisai\ViesRest\ViesClient;
use Omisai\ViesRest\ViesConfig;
$config = ViesConfig::test(); /
$factory = app(HttpClientFactoryInterface::class);
$client = new ViesClient($config, $factory);
$response = $client->checkVat('DE', '100');
var_dump($response->valid); // true for test numbers
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());