VIES (VAT Information Exchange System) is an electronic means of transmitting information relating to VAT-registration (= validity of VAT-numbers) of companies registered in EU.
Use PHP and SOAP to create easy verification of the VAT-number validation.
namespace libs\vies;
use SoapClient;
use SoapFault;
class VatChecker {
/**
*
* @var boolean
*/
private $valid;
/**
*
* @var string
*/
private $vatId;
/**
*
* @var SoapClient
*/
private $client;
public function __construct($vatId){
$this->vatId = $vatId;
$this->client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
$this->valid = $this->validate();
}
private function validate(){
$countryCode = substr($this->vatId, 0, 2);
$vatNumber = substr($this->vatId, 2);
$params = array('countryCode' => $countryCode, 'vatNumber' => $vatNumber);
try{
$result = $this->client->checkVat($params);
return $result->valid;
} catch(SoapFault $e) {
echo 'Error: '.$e->faultstring;
}
}
/**
* @return boolean
*/
public function isValid()
{
return $this->valid;
}
}
And here is an example of the use of this class:
use \libs\vies\VatChecker; $vatNumber = 'CZ27251748'; /* @var $vatChecker \libs\vies\VatChecker */ $vatChecker = new VatChecker($vatNumber); echo $vatChecker->isValid();That's all. Now you can easily check if your business partner from the European Union is a VAT payer.

Comments
Post a Comment