Skip to content

Commit

Permalink
add support for greece vat numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Jongsma authored and peterjaap committed Jun 24, 2021
1 parent 3132492 commit f890bc4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Plugin/Service/Validate/ValidationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Dutchento\Vatfallback\Plugin\Service\Validate;

use Dutchento\Vatfallback\Service\Validate\ValidationServiceInterface;

class ValidationService
{
public function beforeValidateVATNumber(ValidationServiceInterface $subject, string $vatNumber, string $countryIso2): array
{
return [$vatNumber, $this->getCountryCodeForVatNumber($countryIso2)];
}

/**
* 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;
}
}
5 changes: 5 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<plugin name="Dutchento_Vatfallback_Plugin_Magento_Customer_Model_Vat" sortOrder="10"
type="Dutchento\Vatfallback\Plugin\Magento\Customer\Model\Vat"/>
</type>
<type name="Dutchento\Vatfallback\Service\Validate\ValidationServiceInterface">
<plugin name="Dutchento_Vatfallback_Plugin_Service_Validate_ValidationServiceInterface" sortOrder="10"
type="Dutchento\Vatfallback\Plugin\Service\Validate\ValidationService"/>
</type>

<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
Expand Down

0 comments on commit f890bc4

Please sign in to comment.