javascriptphpjqueryhtml

VIES VAT number validation


How to incorporate a form on our website to validate the VIES? I find information to validate it through the website of the European Union.

http://ec.europa.eu/taxation_customs/vies/vieshome.do

And what interest me is validate directly from the form of payment data from my website.


Solution

  • This websites sends an ordinary HTML form to a server.

    The simplest solution is to pass the params in the URL and use file_get_contents to get the response.

    The response can then be parsed to extract the information you want. Not tested, but shows the idea:

    $country1 = 'PL';
    $country2 = 'PL';
    $vatnum1 = '123456';
    $vatnum2 = '789012';
    
    //Prepare the URL
    $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms='.$country1.'&iso='.$country1.'&vat='.$vatnum1.'&name=&companyType=&street1=&postcode=&city=&requesterMs='.$country2.'&requesterIso='.$country2.'&requesterVat='.$vatnum2.'&BtnSubmitVat=Verify';
    
    $response = file_get_contents($url);
    // Do sth with the response
    echo $response;