Download the PHP package mpociot/vat-calculator without Composer

On this page you can find all versions of the php package mpociot/vat-calculator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package vat-calculator

VatCalculator

Tests

Coding Standards

Latest Stable Version

Total Downloads

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a standalone PHP application. Originally created by Marcel Pociot.

[!WARNING]
This package does not provide any promises for correctly calculated taxes. You are still responsible to making sure that any calculated tax is correct for your use case. If you're uncertain if a certain tax is correct or not, it's best that you talk to an accountant.

Requirements

Installation

Install the package with composer:

Standalone

You can also use this package without Laravel. Simply create a new instance of the VatCalculator and use it. All documentation examples use the Laravel Facade code, so make sure not to call the methods as if they were static methods.

Upgrading

Please refer to the upgrade guide when upgrading the library.

Usage

Calculate the gross price

To calculate the gross price use the calculate method with a net price and a country code as parameters.

The third parameter is the postal code of the customer.

As a fourth parameter, you can pass in a boolean indicating whether the customer is a company or a private person. If the customer is a company, which you should check by validating the VAT number, the net price gets returned.

Receive more information

After calculating the gross price you can extract more information from the VatCalculator.

Validate EU VAT numbers

Prior to validating your customers VAT numbers, you can use the shouldCollectVAT method to check if the country code requires you to collect VAT in the first place.

To validate your customers VAT numbers, you can use the isValidVATNumber method. The VAT number should be in a format specified by the VIES. The given VAT numbers will be truncated and non relevant characters / whitespace will automatically be removed.

This service relies on a third party SOAP API provided by the EU. If, for whatever reason, this API is unavailable a VATCheckUnavailableException will be thrown.

Alternatively, it is also possible to validate only the format of the VAT Number specified by VIES. This is useful, if you do not want to wait for a response from the SOAP API.

Get EU VAT number details

To get the details of a VAT number, you can use the getVATDetails method. The VAT number should be in a format specified by the VIES. The given VAT numbers will be truncated and non relevant characters / whitespace will automatically be removed.

This service relies on a third party SOAP API provided by the EU. If, for whatever reason, this API is unavailable a VATCheckUnavailableException will be thrown.

UK VAT Numbers

UK VAT numbers are formatted a little differently:

Laravel

Configuration

By default, the VatCalculator has all EU VAT rules predefined, so that it can easily be updated, if it changes for a specific country.

If you need to define other VAT rates, you can do so by publishing the configuration and add more rules.

Warning
Be sure to set your business country code in the configuration file, to get correct VAT calculation when selling to business customers in your own country.

To publish the configuration files, run the vendor:publish command

This will create a vat_calculator.php in your config directory.

Handling SOAP Faults

If for some reason, SOAP faults happen when the VIES API is faulty, these errors will be handled gracefully and false will be returned. However, if you explicitly want to be aware of any SOAP faults you may instruct VatCalculator to throw them as a VATCheckUnavailableException. The VATCheckUnavailableException will then contain the specific message of the SOAP fault.

Set the option to true in your config file:

You can also set a timeout for the SOAP client. By default, SOAP aborts the request to VIES after 30 seconds. If you do not want to wait that long, you can reduce the timeout, for example to 10 seconds:

ValidVatNumber Validation Rule

VatCalculator also ships with a ValidVatNumber validation rule for VAT Numbers. You can use this when validation input from a form request or a standalone validator instance:

[!WARNING]
The validator extension returns false when the VAT ID Check SOAP API is unavailable.

Cashier Stripe Integration

[!NOTE]
At the moment this package is not compatible with Cashier Stripe v13 or higher because it still relies on the old taxPercentage method which has been removed from Cashier v13. You can still use it on older Cashier Stripe versions in the meantime.

If you want to use this package in combination with Laravel Cashier Stripe you can let your billable model use the BillableWithinTheEU trait. Because this trait overrides the taxPercentage method of the Billable trait, we have to explicitly tell our model to do so.

By using the BillableWithinTheEU trait, your billable model has new methods to set the tax rate for the billable model.

Set everything in one command:

Or use the more readable, chainable approach:

So in order to set the correct tax percentage prior to subscribing your customer, consider the following workflow:

Changelog

Check out the CHANGELOG in this repository for all the recent changes.

Maintainers

VatCalculator is maintained by Dries Vints. Originally created by Marcel Pociot.

License

VatCalculator is open-sourced software licensed under the MIT license.


All versions of vat-calculator with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3|~8.0.0|~8.1.0|~8.2.0|~8.3.0
ext-json Version *
ext-soap Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mpociot/vat-calculator contains the following files

Loading the files please wait ....