mistralys / vies-vat-service
获取增值税号数据,并以JSON格式返回。
1.0.0
2021-06-11 07:26 UTC
Requires
- ext-json: *
- dragonbe/vies: 2.2.0
- mistralys/application-utils: >=1.3.1
Requires (Dev)
- phpunit/phpunit: >=9.5.2
README
对VIES增值税服务进行包装,以JSON格式获取数据。
获取数据
发送请求
只需调用具有vatid
参数的端点
/url/to/endpoint/?vatid=FR00000000
请求始终返回包含status
键的JSON。这指定了请求本身是否成功,而不是增值税号是否有效。
成功请求
成功请求返回关于结果的详细数据。相关部分存储在data > result
下。
{ "status": "success", "data": { "result":{ "vatID":{ "countryCode":"FR", "number":"00000000" }, "valid":true, "identifier":"WJFS4465465SD", "date":"2021-03-17T07:17:07+0100", "companyName":"---", "companyAddress":"---" }, "requester":{ "name":"Company name", "companyType":"", "street":"Street address", "city":"City", "postcode":"00000", "vatID":{ "countryCode":"FR", "number":"000000" } }, "requesterMatch":{ "name":"", "companyType":"", "street":"", "postcode":"", "city":"" } } }
注意:请求者信息是已在服务配置中指定的,在
config.php
中。
根据经验,结果集中的公司名称和地址经常缺失,因此最好不要依赖它。请求者匹配也是如此。
失败请求
请求可能会失败,例如,如果VIES增值税服务宕机。错误消息详细说明了原因。
{ "status": "error", "message": "Error message", "code": 145 }
解析增值税号字符串
静态VatID::parse()
方法接受格式化和未格式化的增值税号字符串。它自动删除大多数常用分隔符和空白字符。
以下所有示例都返回一个有效的VatID
实例
VatID::parse('FR 123 456 78'); VatID::parse('FR-12345678'); VatID::parse('[DE]12-34-56-78'); VatID::parse('de12345678'); // Lowercase country code
运行测试套件
要运行测试,首先将tests/config.dist.php
重命名为tests/config.php
,并填写必要的信息以启用针对VIES服务的实时测试。
可以使用run-tests.bat
在Windows上启动测试。在linux上,运行以下命令
vendor/bin/phpunit