: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.
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.
SIRET
SIRET
What is this? prestashop_1.7.8.8\prestashop\app\Resources\translations\default\AdminOrderscustomersFeature.xlf location
Shop registration information (e.g. SIRET or RCS).
Shop registration information (e.g. SIRET or RCS).
Line: 464
Same : **prestashop_1.7.8.8\prestashop\app\Resources\translations\default\AdminShopparametersHelp.xlf**
Identification number
Identification number
Line: 156
Comment: Please localize this string with the applicable registration number type in your country. For example : "SIRET" in France and "Código fiscal" in Spain.
file: prestashop_1.7.8.8\prestashop\classes\Customer.php
$format['siret'] = (new FormField())
->setName('siret')
->setType('text')
->setLabel($this->translator->trans(
// Please localize this string with the applicable registration number type in your country. For example : "SIRET" in France and "Código fiscal" in Spain.
'Identification number',
[],
'Shop.Forms.Labels'
));
return $sum % 10 === 0;
}
/**
* Validate APE Code.
*
* @param string $ape APE Code
*
* @return bool Return true if is valid
*/
public static function isApe($ape)
{
return (bool) preg_match('/^[0-9]{3,4}[a-zA-Z]{1}$/s', $ape);
}
Here is the not working place of shop location :prestashop_1.7.8.8\prestashop\controllers\admin\AdminStoresController.php
doesn't show frontside shop?? and no valadation and now VAT number .
**Maybe some countries but i like to see : KvK-nummer: 32147382 (siret) frans (8 NL) (10 BE) (outher country??)
BTW-identificatienummer Nederland: NL820471616B01 or BTW-identificatienummer België: BE0824148721 etc.
Bank-number : NL21 INGB 0004546905
prestashop_1.7.8.8\prestashop\install\data\db_structure.sql for data base but now VAT number??
company varchar(255), siret varchar(14), ape varchar(5),
prestashop_1.7.8.8\prestashop\src\Adapter\Customer\CommandHandler\AddCustomerHandler.php
they also got B2B but notting Sire frontend (yep mix drop box not nice by information store) No VAT number
prestashop_1.7.8.8\prestashop\app\Resources\translations\default\AdminOrderscustomersFeature.xlf (2 overeenkomsten)
Regel 1216: VAT number
Regel 1217: VAT number
prestashop_1.7.8.8\prestashop\app\Resources\translations\default\ShopFormsLabels.xlf (2 overeenkomsten)
Regel 51: VAT number
Regel 52: VAT number
prestashop_1.7.8.8\prestashop\app\Resources\translations\default\ShopPdf.xlf (2 overeenkomsten)
Regel 425: VAT Number
Regel 426: VAT Number
prestashop_1.7.8.8\prestashop\classes\Address.php (1 overeenkomsten)
Regel 90: /** @var string VAT number /
prestashop_1.7.8.8\prestashop\classes\form\CustomerAddressFormatter.php (1 overeenkomsten)
Regel 229: return $this->translator->trans('VAT number', [], 'Shop.Forms.Labels');
prestashop_1.7.8.8\prestashop\controllers\admin\AdminImportController.php (1 overeenkomsten)
Regel 442: 'vat_number' => ['label' => $this->trans('VAT number', [], 'Admin.Orderscustomers.Feature')],
prestashop_1.7.8.8\prestashop\docs\CHANGELOG.txt (2 overeenkomsten)
Regel 2046: - #22841: Bring back vat number to address on order view (by @kpodemski)
Regel 5851: - #8138: Fix tax calculation when vat number is used
prestashop_1.7.8.8\prestashop\docs\csv_import\addresses_import.csv (1 overeenkomsten)
Regel 1: Address ID;Alias;Active (0/1);Customer e-mail*;Customer ID;Manufacturer;Supplier;Company;Lastname*;Firstname*;Address 1*;Address 2;Zipcode*;City*;Country*;State;Other;Phone;Mobile Phone;VAT number;DNI
prestashop_1.7.8.8\prestashop\pdf\invoice.summary-tab.tpl (1 overeenkomsten)
Regel 32: {l s='VAT Number' d='Shop.Pdf' pdf='true'}
prestashop_1.7.8.8\prestashop\pdf\order-slip.summary-tab.tpl (1 overeenkomsten)
Regel 30: {l s='VAT Number' d='Shop.Pdf' pdf='true'}
prestashop_1.7.8.8\prestashop\src\Core\Domain\Address\Configuration\AddressConstraint.php (1 overeenkomsten)
Regel 80: * Maximum length for VAT number (value is constrained by database)
prestashop_1.7.8.8\prestashop\src\Core\Import\EntityField\Provider\AddressFieldsProvider.php (1 overeenkomsten)
Regel 76: new EntityField('vat_number', $this->trans('VAT number', 'Admin.Orderscustomers.Feature')),
prestashop_1.7.8.8\prestashop\src\PrestaShopBundle\Form\Admin\Sell\Address\CustomerAddressType.php (1 overeenkomsten)
Regel 257: 'label' => $this->trans('VAT number', 'Admin.Orderscustomers.Feature'),
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
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.
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)
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?
Is there a way to have a fallback when the service is down again.
Because now I use this one on my form: https://wordpress-1250868-4485821.cloudwaysapps.com/nl/gratis-tankkaart-voor-bedrijven-aanvragen/
And it still checked the VAT number but got an error because it couldn’t shown the data behind the VAT number, because the service was down.
Is there a way we just can let it go through but with empty fields and like an error that the service is down?