arraypress/vat-sense
Composer 安装命令:
composer require arraypress/vat-sense
包简介
A PHP library for integrating with the VAT Sense API in WordPress, providing VAT validation, tax rate information, and currency conversion. Features WordPress transient caching and WP_Error support.
关键字:
README 文档
README
A comprehensive PHP library for integrating with the VAT Sense API in WordPress applications.
Features
- VAT Number Validation: Validate VAT numbers against EU, UK, and other supported countries
- EORI Number Validation: Validate Economic Operators Registration and Identification numbers
- Tax Rate Information: Get tax rates for specific countries, including standard, reduced, and zero rates
- Currency Conversion: Convert between currencies using official exchange rates
- VAT Price Calculation: Calculate VAT-inclusive and VAT-exclusive prices
- Invoice Creation and Management: Create, retrieve, update, and delete VAT-compliant invoices
- WordPress Integration: Built-in transient caching and WP_Error support
- Complete API Coverage: All VAT Sense API endpoints supported
Installation
Install via Composer:
composer require arraypress/vat-sense
Usage
Initialization
use ArrayPress\VAT\Sense\Client; // Initialize the client with your VAT Sense API key $client = new Client('your_vat_sense_api_key_here'); // Optionally, configure caching $client->set_cache_enabled(true); $client->set_cache_expiration(HOUR_IN_SECONDS * 12); // 12 hours
VAT Number Validation
// Validate a VAT number $response = $client->validate_vat('GB123456789'); if (is_wp_error($response)) { echo "Error: " . $response->get_error_message(); } else { if ($response->is_vat_valid()) { echo "VAT number is valid!"; echo "Company name: " . $response->get_company_name(); echo "Company address: " . $response->get_company_address(); echo "Country code: " . $response->get_country_code(); } else { echo "VAT number is not valid."; } }
Get Tax Rates
// Get tax rates for a country $response = $client->get_rates_filtered('DE'); if (!is_wp_error($response)) { $standard_rate = $response->get_standard_rate_percentage(); echo "Standard VAT rate: {$standard_rate}%"; // Get reduced rates if available $reduced_rates = $response->get_reduced_rates(); if ($reduced_rates) { foreach ($reduced_rates as $rate) { echo "Reduced rate: {$rate['rate']}%"; } } } // Find a tax rate for a specific product type $response = $client->find_tax_rate('FR', '', 'ebooks');
Calculate VAT Prices
// Calculate VAT on a price $response = $client->calculate_vat_price(100.00, 20.0, 'excl'); if (!is_wp_error($response)) { $price_excl_vat = $response->get_price_excl_vat(); $price_incl_vat = $response->get_price_incl_vat(); $vat_amount = $response->get_vat_amount(); echo "Price (excl. VAT): {$price_excl_vat}"; echo "VAT amount: {$vat_amount}"; echo "Price (incl. VAT): {$price_incl_vat}"; }
Currency Conversion
// Convert currency $response = $client->convert_currency('USD', 'EUR', 50.00); if (!is_wp_error($response)) { $converted_amount = $response->get_converted_amount(); $exchange_rate = $response->get_exchange_rate(); echo "50.00 USD = {$converted_amount} EUR (rate: {$exchange_rate})"; }
Create and Manage Invoices
// Create an invoice $invoice_data = [ 'date' => date('Y-m-d H:i:s'), 'tax_point' => date('Y-m-d H:i:s'), 'type' => 'sale', 'tax_type' => 'incl', 'currency_code' => 'EUR', 'business' => [ 'name' => 'My Company', 'address' => "123 Business Street\nLondon\nSW1 1AA\nUnited Kingdom", 'vat_number' => 'GB123456789', 'company_number' => '12345678' ], 'customer' => [ 'name' => 'Client Company', 'address' => "456 Client Avenue\nBerlin\n10115\nGermany", 'vat_number' => 'DE987654321' ], 'items' => [ [ 'item' => 'Professional services', 'quantity' => 1, 'price_each' => 500.00, 'vat_rate' => 19.0 ] ] ]; $response = $client->create_invoice($invoice_data); if (!is_wp_error($response)) { $invoice_id = $response->get_invoice_id(); $invoice_url = $response->get_invoice_url(); $invoice_pdf_url = $response->get_invoice_url(true); echo "Invoice created successfully!"; echo "Invoice ID: {$invoice_id}"; echo "Invoice URL: {$invoice_url}"; echo "Invoice PDF URL: {$invoice_pdf_url}"; }
Check API Usage
// Check API usage $response = $client->get_usage(); if (!is_wp_error($response)) { $total = $response->get_total_requests(); $used = $response->get_used_requests(); $remaining = $response->get_remaining_requests(); echo "API Usage:"; echo "Total allowed: {$total}"; echo "Used: {$used}"; echo "Remaining: {$remaining}"; }
Cache Management
The library includes built-in caching using WordPress transients:
// Enable or disable caching $client->set_cache_enabled(true); // Set cache expiration time (in seconds) $client->set_cache_expiration(DAY_IN_SECONDS); // Clear all cached data $client->clear_cache(); // Clear specific cached data $client->clear_cache('vat_validate_GB123456789');
API Documentation
For detailed API documentation, visit the VAT Sense API Reference.
Requirements
- PHP 7.4 or later
- WordPress 5.0 or later
License
This library is licensed under the GPL v2 or later.
Credits
Developed by ArrayPress
arraypress/vat-sense 适用场景与选型建议
arraypress/vat-sense 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ecommerce」 「wordpress」 「vat」 「invoicing」 「woocommerce」 「tax-rates」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/vat-sense 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/vat-sense 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/vat-sense 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A VAT number check (Web Service) Plugin for CakePHP
Nevogate Payment Gateway SDK
Validate the format of EU vat numbers.
PHP VAT checker based on the European Commission web service
Dealing with payments through the Egyptian payment gateway PayMob
A library to deal with VAT Numbers within Teamleader CRM
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-09-02