Giter VIP home page Giter VIP logo

ph-7 / eu-vat-validator Goto Github PK

View Code? Open in Web Editor NEW
92.0 9.0 16.0 90 KB

: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:

Home Page: https://github.com/pH-7/eu-vat-validator

License: GNU General Public License v3.0

PHP 100.00%
eu-vat-validator vat-number eu-vat tax vies vat-validator vat-validation eu eu-api europa-api

eu-vat-validator's Introduction

EU VAT Number Validator

A simple and clean PHP class that validates EU VAT numbers against the central ec.europa.eu database (using the official europa API).

EU VATIN validator; EU Flag

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.

Composer Installation

composer require ph-7/eu-vat-validator
  • Then, include Composer's autoload (if not already done in your project)
require_once 'vendor/autoload.php';

Manual Installation (the old-fashioned way)

If you don't use Composer, you can install it without Composer by including the following

require 'src/autoloader.php';

How to Use

Example

use PH7\Eu\Vat\Validator;
use PH7\Eu\Vat\Provider\Europa;

$oVatValidator = new Validator(new Europa, '0472429986', 'BE');

if ($oVatValidator->check()) {
    $sRequestDate = $oVatValidator->getRequestDate();
    // Optional, format the date
    $sFormattedRequestDate = (new DateTime)->format('d-m-Y');

    echo 'Business Name: ' . $oVatValidator->getName() . '<br />';
    echo 'Address: ' . $oVatValidator->getAddress() . '<br />';
    echo 'Request Date: ' . $sFormattedRequestDate . '<br />';
    echo 'Member State: ' . $oVatValidator->getCountryCode() . '<br />';
    echo 'VAT Number: ' . $oVatValidator->getVatNumber() . '<br />';
} else {
    echo 'Invalid VAT number';
}

Optimization (Suggestion)

Depending of the use of this library, it could be handy to cache the result specifically for each specified VAT number.

Requirements

About Me

I'm Pierre-Henry Soria, a passionate Software Engineer and the creator of pH7CMS.

Where to Contact Me?

You can by email at pierrehenrysoria+github [[AT]] gmail [[D0T]] com

Wordpress Plugin

VIES Validator WP plugin uses also this EU VAT Validation library for WooCommerce checkout, when you need to make sure that the VAT number is valid (that plugin was deleloped by WpZen, not me 😃).

References

VAT Information Exchange System (VIES)

License

Under General Public License 3 or later.

eu-vat-validator's People

Contributors

ph-7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eu-vat-validator's Issues

Remove starting / ending comma for getAddress()

When requesting the address, it's starting / ending with a comma.
Probably the $this->oResponse->address starts with a newline

Maybe add a trim or something in the removeNewLines

return trim(str_replace(["\n", "\r\n"], ', ', $sString), ', ');

Impossible to retrieve the VAT details: MS_UNAVAILABLE

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?
Scherm­afbeelding 2024-03-15 om 14 49 10

erroneous response handling -- uncaught exception

Hello,

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

There are some more cases listed in the WSDL at http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl -- possibly not handled by the Validator. At the time of writing, these are:

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.

Best!

Can you help me pH-7

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.

?? prestashop_1.7.8.8\prestashop\app\Resources\translations\default\ShopFormsLabels.xlf

/** @var string WebSite * */
public $website;

/** @var string Company */
public $company;

/** @var string SIRET */
public $siret;

/** @var string APE */
public $ape;

~~
'website' => ['type' => self::TYPE_STRING, 'validate' => 'isUrl'],
'company' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
'siret' => ['type' => self::TYPE_STRING, 'validate' => 'isGenericName'],
'ape' => ['type' => self::TYPE_STRING, 'validate' => 'isApe'],

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'
));

prestashop_1.7.8.8\prestashop\classes\form\CustomerFormatter.php

i tink here is the best place for your script in site? location: prestashop_1.7.8.8\prestashop\classes\Validate.php

