Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento EU VAT tax validation fails, customer group change not applied

Our company is VAT registered and removes VAT from EU B2B sales where a valid VAT number has been provided. Magento version is 1.9 which includes support for this tax issue, customer group is (was) automatically assigned once the VAT number is validated.

There was originally a problem where Magento showed two instances of a VAT number entry form, one of these worked and the other didn't so results were unreliable. I subsequently hid the VAT form which was not working and all appeared to be working properly. There was still an issue if the customer didn't read the instruction to remove the country code from the VAT number, this prevents the VAT number from being validated but overall it was working. Recently, VAT has not been removed for EU VAT reg customers, even manually adjusting the customers account group to the VAT exempt group has not removed VAT.

It seems that checking of the VAT number against the appropriate VAT database is not taking place. We've tried using what we know to be valid VAT numbers and an error "Your Tax ID cannot be validated. If you believe this is an error, please contact us at [email address]"

Presumably everyone who uses the EU VAT rules feature is having the same issue, perhaps something as simple as a hyperlink being changed is the cause, searching has revealed no other recent similar problems though.

Can someone advise where in Magento the code for the VAT check and authorisation is held please?

Thanks in advance for any help. RobH

like image 383
Sparko Avatar asked Mar 16 '23 20:03

Sparko


1 Answers

There are 2 fields for the VAT ID inside Magento. The first one is related to the customer entity, which won't be checked against the VAT validation service "VIES". It has only some information character, but is has no impact of the customer group assignment.

The second VAT ID field is related to the customer address entity, which will be checked against the VIES service. If the VAT ID is valid, your customer will be assigned to your defined customer group (e.g. "Valid VAT ID", etc.). Important: Magento doesn't accept VAT IDs with country code prefixes. E.g. "ATU69014309" is not a valid TAX ID for Magento. Instead the VAT ID without country prefix "U69014309" is valid. You can fix this issue easily if you extend the following method of the class Mage_Customer_Helper_Data:

/**
 * Send request to VAT validation service and return validation result
 *
 * @param string $countryCode
 * @param string $vatNumber
 * @param string $requesterCountryCode
 * @param string $requesterVatNumber
 *
 * @return Varien_Object
 */
public function checkVatNumber($countryCode, $vatNumber, $requesterCountryCode = '', $requesterVatNumber = '')
{

    // Remove the country code prefix from the vat number
    $vatNumber = preg_replace("/^[a-z]{2}/i", "", $vatNumber); 

    ...

Also important: The VAT ID which the user enters during the checkout inside the address will be also ignored (known Magento Issue).

Kind regards, Robert

like image 171
Robert Erlinger Avatar answered Apr 25 '23 16:04

Robert Erlinger