node-sales-tax

International sales tax calculator for Node (offline, except for VAT number validation). Tax rates are kept up-to-date.
You may use it to calculate VAT rates for countries in the European Union (VAT MOSS), GST in Canada, or get VAT for countries such as China, or even Hong Kong (which has no VAT).
Who uses it?
 |
Crisp |
👋 You use sales-tax and you want to be listed there? Contact me!
How to install?
Include sales-tax
in your package.json
dependencies.
Alternatively, you can run npm install sales-tax --save
.
How to use?
This module may be used to acquire the billable VAT percentage for a given customer. You may also use it directly to process the total amount including VAT you should bill; and even to validate a customer's VAT number.
:red_circle: Important: in order to fetch the sales tax for a customer, you need to know their country. The country must be passed to all module methods, formatted as ISO ALPHA-2 (eg. France is FR, United States is US).
:arrow_right: Import the module
Import the module in your code:
var SalesTax = require("sales-tax");
:white_check_mark: Check if a country / state has sales tax
Check if France has any sales tax (returns true
):
var franceHasSalesTax = SalesTax.hasSalesTax("FR")
var brazilHasSalesTax = SalesTax.hasSalesTax("BR")
var hongKongHasSalesTax = SalesTax.hasSalesTax("HK")
:white_check_mark: Get the sales tax for a customer
:fr: Given a French customer VAT number (eg. here SAS CLEVER CLOUD
with VAT number FR 87524172699
):
SalesTax.getSalesTax("FR", "87524172699")
.then((tax) => {
});
Note: Clever-Cloud is a real living business from France, check their website there.
:latvia: Given a Latvian customer without any VAT number (eg. a physical person):
SalesTax.getSalesTax("LV")
.then((tax) => {
});
:hong_kong: Given an Hong Kong-based customer (eg. a physical person):
SalesTax.getSalesTax("HK")
.then((tax) => {
});
:es: Given a Spanish customer who provided an invalid VAT number (eg. a rogue individual):
SalesTax.getSalesTax("ES", "12345523")
.then((tax) => {
});
:white_check_mark: Process the price including sales tax for a customer
:estonia: Given an Estonian customer without any VAT number, buying for 100.00€ of goods (eg. a physical person):
SalesTax.getAmountWithSalesTax("EE", 100.00)
.then((amountWithTax) => {
});
:white_check_mark: Validate tax number for a customer
:fr: Given a French customer VAT number (eg. here SAS CLEVER CLOUD
with VAT number FR 87524172699
):
SalesTax.validateTaxNumber("FR", "87524172699")
.then((isValid) => {
});
:latvia: Given a Latvian customer without any VAT number (eg. a physical person):
SalesTax.validateTaxNumber("LV")
.then((isValid) => {
});
:es: Given a Spanish customer who provided an invalid VAT number (eg. a rogue individual):
SalesTax.validateTaxNumber("ES", "12345523")
.then((isValid) => {
});
:white_check_mark: Check if a customer is tax-exempt
:fr: Given a French customer VAT number (eg. here SAS CLEVER CLOUD
with VAT number FR 87524172699
):
SalesTax.isTaxExempt("FR", "87524172699")
.then((isTaxExempt) => {
});
:morocco: Given a Morocco-based customer:
SalesTax.isTaxExempt("MA")
.then((isTaxExempt) => {
});
:hong_kong: Given an Hong Kong-based customer:
SalesTax.isTaxExempt("HK")
.then((isTaxExempt) => {
});
Where is the offline tax data is pulled from?
The offline tax data is pulled from VAT, GST and sales tax rates — ey.com.
It is kept up-to-date with the year-by-year tax changes worldwide.
Some countries have multiple sales tax, eg. Brazil. In those cases, the returned sales tax is the one on services. Indeed, I consider most users of this module use it for their SaaS business — in other words, service businesses.
How are tax numbers validated?
For now, this module only supports tax number (VAT number) validation for European countries.
:eu: European countries
European VAT numbers are validated against the official ec.europa.eu
API, which return whether a given VAT number exists or not. This helps you ensure a customer-provided VAT number is valid (ie. you don't have to bill VAT for this customer).
You can manually check a VAT number on VIES VAT number validation.