PHP Classes

PHP VAT Number Check: Validate and query VAT related information

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 332 All time: 7,127 This week: 96Up
Version License PHP version Categories
vatlayer 1.0GNU General Publi...5PHP 5, Web services, Finances


This class can validate and query VAT related information.

It can send HTTP requests to the VAT Layer API Web servers to perform several operations related with VAT numbers. Currently it can:

- Validate VAT numbers
- Retrieve company information for a given VAT number
- Get country specific VAT rates including reduced rates by type
- Perform VAT compliant pricing calculations

It supports all countries in the European Union.

Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 59
All time rank: 608 in United States United States
Week rank: 16 Up2 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x


usage example
vatLayer 1.0

//instantiate the class
$vatLayer = new vatLayer();

//validate vat number
echo '<h4>Validate VAT Number</h4>';

//set api end point to validate

//set the vat number
//we use the setParam method to set the parameter and value
//to send to the api

//get the api response

//the response object will be in the class property response
//we need to ensure that the countries vat database was online
//before trusting the validation
if( $vatLayer->response->database == 'ok' ){
//manage the booleans
$valid = ( $vatLayer->response->valid ) ? 'Yes' : 'No';
$formatValid = ( $vatLayer->response->format_valid ) ? 'Yes' : 'No';
'VAT number: '.$vatLayer->response->vat_number.'<br>';
'Correct format: '.$formatValid.'<br>';
'Valid: '.$valid.'<br>';
'Country Code: '.$vatLayer->response->country_code.'<br>';
'Company: '.$vatLayer->response->company_name.'<br>';
'Address: '.$vatLayer->response->company_address.'<br>';
'sorry, '.$vatLayer->response->country_code.' vat database is offline<br>';

//get VAT rates for a specified country
echo '<h4>VAT Rates by country code</h4>';

//set api end point to rate

//reset parameters for new request

//set the country code

//get the api response

'The returned response contains the following, including reduced rates<br>';

//calculate vat compliant price
echo '<h4>Calculate VAT compliant price</h4>';

//set api end point to price

//reset parameters for new request

//set the country code

//set the amount to calculate VAT on

//get the api response

'Item purchased in '.$vatLayer->response->country_name.' for '.$vatLayer->response->price_excl_vat.' costs '.$vatLayer->response->price_incl_vat.' including VAT<br>';

'<br>Items in reduced VAT types also supported<br>';

//set the vat type parameter, in addition to already set parameters

//get the api response

'<br>'.$vatLayer->response->type.' goods cost '.$vatLayer->response->price_incl_vat.' using a VAT rate of '.$vatLayer->response->vat_rate.'<br>';

//reduced vat rate types
//this api call is not charged against your monthtly limit
echo '<h4>List of reduced VAT rate types</h4>';

//set the api end point to types

//reset parameters for new request
//there are no parameters sent to the types end point

//get api response

//show types
foreach( $vatLayer->response->types as $type ){

//all vat rates by country
//to conserve bandwidth, this end point is not automatically shown
//uncomment the following lines to see it in operation

//echo '<h4>Returned object for all VAT rates by country</h4>';


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example Usage
Accessible without login Plain text file license.txt Lic. License
Plain text file vatlayer.class.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:7,127
This week:96Up