Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Vat Calculator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-Native Compatibility: The package is designed for Laravel (via facade) but also supports standalone PHP, making it a strong fit for Laravel-based e-commerce, SaaS, or subscription platforms. The BillableWithinTheEU trait integrates seamlessly with Laravel Cashier (pre-v13), addressing a critical gap in EU VAT compliance for subscription billing.
  • Modular Design: Core functionality (tax calculation, VAT validation) is decoupled from Laravel-specific features (e.g., Cashier integration), allowing selective adoption. The package’s configuration-driven approach (e.g., vat_calculator.php) enables customization without forking.
  • EU MOSS/OSS Alignment: Explicitly addresses EU VAT rules, including postal-code-based rate adjustments (e.g., German reduced rates for certain regions) and B2B vs. B2C differentiation, which is critical for compliance with EU VAT Directive 2006/112/EC and MOSS/OSS regulations.
  • Extensibility: Supports custom VAT rules via configuration, allowing businesses to override default rates (e.g., for specific product categories or exemptions).

Integration Feasibility

  • Low Friction for Laravel Apps:
    • Facade-based API (VatCalculator::calculate()) requires minimal code changes.
    • Validation Rule (ValidVatNumber) integrates directly with Laravel’s validator.
    • Cashier Trait (BillableWithinTheEU) provides a drop-in replacement for taxPercentage, reducing refactoring effort.
  • Standalone PHP Support: Can be used in non-Laravel PHP apps (e.g., legacy systems, microservices) with minor adjustments (e.g., instantiating VatCalculator manually).
  • Third-Party Dependencies:
    • VIES SOAP API: For VAT validation, introduces external dependency risk (API downtime, rate limits).
    • HMRC API: Required for UK VAT validation, adding authentication complexity (OAuth2 via .env).
    • No hard dependencies on other Laravel packages (e.g., no Guzzle, Symfony HTTP client required).

Technical Risk

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.

Key Questions for TPM

  1. Compliance Requirements:
    • Does the business operate in multiple EU countries? If so, does the package’s postal-code-based rate detection cover all edge cases (e.g., German reduced rates)?
    • Are there non-EU markets (e.g., UK post-Brexit, Switzerland)? The package supports UK VAT but may need adjustments for other regions.
  2. Cashier Version:
    • Is the app using Laravel Cashier v13+? If yes, how will tax logic be handled without the BillableWithinTheEU trait?
  3. VAT Validation Workflow:
    • Is real-time VAT validation required for all transactions, or can format validation (isValidVatNumberFormat) suffice for initial checks?
    • What’s the fallback strategy if the VIES/HMRC APIs are down? (e.g., manual review, cached responses)
  4. Customization Needs:
    • Are there product-specific VAT exemptions (e.g., digital vs. physical goods) not covered by the package?
    • Does the business need audit logs for VAT calculations? The package doesn’t provide this out-of-the-box.
  5. Scaling:
    • How many VAT validation requests are expected per day? The SOAP API may have rate limits.
    • Will caching (e.g., Redis) be implemented for VAT rates or validation responses?

Integration Approach

Stack Fit

  • Primary Use Case: Laravel-based e-commerce, SaaS, or subscription platforms selling to EU customers.
  • Secondary Use Case: Standalone PHP applications needing VAT calculation (e.g., legacy systems, microservices).
  • Compatibility:
    • Laravel: Full integration via facade, validation rule, and Cashier trait.
    • Non-Laravel PHP: Requires manual instantiation of VatCalculator (minimal effort).
    • Symfony: Could be adapted with minor changes (e.g., DI container binding).
    • Other Frameworks: Not directly supported; would require wrapper logic.

Migration Path

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.

Compatibility

  • PHP Version: Requires PHP 7.3+ (no issues for modern stacks).
  • Laravel Version: Optimized for Laravel 6+; may need adjustments for older versions (e.g., Cashier v6 support).
  • Database: No schema changes required.
  • Dependencies:
    • SOAP Extension: Required for VAT validation (enabled by default in PHP).
    • cURL/HTTP Client: Used for HMRC UK API (if enabled).
    • No heavy dependencies (e.g., no queue workers, event listeners by default).

Sequencing

  1. Phase 1: Core Tax Calculation
    • Replace manual VAT logic with VatCalculator::calculate().
    • Validate against business country code and postal codes.
  2. Phase 2: VAT Validation
    • Integrate ValidVatNumber rule into checkout forms.
    • Implement fallback for VIES API downtime (e.g., cached responses or manual review).
  3. Phase 3: Cashier Integration (if applicable)
    • Apply BillableWithinTheEU trait (only for Cashier < v13).
    • Test B2B vs. B2C tax differentiation.
  4. Phase 4: UK VAT Support
    • Register with HMRC and configure .env for UK VAT validation.
  5. Phase 5: Performance Optimization
    • Cache VAT rates and validation responses (e.g., Redis).
    • Implement retry logic for SOAP API failures.

Operational Impact

Maintenance

  • Configuration-Driven Updates:
    • VAT rates are configurable (no code changes needed for EU updates).
    • Upgrade Path: Follow the UPGRADE.md guide; breaking changes are rare (e.g., Cashier v13+ incompatibility).
  • Dependency Management:
    • VIES/HMRC APIs: Monitor for changes (e.g., rate limits, authentication updates).
    • SOAP Client: May require updates if EU changes their API schema.
  • Custom Rules:
    • Business-specific VAT rules (e.g., exemptions) must be manually added to the config.

Support

  • Troubleshooting:
    • VAT Validation Failures: Check if VIES/HMRC APIs are down (package provides graceful fallbacks).
    • Cashier Issues: Ensure compatibility with the installed version (v13+ requires work
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky