danielebarbaro/laravel-vat-eu-validator
Composer 安装命令:
composer require danielebarbaro/laravel-vat-eu-validator
包简介
A simple package that validates EU VAT numbers against the central ec.europa.eu database
关键字:
README 文档
README
laravel-vat-eu-validator is a package inspired from vat.php to validate a VAT number for businesses based in Europe.
For Laravel 10, 11, 12, 13 use tag 3.x
For Laravel 10, 11, 12 use tag 2.x (legacy SOAP-only)
For Laravel 8, 9 use tag 1.20
For Laravel 5, 6, 7 use tag 0.5.4
What's new in v3.0
- REST Client support: an alternative to the traditional SOAP client, using the official European Commission REST APIs
- Strategy Pattern architecture: ViesClientInterface interface with ViesSoapClient and ViesRestClient implementations
- Publishable configuration file: choose which client to use and configure its parameters
- Restructured test suite: separation between unit and functional tests
- PHP 8.4 e 8.5 support
Installation
You can install the package via composer:
composer require danielebarbaro/laravel-vat-eu-validator
The package will automatically register itself.
Configuration
VIES Client Configuration
The package supports multiple VIES clients for VAT validation:
- SOAP Client (default): Uses the traditional SOAP API
- REST Client: Uses the modern REST API
To customize the client configuration, publish the configuration file:
php artisan vendor:publish --tag=laravel-vat-eu-validator-config
This will create a config/vat-validator.php file where you can configure which client to use:
<?php use Danielebarbaro\LaravelVatEuValidator\Vies\ViesRestClient; use Danielebarbaro\LaravelVatEuValidator\Vies\ViesSoapClient; return [ // Select which client to use for VIES validation // Available: ViesSoapClient::CLIENT_NAME, ViesRestClient::CLIENT_NAME 'client' => ViesSoapClient::CLIENT_NAME, // Default: SOAP 'clients' => [ ViesSoapClient::CLIENT_NAME => [ 'timeout' => 10, ], ViesRestClient::CLIENT_NAME => [ 'timeout' => 10, 'base_url' => ViesRestClient::BASE_URL, ], ], ];
Switching to REST Client
To use the REST client instead of SOAP, update your config/vat-validator.php:
'client' => ViesRestClient::CLIENT_NAME,
The REST client uses the official European Commission VIES REST API endpoints, which do not require authentication or API keys.
Customizing REST Client Configuration
You can customize the REST client timeout and base URL if needed:
'clients' => [ ViesRestClient::CLIENT_NAME => [ 'timeout' => 10, // seconds 'base_url' => env('VIES_REST_BASE_URL', ViesRestClient::BASE_URL), ], ],
By default, the client uses the official EU endpoint: https://ec.europa.eu/taxation_customs/vies/rest-api
Customizing Timeout
You can adjust the timeout for API requests:
'clients' => [ ViesSoapClient::CLIENT_NAME => [ 'timeout' => 30, // seconds ], ],
Usage
use Danielebarbaro\LaravelVatEuValidator\Facades\VatValidatorFacade as VatValidator; // Check VAT format and VIES existence VatValidator::validate('IT12345'); // Check VAT format VatValidator::validateFormat('IT12345678901'); // Check VAT existence VatValidator::validateExistence('IT12345678901');
Validation
The package registers two new validation rules.
vat_number
The field under validation must be a valid and existing VAT number.
vat_number_exist
The field under validation check id is an existing VAT number.
vat_number_format
The field under validation must be a valid VAT number.
use Illuminate\Http\Request; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber()], ]); $request->validate([ 'bar_field' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist()], ]); $request->validate([ 'bar_field' => [new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat()], ]); } }
Alternatively, you can also use the Rule directly.
use Illuminate\Http\Request; use Danielebarbaro\LaravelVatEuValidator\Rules; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [ new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber() ], 'bar_field' => [ new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist() ], 'bar_field' => [ new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat() ], ]); } }
or
use Illuminate\Http\Request; use Danielebarbaro\LaravelVatEuValidator\Rules; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [ new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber(), new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist(), new \Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat(), ], ]); } }
or
use Illuminate\Http\Request; use Danielebarbaro\LaravelVatEuValidator\Rules; class Controller { public function foo(Request $request) { $request->validate([ 'bar_field' => [ 'vat_number', 'vat_number_format', 'vat_number_exist', ], ]); } }
Translations
Most of the displayed strings are defined in the vatEuValidator::validation translation files. The package ships with a few supported locales, but if yours is not yet included we would greatly appreciate a PR.
If not already published, you can edit or fill the translation files using php artisan vendor:publish --tag=laravel-vat-eu-validator-lang, this will copy our translation files to your app's vendor/laravelVatEuValidator "lang" path.
Testing
# Run unit tests composer test # Run functional tests (makes actual API calls) composer test-functional
For detailed testing documentation, see tests/README.md.
Upgrading from v2.x to v3.0
No changes needed if you use the package as-is
The package works out-of-the-box with SOAP as the default client, exactly as before.
If you were instantiating VatValidator or Client manually
// ❌ Before (v2.x) use Danielebarbaro\LaravelVatEuValidator\Vies\Client; $validator = new VatValidator(new Client()); // ✅ After (v3.0) use Danielebarbaro\LaravelVatEuValidator\Vies\ViesSoapClient; $validator = new VatValidator(new ViesSoapClient()); // Or with REST client use Danielebarbaro\LaravelVatEuValidator\Vies\ViesRestClient; $validator = new VatValidator(new ViesRestClient());
If you want to switch to the REST client
- Publish the configuration:
php artisan vendor:publish --tag=laravel-vat-eu-validator-config - Update
config/vat-validator.php:
'client' => ViesRestClient::CLIENT_NAME,
If your tests reference Vies\Client
Update references to ViesSoapClient or use ViesClientInterface for mocking.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email barbaro.daniele@gmail.com instead of using the issue tracker.
Credits
Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
danielebarbaro/laravel-vat-eu-validator 适用场景与选型建议
danielebarbaro/laravel-vat-eu-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 409.97k 次下载、GitHub Stars 达 41, 最近一次更新时间为 2019 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「vat」 「laravel」 「danielebarbaro」 「laravel-vat-eu-validator」 「vat-eu-validator」 「vat-validator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 danielebarbaro/laravel-vat-eu-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danielebarbaro/laravel-vat-eu-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 danielebarbaro/laravel-vat-eu-validator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A VAT number check (Web Service) Plugin for CakePHP
Validate the format of EU vat numbers.
PHP VAT checker based on the European Commission web service
A Laravel package to parse KML and KMZ files
A library to deal with VAT Numbers within Teamleader CRM
Alfabank REST API integration
统计信息
- 总下载量: 409.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 41
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-05