/**
* Validate SIRET Code.
*
* @param string $siret SIRET Code
*
* @return bool Return true if is valid
*/
public static function isSiret($siret)
{
if (Tools::strlen($siret) != 14) {
return false;
}
$sum = 0;
for ($i = 0; $i != 14; ++$i) {
$tmp = ((($i + 1) % 2) + 1) * (int) ($siret[$i]);
if ($tmp >= 10) {
$tmp -= 9;
}
$sum += $tmp;
}

    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 .

'PS_SHOP_DETAILS' => [
'title' => $this->trans('Registration number', [], 'Admin.Shopparameters.Feature'),
'hint' => $this->trans('Shop registration information (e.g. SIRET or RCS).', [], 'Admin.Shopparameters.Help'),
'validation' => 'isGenericName',
'type' => 'textarea',
'cols' => 30,
'rows' => 5,
~~later fax ??
'PS_SHOP_FAX' => [
'title' => $this->trans('Fax', [], 'Admin.Global'),
'validation' => 'isGenericName',
'type' => 'text',

**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

or

Geregistreerd KvK nummer: 08137001
IBAN: NL21 INGB 0004546905
BTW: NL001947572B19**

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

// fill b2b customer fields
$customer->company = $command->getCompanyName();
$customer->siret = $command->getSiretCode();
$customer->ape = $apeCode;

prestashop_1.7.8.8\prestashop\vendor\prestashop\translationtools-bundle\Translation\Fixtures\fields_catalogue.php

first page siret and vat_number But what is page? I'm maybe not long reading these scrips and structure's like 4 mounts?

$_FIELDS['Customer_342f5c77ed008542e78094607ce1f7f3'] = 'firstname';
$_FIELDS['Customer_8ad75c5a8821cc294f189181722acb56'] = 'lastname';
$_FIELDS['Customer_cf673f7ee88828c9fb8f6acf2cb08403'] = 'birthday';
$_FIELDS['Customer_0c83f57c786a0b4a39efab23731c7ebc'] = 'email';
$_FIELDS['Customer_d1befa03c79ca0b84ecc488dea96bc68'] = 'website';
$_FIELDS['Customer_93c731f1c3a84ef05cd54d044c379eaa'] = 'company';
$_FIELDS['Customer_01b0fd027f8764f9c069506b8de8bf2e'] = 'siret';
$_FIELDS['Warehouse_b8af13ea9c8fe890c9979a1fa8dbde22'] = 'reference';
$_FIELDS['Warehouse_b068931cc450442b63f5b3d276ea4297'] = 'name';
$_FIELDS['Warehouse_23c3b4d168a45ef94635494ce42eb658'] = 'management_type';
$_FIELDS['Country_213ecf1210f43736b6d4997fcfa27954'] = 'iso_code';
$_FIELDS['Country_b068931cc450442b63f5b3d276ea4297'] = 'name';
$_FIELDS['Country_37f577d6d447ff0743d74245446223b3'] = 'zip_code_format';
$_FIELDS['State_213ecf1210f43736b6d4997fcfa27954'] = 'iso_code';
$_FIELDS['State_b068931cc450442b63f5b3d276ea4297'] = 'name';
$_FIELDS['Address_93c731f1c3a84ef05cd54d044c379eaa'] = 'company';
$_FIELDS['Address_8ad75c5a8821cc294f189181722acb56'] = 'lastname';
$_FIELDS['Address_342f5c77ed008542e78094607ce1f7f3'] = 'firstname';
$_FIELDS['Address_81e70cb16ec45f5ab19bb6638e8e6c2d'] = 'address1';
$_FIELDS['Address_f669f8e9f6599d0dfcd613bc6e2f347e'] = 'address2';
$_FIELDS['Address_e90ebd9556fa4031171f043013794b61'] = 'postcode';
$_FIELDS['Address_4ed5d2eaed1a1fadcc41ad1d58ed603e'] = 'city';
$_FIELDS['Address_795f3202b17cb6bc3d4b771d8c6c9eaf'] = 'other';
$_FIELDS['Address_f7a42fe7211f98ac7a60a285ac3a9e87'] = 'phone';
$_FIELDS['Address_2df2ca5cf808744c2977e4073f6b59c8'] = 'phone_mobile';
$_FIELDS['Address_eec0a9661213354fa7a52519eea3f827'] = 'vat_number';
$_FIELDS['Address_d56f5e97524d5d1ad77ec197ae11dad0'] = 'dni';

$catalogue = new \Symfony\Component\Translation\MessageCatalogue();

function addEntry($catalogue, $original, $translation, $domain = 'messages')
{
$catalogue->set($original, $translation, $domain);
$catalogue->setMetadata($original, ['line' => 0, 'file' => FILE], $domain);
}

foreach ($FIELDS as $key => $value) {
addEntry($catalogue, $value, $value, reset(explode('
', $key)));
}

rest VAT numbers look up:

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'),

Where can i place your script ?

Kind reagards Imke.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.