Skip to content

Commit 5849689

Browse files
authored
ENGCOM-4108: Fixes incorrect country code being used for Greek VAT numbers, should… #20548
2 parents 611b516 + 3a15ad5 commit 5849689

File tree

1 file changed

+25
-4
lines changed
  • app/code/Magento/Customer/Model

1 file changed

+25
-4
lines changed

app/code/Magento/Customer/Model/Vat.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,21 @@ public function checkVatNumber($countryCode, $vatNumber, $requesterCountryCode =
179179
return $gatewayResponse;
180180
}
181181

182+
$countryCodeForVatNumber = $this->getCountryCodeForVatNumber($countryCode);
183+
$requesterCountryCodeForVatNumber = $this->getCountryCodeForVatNumber($requesterCountryCode);
184+
182185
try {
183186
$soapClient = $this->createVatNumberValidationSoapClient();
184187

185188
$requestParams = [];
186-
$requestParams['countryCode'] = $countryCode;
189+
$requestParams['countryCode'] = $countryCodeForVatNumber;
187190
$vatNumberSanitized = $this->isCountryInEU($countryCode)
188-
? str_replace([' ', '-', $countryCode], ['', '', ''], $vatNumber)
191+
? str_replace([' ', '-', $countryCodeForVatNumber], ['', '', ''], $vatNumber)
189192
: str_replace([' ', '-'], ['', ''], $vatNumber);
190193
$requestParams['vatNumber'] = $vatNumberSanitized;
191-
$requestParams['requesterCountryCode'] = $requesterCountryCode;
194+
$requestParams['requesterCountryCode'] = $requesterCountryCodeForVatNumber;
192195
$reqVatNumSanitized = $this->isCountryInEU($requesterCountryCode)
193-
? str_replace([' ', '-', $requesterCountryCode], ['', '', ''], $requesterVatNumber)
196+
? str_replace([' ', '-', $requesterCountryCodeForVatNumber], ['', '', ''], $requesterVatNumber)
194197
: str_replace([' ', '-'], ['', ''], $requesterVatNumber);
195198
$requestParams['requesterVatNumber'] = $reqVatNumSanitized;
196199
// Send request to service
@@ -301,4 +304,22 @@ public function isCountryInEU($countryCode, $storeId = null)
301304
);
302305
return in_array($countryCode, $euCountries);
303306
}
307+
308+
/**
309+
* Returns the country code to use in the VAT number which is not always the same as the normal country code
310+
*
311+
* @param string $countryCode
312+
* @return string
313+
*/
314+
private function getCountryCodeForVatNumber(string $countryCode): string
315+
{
316+
// Greece uses a different code for VAT numbers then its country code
317+
// See: http://ec.europa.eu/taxation_customs/vies/faq.html#item_11
318+
// And https://en.wikipedia.org/wiki/VAT_identification_number:
319+
// "The full identifier starts with an ISO 3166-1 alpha-2 (2 letters) country code
320+
// (except for Greece, which uses the ISO 639-1 language code EL for the Greek language,
321+
// instead of its ISO 3166-1 alpha-2 country code GR)"
322+
323+
return $countryCode === 'GR' ? 'EL' : $countryCode;
324+
}
304325
}

0 commit comments

Comments
 (0)