patrixshah-uk-vat-checker/hmrc-vat-check
Composer 安装命令:
composer require patrixshah-uk-vat-checker/hmrc-vat-check
包简介
A Laravel package to check UK VAT numbers by using HMRC Goverment Portal. It's using VAT API version 2.0 with OAuth 2.
README 文档
README
A Laravel package to check UK VAT numbers using the HMRC VAT API. This package provides an easy way to integrate VAT number validation in your Laravel application.
Installation
You can install the package via composer. Run the following command:
composer require patrixshah-uk-vat-checker/hmrc-vat-check
Configuration
After installing the package, you need to publish the configuration file to customize your API credentials and endpoint URLs.
-
Step 1: Publish Configuration File Run the following Artisan command to publish the configuration file:
php artisan vendor:publish --provider="PatrixshahUKVatChecker\HmrcVatCheck\HmrcVatCheckServiceProvider" --tag=configThis command will create a hmrc_vat.php configuration file in your config directory.
-
Step 2: Set Environment Variables Next, you need to set the required environment variables in your .env file. Add the following lines to your .env file:
HMRC_CLIENT_ID=your-client-id HMRC_CLIENT_SECRET=your-client-secret HMRC_OAUTH2_URL=https://test-api.service.hmrc.gov.uk/oauth/token HMRC_GRANT_TYPE=client_credentials HMRC_SCOPE=read:vat HMRC_CHECK_VAT_NUMBER=https://test-api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup
Replace the placeholders with your actual HMRC API credentials and URLs.
-
Step 3: Clear Configuration Cache To ensure Laravel recognizes your new configuration, clear the configuration cache:
php artisan config:clear
Usage
Once you have installed and configured the package, you can use it to check VAT numbers through an API endpoint.
Example API Usage The package provides an API endpoint that you can use to check a VAT number.
-
Step 1: Define the Route (Optional) If you want to define a custom route in your Laravel application, add the following to your routes/api.php file:
use Illuminate\Support\Facades\Route; use YourVendorName\HmrcVatCheck\Controllers\VatCheckController; Route::post('/api/vat/check', [VatCheckController::class, 'checkVatNumber']);
If the route is already defined in the package, you can skip this step.
-
Step 2: Make an API Request You can now make a POST request to the /api/vat/check endpoint with the VAT number:
curl -X POST http://your-app-url/api/vat/check \ -H "Content-Type: application/json" \ -d '{"vat_number": "GB123456789"}'
-
Step 3: Handle the Response If the VAT number is valid, you will receive a JSON response like this:
{ "success": true, "data": { "target": { "name": "MS&AD Insurance", "vatNumber": "293129633", "address": { "line1": "82 Clemie Close", "postcode": "RM37 4KI", "countryCode": "GB" } }, "processingDate": "2024-08-23T13:14:06+01:00" } }If there is an error or the VAT number is invalid, you will receive a response like this:
{ "success": false, "message": "Error checking VAT number: [Error Details]" }
Customization
Configuring HMRC API Credentials You can change the API credentials and other settings by modifying the config/hmrc_vat.php file
return [ 'client_id' => env('HMRC_CLIENT_ID', 'your-client-id'), 'client_secret' => env('HMRC_CLIENT_SECRET', 'your-client-secret'), 'oauth2_url' => env('HMRC_OAUTH2_URL', 'https://test-api.service.hmrc.gov.uk/oauth/token'), 'grant_type' => env('HMRC_GRANT_TYPE', 'client_credentials'), 'scope' => env('HMRC_SCOPE', 'read:vat'), 'check_vat_number_url' => env('HMRC_CHECK_VAT_NUMBER', 'https://test-api.service.hmrc.gov.uk/organisations/vat/check-vat-number/lookup'), ];
Make sure to update these values according to your needs and the environment you are working in.
Author
- Name: Pratik Shah
- LinkedIn: Pratik Shah
License
This package is open-source software licensed under the MIT License.
patrixshah-uk-vat-checker/hmrc-vat-check 适用场景与选型建议
patrixshah-uk-vat-checker/hmrc-vat-check 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「api」 「vat」 「laravel」 「hmrc」 「uk-vat-checker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 patrixshah-uk-vat-checker/hmrc-vat-check 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 patrixshah-uk-vat-checker/hmrc-vat-check 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 patrixshah-uk-vat-checker/hmrc-vat-check 相关的其它包
同方向 / 同关键字的高下载量 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 PSR-7 compatible library for making CRUD API endpoints
Simple ASCII output of array data
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-23