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: 331 This week: 1All time: 7,134 This week: 560Up
Version License PHP version Categories
vatlayer 1.0GNU General Publi...5PHP 5, Web services, Finances
Description 

Author

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: 58
All time rank: 618 in United States United States
Week rank: 20 Up3 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?php
/*
usage example
vatLayer 1.0
*/

//instantiate the class
include('vatlayer.class.php');
$vatLayer = new vatLayer();

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

//set api end point to validate
$vatLayer->setEndPoint('validate');

//set the vat number
//we use the setParam method to set the parameter and value
//to send to the api
$vatLayer->setParam('vat_number','LU26375245');

//get the api response
$vatLayer->getResponse();

//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';
   
    echo
'VAT number: '.$vatLayer->response->vat_number.'<br>';
    echo
'Correct format: '.$formatValid.'<br>';
    echo
'Valid: '.$valid.'<br>';
    echo
'Country Code: '.$vatLayer->response->country_code.'<br>';
    echo
'Company: '.$vatLayer->response->company_name.'<br>';
    echo
'Address: '.$vatLayer->response->company_address.'<br>';
}else{
    echo
'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
$vatLayer->setEndPoint('rate');

//reset parameters for new request
$vatLayer->resetParams();

//set the country code
$vatLayer->setParam('country_code','DE');

//get the api response
$vatLayer->getResponse();

echo
'The returned response contains the following, including reduced rates<br>';
var_dump($vatLayer->response);

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

//set api end point to price
$vatLayer->setEndPoint('price');

//reset parameters for new request
$vatLayer->resetParams();

//set the country code
$vatLayer->setParam('country_code','DE');

//set the amount to calculate VAT on
$vatLayer->setParam('amount',150);

//get the api response
$vatLayer->getResponse();

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

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

//set the vat type parameter, in addition to already set parameters
$vatLayer->setParam('type','medical');

//get the api response
$vatLayer->getResponse();

echo
'<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
$vatLayer->setEndPoint('types');

//reset parameters for new request
//there are no parameters sent to the types end point
$vatLayer->resetParams();

//get api response
$vatLayer->getResponse();

//show types
foreach( $vatLayer->response->types as $type ){
    echo
$type.'<br>';
}

//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>';
//$vatLayer->setEndPoint('rate_list');
//$vatLayer->getResponse();
//var_dump($vatLayer->response);

?>


  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  
 0%
Total:331
This week:1
All time:7,134
This week:560Up