PHP / Magento Dev Blog

  • Home

Magento 2 wrong VAT for EU B2B customers – tax configuration

by Henryk Tews / Friday, 10 July 2026 / Published in Magento / Adobe Commerce

A B2B shop was charging 23% VAT to customers from Germany and France who provided EU VAT numbers. Under the reverse charge principle, VAT should be 0% for EU businesses with a VAT number. The problem generated customer complaints and tax risk. Fix time: 8 hours.

Symptoms

  • EU customers with VAT number pay full 23% VAT
  • Invoices issued with incorrect VAT rate
  • The “VAT number” field in checkout is visible but does not affect price

Configuration

# For B2B reverse charge you need a Customer Tax Class
# Stores > Tax > Customer Tax Classes: add "EU B2B Customer"
# Stores > Tax > Tax Rules:
#   - Customer Tax Class: EU B2B Customer
#   - Product Tax Class: Taxable Goods
#   - Tax Rate: 0% EU
#   - Priority: 0 (higher than standard VAT)
<?php
// Observer that changes tax class after EU VAT number validation
class VatValidationObserver implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer): void
    {
        $customer  = $observer->getCustomer();
        $vatNumber = $customer->getTaxvat();

        if ($this->isValidEuVat($vatNumber)) {
            $customer->setGroupId($this->getB2bGroupId());
            $customer->setTaxClassId($this->getEuB2bTaxClassId());
        }
    }

    private function isValidEuVat(string $vatNumber): bool
    {
        $client      = new \SoapClient('https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl');
        $countryCode = substr($vatNumber, 0, 2);
        $number      = substr($vatNumber, 2);

        try {
            $result = $client->checkVat(['countryCode' => $countryCode, 'vatNumber' => $number]);
            return $result->valid;
        } catch (\Exception $e) {
            return false;
        }
    }
}

Takeaways

Reverse charge for EU B2B requires VAT number validation via VIES API, a separate tax class for B2B customers and an appropriate tax rule with 0% VAT. Always consult tax configuration with an accountant.

About Henryk Tews

What you can read next

Xdebug – configuration, PHPStorm, debugging Magento plugins
Strategy pattern in PHP – and how Magento 2 uses it in pricing

© 2026 Created by

TOP
Zarządzaj zgodą
Aby zapewnić jak najlepsze wrażenia, korzystamy z technologii, takich jak pliki cookie, do przechowywania i/lub uzyskiwania dostępu do informacji o urządzeniu. Zgoda na te technologie pozwoli nam przetwarzać dane, takie jak zachowanie podczas przeglądania lub unikalne identyfikatory na tej stronie. Brak wyrażenia zgody lub wycofanie zgody może niekorzystnie wpłynąć na niektóre cechy i funkcje.
Funkcjonalne Always active
Przechowywanie lub dostęp do danych technicznych jest ściśle konieczny do uzasadnionego celu umożliwienia korzystania z konkretnej usługi wyraźnie żądanej przez subskrybenta lub użytkownika, lub wyłącznie w celu przeprowadzenia transmisji komunikatu przez sieć łączności elektronicznej.
Preferencje
Przechowywanie lub dostęp techniczny jest niezbędny do uzasadnionego celu przechowywania preferencji, o które nie prosi subskrybent lub użytkownik.
Statystyka
Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do celów statystycznych. Przechowywanie techniczne lub dostęp, który jest używany wyłącznie do anonimowych celów statystycznych. Bez wezwania do sądu, dobrowolnego podporządkowania się dostawcy usług internetowych lub dodatkowych zapisów od strony trzeciej, informacje przechowywane lub pobierane wyłącznie w tym celu zwykle nie mogą być wykorzystywane do identyfikacji użytkownika.
Marketing
Przechowywanie lub dostęp techniczny jest wymagany do tworzenia profili użytkowników w celu wysyłania reklam lub śledzenia użytkownika na stronie internetowej lub na kilku stronach internetowych w podobnych celach marketingowych.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Zobacz preferencje
  • {title}
  • {title}
  • {title}