mpociot/vat-calculator
EU VAT/MOSS calculator for Laravel/Cashier or standalone PHP. Calculate gross prices and tax rates by country/postal code, handle B2B/B2C rules, and validate EU VAT numbers. Simple API via facade or instance.
BillableWithinTheEU trait integrates seamlessly with Laravel Cashier (pre-v13), addressing a critical gap in EU VAT compliance for subscription billing.vat_calculator.php) enables customization without forking.VatCalculator::calculate()) requires minimal code changes.ValidVatNumber) integrates directly with Laravel’s validator.BillableWithinTheEU) provides a drop-in replacement for taxPercentage, reducing refactoring effort.VatCalculator manually)..env).| Risk Area | Severity | Mitigation |
|---|---|---|
| VIES API Unavailability | High | Graceful fallback (returns false), configurable timeout (default: 30s), and forward_soap_faults option to throw exceptions. |
| UK VAT API Dependency | Medium | Requires HMRC registration; fails gracefully if unavailable. |
| Cashier v13+ Incompatibility | High | Blocker for new Laravel apps using Cashier v13+. Workaround: Downgrade or use standalone tax logic. |
| Postal Code Edge Cases | Medium | Package handles ZIP-based rate adjustments (e.g., Germany), but business-specific rules (e.g., exemptions) may require custom logic. |
| Data Staleness | Low | VAT rates are configuration-driven; updates require manual config changes (not auto-fetched). |
| Performance | Low | SOAP calls for VAT validation are synchronous and may introduce latency. Caching responses (e.g., Redis) could mitigate this. |
BillableWithinTheEU trait?isValidVatNumberFormat) suffice for initial checks?VatCalculator (minimal effort).| Scenario | Integration Steps |
|---|---|
| Greenfield Laravel App | 1. Install via Composer. 2. Publish config (php artisan vendor:publish). 3. Set business_country_code in config. 4. Use VatCalculator::calculate() in pricing logic. 5. (Optional) Integrate with Cashier. |
| Existing Laravel App | 1. Install package. 2. Replace manual tax calculations with VatCalculator. 3. Add VAT validation to checkout forms using ValidVatNumber rule. 4. Test edge cases (e.g., German ZIP codes). |
| Non-Laravel PHP | 1. Install via Composer. 2. Instantiate VatCalculator manually. 3. Set business country code ($calculator->setBusinessCountryCode('DE')). 4. Use calculate() method. |
| Cashier v13+ Apps | 1. Option A: Downgrade Cashier to v12. 2. Option B: Replace taxPercentage with custom logic using VatCalculator. 3. Option C: Use standalone tax logic in subscription workflows. |
VatCalculator::calculate().ValidVatNumber rule into checkout forms.BillableWithinTheEU trait (only for Cashier < v13)..env for UK VAT validation.How can I help you explore Laravel packages today?