While placing an order using Paypal as payment, Magento 2 is adding the total tax twice to the AMT (amount) sent to PayPal.
Here is what is sent to paypal :
'AMT' => 134.10, // should be 114.10
'SHIPPINGAMT' => 5.00,
'ITEMAMT' => 89.10,
'TAXAMT' => 20.00,
Here is Paypal's error:
PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts (#10413: Transaction refused because of an invalid argument. See additional error messages for details).
The quote tax is set via a plugin :
<preference for="Magento\Tax\Model\Sales\Total\Quote\Tax" type="Vendor\Module\Model\Sales\Total\Quote\Tax"/>
Class :
class Tax extends \Magento\Tax\Model\Sales\Total\Quote\Tax{
public function __construct(
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Api\TaxCalculationInterface $taxCalculationService,
\Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory,
\Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory,
\Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory,
CustomerAddressFactory $customerAddressFactory,
CustomerAddressRegionFactory $customerAddressRegionFactory,
\Magento\Tax\Helper\Data $taxData ) {
$this->setCode('tax');
parent::__construct($taxConfig, $taxCalculationService, $quoteDetailsDataObjectFactory, $quoteDetailsItemDataObjectFactory, $taxClassKeyDataObjectFactory, $customerAddressFactory, $customerAddressRegionFactory, $taxData
);
}
public function collect(
\Magento\Quote\Model\Quote $quote,
\Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
\Magento\Quote\Model\Quote\Address\Total $total ) {
$total->setTotalAmount('tax', 20); //set fixed value for testing
$total->setBaseTotalAmount('tax', 20); //set fixed value for testing
return $this;
}
}
When the payment is "Check / Money order" the Order's totals and tax are correct.
I have been trying to solve this issue over the last week but without any success. Our Magento 2.3 instance doesn't have any other module and this is the only place the quote has been modified or even used.
Thanks