:moneybag: A simple and clean PHP library that validates EU VAT registration numbers against the central ec.europa.eu database (using the official europa API) :eu:
A simple and clean PHP class that validates EU VAT numbers against the central ec.europa.eu database (using the official europa API).
The Problem
Validate VAT numbers might be difficult and if you use a validation pattern to check if the format is valid, you are never sure if the VAT registration number is still valid.
The Solution
This PHP VAT validator library uses real-time data feeds from individual EU member states' VAT systems so you are sure of the validity of the number and avoid fraud with expired or wrong VAT numbers.
For example, this kind of validation can be very useful on online payment forms.
Previously the VAT validator was working just fine.
But now I get following error, see screenshot.
I saw that your code did change a little bit but more in syntax than new code.
So I'm not sure what's not working anymore?
I've notice the (1) Validator throws a Uncaught Exception PHP Error below, when Member State Service is not available, while (2) Service page at http://ec.europa.eu/taxation_customs/vies/vatRequest.html returns a user-friendly error: Member State service unavailable. Please re-submit your request later.
An uncaught Exception was encountered
Type: PH7\Eu\Vat\Exception
Message: Impossible to retrieve the VAT details: MS_UNAVAILABLE
Filename: /composer/vendor/ph-7/eu-vat-validator/src/Vat/Provider/Europa.php
Line Number: 59
100 = Valid request with Valid VAT Number
200 = Valid request with an Invalid VAT Number
201 = Error : INVALID_INPUT
202 = Error : INVALID_REQUESTER_INFO
300 = Error : SERVICE_UNAVAILABLE
301 = Error : MS_UNAVAILABLE
302 = Error : TIMEOUT
400 = Error : VAT_BLOCKED
401 = Error : IP_BLOCKED
500 = Error : GLOBAL_MAX_CONCURRENT_REQ
501 = Error : GLOBAL_MAX_CONCURRENT_REQ_TIME
600 = Error : MS_MAX_CONCURRENT_REQ
601 = Error : MS_MAX_CONCURRENT_REQ_TIME
For all the other cases, The web service will responds with a "SERVICE_UNAVAILABLE" error.
It would be brilliant, If you could add these to your Validator, so it would return (1) a user-friendly error with a customizable message, or (2) a response, based on which would be possible to manualy write the right message.
If of some help, I've noticed the Service returns (1) an Object, whenever the number is validated (valid or invalid) and (2) a String for all other cases. I didn't test many cases, so it may not hold true for all cases. Specifically I couldn't test these Numbers (100, 200, 201, etc.) mentioned in WSDL.
It looks like this getResource method will never throw SoapFault ( which is very good ) because it will be caught in line 57. In only throws the 'Exception' exception, so this annotation can be removed
exit('Impossible to connect to the europa SOAP : ' . $oExcept->faultstring);
The Constructor should throw the exception (kind of ConnectionNotEstablishedException or ProviderNotAvailableException) not just exit, to allow the outer code to deal with the problem (eg display the error message, retry after some delay, etc)
i'm trying to write prestashop in back-end and front. VAT number and validate like you wrote. and also siret france (KvK number NL) and eng Chamber of combers.