Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
johanwilfer opened this issue Nov 13, 2018 · 4 comments

Comments

@johanwilfer
Copy link

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!

@johanwilfer johanwilfer changed the title Grece is using Grece is using custom country code EL instead of the international code GR Nov 13, 2018
@DragonBe
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

@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
Copy link
Contributor

cottton commented Jun 30, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants