DragonBe / vies

Component using the European Commission (EC) VAT Information Exchange System (VIES) to verify and validate VAT registration numbers in the EU, using PHP and Composer.
http://ec.europa.eu/taxation_customs/vies/faqvies.do#item16
MIT License
266 stars 59 forks source link

Grece is using custom country code EL instead of the international code GR #57

Closed johanwilfer closed 5 years ago

johanwilfer commented 5 years ago

The two-letter country code for Greece is GR, but in VAT id's in Europe Greece uses the EL-prefix instead.

https://en.wikipedia.org/wiki/ISO_3166-2:GR

In our code we used this list to compare to the international country codes and because GR != EL this obviously failed: https://github.com/DragonBe/vies/blob/master/src/Vies/Vies.php#L63

We will now take the list from listEuropeanCountries and make sure we convert this, but opening this here as a note. Maybe we should note the exception in a comment in this method, or note that EL is not the international code for Greece, they just use that as a VAT prefix. So in a sense the method name is misleading...

Thanks for a great library!

DragonBe commented 5 years ago

Thank you @johanwilfer for mentioning this. We have noticed the difference in the VAT prefix and the international country code, but as all things from the European Commission, exceptions on the rule must exist.

I agree that this exception should be documented in the code to make it clear for developers and integrators why this exception exists, maybe even add this as a separate remark in the README.md to emphasise the difference that it's not a bug, but a feature 😸 So, just updated the README.

Just for my understanding: this VIES library processes the Greece VAT IDN's correctly, right? It's just that the prefix EL is different from the international ISO code for Greece, being GR. Correct?

Just to verify, I've added the Greece railway company Train OSE SA in my example, returning valid information after validation:

Valid
Identifier: WAPIAAAAWcNVzowR
Date and time: 13/11/2018 01:00
Company name: ΤΡΑΙΝΟΣΕ ΜΕΤΑΦΟΡΕΣ ΜΕΤΑΦΟΡΙΚΕΣ ΥΠΗΡΕΣΙΕΣ ΕΠΙΒΑΤΩΝ ΚΑΙ ΦΟΡΤΙΟΥ ΑΝΩΝΥΜΗ ΣΙΔΗΡΟΔΡΟΜΙΚΗ ΕΤΑΙΡΕΙΑ ||ΤΡΑΙΝΟΣΕ  ΑΕ
Company address: ΚΑΡΟΛΟΥ 1-3       10437 - ΑΘΗΝΑ
johanwilfer commented 5 years ago

Yes, the validation works great. I just tested this also. The problem for us was that we use the list in the mentioned method to show/hide the VAT inputs, so we didn't even ask for it for Greek customers as there was no country "EL" selected...

Thanks for updating the README about this. :-)

DragonBe commented 5 years ago

@johanwilfer You're very welcome. Only with this kind of feedback I can make the information more meaningful for users, especially when you're not engaging with VAT related things on a regular basis. The more I receive this type of not expected behaviour, the better use cases I can come up with and more accurate we can make our pre-validation before we fire things of to the EC VIES service.

cottton commented 3 years ago

Old but still

GR <-> EL

As i read: GR is a country iso, and EL is a VAT prefix.

VIES_EU_COUNTRY_LIST contains country iso as keys. So 'EL' => ['name' => 'Greece', 'validator' => Validator\ValidatorEL::class], is actually a bad choice.

We may should change that in next major release to GR (may add additional row with GR inthe current lastest version), to keep the keys as country iso only, and add an additional value 'vat_prefix' => 'EL' (optionally).

Every method should look up the vat prefix in the array instead using the country iso.

Example: https://github.com/DragonBe/vies/blob/master/src/Vies/Vies.php#L491

    $requestParams = [
        'countryCode' => $countryCode,
        'vatNumber' => $testVatNumber,
    ];

Should then look like

$requestParams = [
    'countryCode' => $this->getVatPrefix($countryIso),
    'vatNumber' => $testVatNumber,
];

// ...
public function getVatPrefix($countryIso)
{
    if (!isset(self::VIES_EU_COUNTRY_LIST[$countryIso])) {
        // todo throw exception "invalid ..."
    }
    if (!isset(self::VIES_EU_COUNTRY_LIST[$countryIso]['var_prefix'])) {
        // VAT has a vat prefix that is NOT the same as the country iso.
        return self::VIES_EU_COUNTRY_LIST[$countryIso]['var_prefix'];
    }
    // VAT has a vat prefix that is the same as the country iso.
    return $countryIso;
}

TODO: does VIES expect the VAT prefix, or the real country iso? Should we name it "vat prefix" or "country code"? Perhaps country code since this is already the case in lots of code already.