@@ -179,18 +179,21 @@ public function checkVatNumber($countryCode, $vatNumber, $requesterCountryCode =
179
179
return $ gatewayResponse ;
180
180
}
181
181
182
+ $ countryCodeForVatNumber = $ this ->getCountryCodeForVatNumber ($ countryCode );
183
+ $ requesterCountryCodeForVatNumber = $ this ->getCountryCodeForVatNumber ($ requesterCountryCode );
184
+
182
185
try {
183
186
$ soapClient = $ this ->createVatNumberValidationSoapClient ();
184
187
185
188
$ requestParams = [];
186
- $ requestParams ['countryCode ' ] = $ countryCode ;
189
+ $ requestParams ['countryCode ' ] = $ countryCodeForVatNumber ;
187
190
$ vatNumberSanitized = $ this ->isCountryInEU ($ countryCode )
188
- ? str_replace ([' ' , '- ' , $ countryCode ], ['' , '' , '' ], $ vatNumber )
191
+ ? str_replace ([' ' , '- ' , $ countryCodeForVatNumber ], ['' , '' , '' ], $ vatNumber )
189
192
: str_replace ([' ' , '- ' ], ['' , '' ], $ vatNumber );
190
193
$ requestParams ['vatNumber ' ] = $ vatNumberSanitized ;
191
- $ requestParams ['requesterCountryCode ' ] = $ requesterCountryCode ;
194
+ $ requestParams ['requesterCountryCode ' ] = $ requesterCountryCodeForVatNumber ;
192
195
$ reqVatNumSanitized = $ this ->isCountryInEU ($ requesterCountryCode )
193
- ? str_replace ([' ' , '- ' , $ requesterCountryCode ], ['' , '' , '' ], $ requesterVatNumber )
196
+ ? str_replace ([' ' , '- ' , $ requesterCountryCodeForVatNumber ], ['' , '' , '' ], $ requesterVatNumber )
194
197
: str_replace ([' ' , '- ' ], ['' , '' ], $ requesterVatNumber );
195
198
$ requestParams ['requesterVatNumber ' ] = $ reqVatNumSanitized ;
196
199
// Send request to service
@@ -301,4 +304,22 @@ public function isCountryInEU($countryCode, $storeId = null)
301
304
);
302
305
return in_array ($ countryCode , $ euCountries );
303
306
}
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
+ }
304
325
}
0 commit comments