I created a vat number checker package

Published in Originals on Feb 11, 2024

When populating client information in an accounting platform you have to make sure the VAT Numbers of the clients you create on the service side are correct.

In the past we've encountered issues with this, for example, when injecting client data into an accounting software the API returned with an Exception whenever the VAT Number is invalid. In small cases this is managable for the customer (owner of the saas or producted we created) to manually adjust the VAT Number (which the endcustomer inputted).

But when the product grows larger and larger, this is something you want to prompt right away, while the end customer is inputting their data.

As we needed this solution for several customers and products, I went about and made a package that does just what we need.

Installing

Installing the package is done via composer

composer require burtds/laravel-vatnumber-checker

Afterwords, you're able to fetch your desired information. There is no need to add something to the .env. file everything is present in the package.

This packages uses an API provided by the European Commission called "VIES".

Usage

You'll need to import the Facade on top of the file where you need to call the VIES API.

use Burtds\VatChecker\Facades\VatChecker

Once that's in place you can start making requests towards the service.

All the functions accept 2 parameters, respectivly the country code and the vat number that is chained onto that.
For this example we're using the VAT Number of Vulpo BV, and the country code 'BE'.

$validVatNumber = '0749617582' // Vulpo BV's VAT number

// returns the validity of a VAT number
VatChecker::isVatValid('BE', $validVatNumber); 

As the example reads, this will return a boolean true when the VAT Number is valid. In case the VAT Number is invalid, the package will throw a VatNumberNotFound exception.

Besides checking the validity of a VAT Number we can also fetch information about the related company.

// returns the company name related to the VAT number
VatChecker::getCompanyName('BE', $validVatNumber); 

// returns the company address related to the VAT number
VatChecker::getCompanyAddress('BE', $validVatNumber); 

We can also go one step further and fetch the raw data that the VIES API returns upon request.

// returns a raw response of the European Commission's API
VatChecker::getRawVatInstance('BE', $validVatNumber); 

Closing off

In the near future I'd like to add the possibility to access a VAT Number in 2 parameters or a single parameter. So I will surely add this in the coming months (whenever I find some extra time).

You're free to use this package, all feedback is more than welcome.

👉 You can find the repo on GitHub here, be sure to give it a star if you like it.



#laravel, #package, #github, #open-source, #vat