VATRates
Up-to-date European VAT Rates
vatrates.nickstakenburg.com
VAT rates stored in JSON
format, with Javascript and PHP classes for easy access.
Install
Download
CDN
<script src='https://unpkg.com/vatrates@2/dist/vatrates.min.js'></script>
<script src='https://unpkg.com/vatrates@2/dist/vatrates.js'></script>
NPM
npm install vatrates
Composer
For the PHP package:
composer require staaky/vatrates
Javascript
Require vatrates or use a script tag to include vatrates.js:
var vatRates = require('vatrates');
<script src='vatrates.js'></script>
An instance created with new VATRates()
gives you several VAT rate functions. It's recommended to always use an isVATCountry()
check before using them, like this:
var VATRates = require('vatrates');
var vatRates = new VATRates();
if (vatRates.isVATCountry('RO')) {
console.log(vatRates.getSuperReducedRate('RO'));
console.log(vatRates.getReducedRates('RO'));
console.log(vatRates.getStandardRate('RO'));
console.log(vatRates.getParkingRate('RO'));
}
Default rates are for today, to get rates for a different day pass in a Date
:
var vatRates = new VATRates(new Date('2016-01-01'));
if (vatRates.isVATCountry('RO')) {
console.log(vatRates.getStandardRate('RO'));
}
You can also change the date by calling setDate()
on a previously created instance:
var vatRates = new VATRates();
vatRates.setDate(new Date('2015-01-01'));
if (vatRates.isVATCountry('RO')) {
console.log(vatRates.getStandardRate('RO'));
}
getCountry(countryCode)
Another approach is to use getCountry()
, it returns a VATCountry
or undefined
if the country doesn't use VAT. With a VATCountry you'll have all the VAT rate functions and some extra helpers.
var vatRates = new VATRates();
var country;
if ((country = vatRates.getCountry('GB'))) {
console.log(country.getName());
console.log(country.getCode());
console.log(country.getCountryCode());
console.log(country.getSuperReducedRate());
console.log(country.getReducedRates());
console.log(country.getStandardRate());
console.log(country.getParkingRate());
}
The United Kingdom and Greece use extra non standard country codes "UK" and "EL", these are also accepted.
vatRates.getCountry('UK');
getCountries()
Returns an Array
of all the countries using VAT, as VATCountry
's.
var vatRates = new VATRates();
var countries = vatRates.getCountries();
countries.forEach(function(country) {
console.log(country.getCountryCode() + " has VAT: " + country.getStandardRate());
});
setDate(date)
Set the Date
for which to return VAT rates.
var vatRates = new VATRates();
vatRates.setDate(new Date('2015-01-01'));
This is identical to:
var vatRates = new VATRates(new Date('2015-01-01'));
All other functions take this date into account, so make sure to always set the date first.
isVATCountry(countryCode)
Returns true
if a country uses VAT, or false
if not.
var vatRates = new VATRates();
console.log(vatRates.isVATCountry('FR'));
console.log(vatRates.isVATCountry('US'));
getSuperReducedRate(countryCode)
Returns the super reduced rate for a country, or undefined
when none is available.
var vatRates = new VATRates();
if (vatRates.isVATCountry('FR')) {
console.log(vatRates.getSuperReducedRate('FR'));
});
A VATCountry
returned by getCountry()
offers this method directly.
var vatRates = new VATRates();
var country;
if ((country = vatRates.getCountry('FR'))) {
console.log(country.getName());
console.log(country.getSuperReducedRate());
}
getReducedRates(countryCode)
Returns an Array
of reduced rates for a country, or undefined
when none are available.
var vatRates = new VATRates();
if (vatRates.isVATCountry('IE')) {
console.log(vatRates.getReducedRates('IE'));
});
A VATCountry
offers this method directly.
var vatRates = new VATRates();
var country;
if ((country = vatRates.getCountry('IE'))) {
console.log(country.getName());
console.log(country.getReducedRates());
}
getStandardRate(countryCode)
Returns the standard rate for a country, or undefined
when none is available.
var vatRates = new VATRates();
if (vatRates.isVATCountry('NL')) {
console.log(vatRates.getStandardRate('NL'));
});
A VATCountry
offers this method directly.
var vatRates = new VATRates();
var country;
if ((country = vatRates.getCountry('NL'))) {
console.log(country.getName());
console.log(country.getStandardRate());
}
getParkingRate(countryCode)
Returns the parking rate for a country, or undefined
when none is available.
var vatRates = new VATRates();
if (vatRates.isVATCountry('LU')) {
console.log(vatRates.getParkingRate('LU'));
}
A VATCountry
offers this method directly.
var vatRates = new VATRates();
var country;
if ((country = vatRates.getCountry('LU'))) {
console.log(country.getName());
console.log(country.getParkingRate());
}
PHP
After installing through Composer use Staaky\VATRates\VATRates
composer require staaky/vatrates
use Staaky\VATRates\VATRates;
An instance created with new VATRates()
gives you several VAT rate functions. It's recommended to always use an isVATCountry()
check before using them, like this:
$vatRates = new VATRates();
if ($vatRates->isVATCountry('RO')) {
var_dump($vatRates->getSuperReducedRate('RO'));
var_dump($vatRates->getReducedRates('RO'));
var_dump($vatRates->getStandardRate('RO'));
var_dump($vatRates->getParkingRate('RO'));
}
Default rates are for today, to get rates for a different day pass in a DateTime
:
$vatRates = new VATRates(new DateTime('2016-01-01'));
if ($vatRates->isVATCountry('RO')) {
var_dump($vatRates->getStandardRate('RO'));
}
You can also change the date by calling setDate()
on a previously created instance:
$vatRates = new VATRates();
$vatRates->setDate(new DateTime('2015-01-01'));
if ($vatRates->isVATCountry('RO')) {
var_dump($vatRates->getStandardRate('RO'));
}
getCountry(countryCode)
Another approach is to use getCountry()
, it returns a VATCountry
or null
if the country doesn't use VAT. With a VATCountry
you'll have all the VAT rate functions and some extra helpers.
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('GB'))) {
var_dump($country->getName());
var_dump($country->getCode());
var_dump($country->getCountryCode());
var_dump($country->getSuperReducedRate());
var_dump($country->getReducedRates());
var_dump($country->getStandardRate());
var_dump($country->getParkingRate());
}
The United Kingdom and Greece use extra non standard country codes "UK" and "EL", these are also accepted.
$vatRates->getCountry('UK');
getCountries()
Returns an array
of all the countries using VAT, as VATCountry
's.
$vatRates = new VATRates();
$countries = $vatRates->getCountries();
foreach ($countries as $country) {
print_r($country->getCountryCode() . " has VAT: " . $country->getStandardRate() . "\n");
}
setDate(DateTime $date)
Set the date for which to return VAT rates.
$vatRates = new VATRates();
$vatRates->setDate(new DateTime('2015-01-01'));
This is identical to:
$vatRates = new VATRates(new DateTime('2015-01-01'));
All other functions take this date into account, so make sure to always set the date first.
isVATCountry($countryCode)
Returns true
if a country uses VAT, or false
if not.
$vatRates = new VATRates();
var_dump($vatRates->isVATCountry('FR'));
var_dump($vatRates->isVATCountry('US'));
getSuperReducedRate($countryCode)
Returns the super reduced rate for a country, or null
if none is available.
$vatRates = new VATRates();
if ($vatRates->isVATCountry('FR')) {
var_dump($vatRates->getSuperReducedRate('FR'));
});
A VATCountry
returned by getCountry()
offers this method directly.
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('FR'))) {
var_dump($country->getName());
var_dump($country->getSuperReducedRate());
}
getReducedRates($countryCode)
Returns an array
of reduced rates for a country, or null
if none are available.
$vatRates = new VATRates();
if ($vatRates->isVATCountry('IE')) {
var_dump($vatRates->getReducedRates('IE'));
}
A VATCountry
offers this method directly.
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('IE'))) {
var_dump($country->getName());
var_dump($country->getReducedRates());
}
getStandardRate($countryCode)
Returns the standard rate for a country, or null
when none is available.
$vatRates = new VATRates();
if ($vatRates->isVATCountry('NL')) {
var_dump($vatRates->getStandardRate('NL'));
});
A VATCountry
offers this method directly.
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('NL'))) {
var_dump($country->getName());
var_dump($country->getStandardRate());
}
getParkingRate($countryCode)
Returns the parking rate for a country, or null
when none is available.
$vatRates = new VATRates();
if ($vatRates->isVATCountry('LU')) {
var_dump($vatRates->getParkingRate('LU'));
});
A VATCountry
offers this method directly.
$vatRates = new VATRates();
if (($country = $vatRates->getCountry('LU'))) {
var_dump($country->getName());
var_dump($country->getParkingRate());
}
Development
Webpack
Use webpack
to create a new build after you've made changes.
webpack
Gulp
Use gulp
to load up the page in the /example
folder. It shows the output of all files (Javascript, JSON & PHP) and automatically rebuilds with webpack as you modify source code.
gulp
Unit Tests
Run unit tests using npm test
, this runs tests for every language.
npm test
Javascript tests are run with Mocha and PHP tests with Peridot. They can be run individually as well:
npm run mocha
npm run peridot
Contribute
VAT rates are kept up to date manually using data from the European Commission and VATLive.com. Initial historic rates are based on data from jsonvat.com.
If you notice an incorrect rate please create an issue or send a pull request. Future VAT changes can also be added to the JSON
file. If you know of an upcoming change that isn't listed yet, please let me know.
Data on historic VAT rates is also appreciated. This can be hard to track down, especially the non-standard rates.
License
VATRates is MIT Licensed