Skip to content

Commit

Permalink
Fixes incorrect country code being used for Greek VAT numbers, should…
Browse files Browse the repository at this point in the history
… be 'EL' instead of 'GR'.
  • Loading branch information
hostep authored and Amol Chaudhari committed Feb 12, 2019
1 parent 2fcf9b7 commit bfa4e1f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions app/code/Magento/Customer/Model/Vat.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,21 @@ public function checkVatNumber($countryCode, $vatNumber, $requesterCountryCode =
return $gatewayResponse;
}

$countryCodeForVatNumber = $this->getCountryCodeForVatNumber($countryCode);
$requesterCountryCodeForVatNumber = $this->getCountryCodeForVatNumber($requesterCountryCode);

try {
$soapClient = $this->createVatNumberValidationSoapClient();

$requestParams = [];
$requestParams['countryCode'] = $countryCode;
$requestParams['countryCode'] = $countryCodeForVatNumber;
$vatNumberSanitized = $this->isCountryInEU($countryCode)
? str_replace([' ', '-', $countryCode], ['', '', ''], $vatNumber)
? str_replace([' ', '-', $countryCodeForVatNumber], ['', '', ''], $vatNumber)
: str_replace([' ', '-'], ['', ''], $vatNumber);
$requestParams['vatNumber'] = $vatNumberSanitized;
$requestParams['requesterCountryCode'] = $requesterCountryCode;
$requestParams['requesterCountryCode'] = $requesterCountryCodeForVatNumber;
$reqVatNumSanitized = $this->isCountryInEU($requesterCountryCode)
? str_replace([' ', '-', $requesterCountryCode], ['', '', ''], $requesterVatNumber)
? str_replace([' ', '-', $requesterCountryCodeForVatNumber], ['', '', ''], $requesterVatNumber)
: str_replace([' ', '-'], ['', ''], $requesterVatNumber);
$requestParams['requesterVatNumber'] = $reqVatNumSanitized;
// Send request to service
Expand Down Expand Up @@ -301,4 +304,22 @@ public function isCountryInEU($countryCode, $storeId = null)
);
return in_array($countryCode, $euCountries);
}

/**
* Returns the country code to use in the VAT number which is not always the same as the normal country code
*
* @param string $countryCode
* @return string
*/
private function getCountryCodeForVatNumber(string $countryCode): string
{
// Greece uses a different code for VAT numbers then its country code
// See: http://ec.europa.eu/taxation_customs/vies/faq.html#item_11
// And https://en.wikipedia.org/wiki/VAT_identification_number:
// "The full identifier starts with an ISO 3166-1 alpha-2 (2 letters) country code
// (except for Greece, which uses the ISO 639-1 language code EL for the Greek language,
// instead of its ISO 3166-1 alpha-2 country code GR)"

return $countryCode === 'GR' ? 'EL' : $countryCode;
}
}

0 comments on commit bfa4e1f

Please sign in to comment.