mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
101 stars 53 forks source link

When using Mollie Order API with tax on the surcharge, the tax percentage of the payment fee is not sent to Mollie. Result: conflict in grand totals #532

Closed erwinschaap closed 1 year ago

erwinschaap commented 2 years ago

Describe the bug When we use the Mollie Order API and set the tax percentage on for example: 21% on the payment fee and we create an order with payment fee, the tax percentage (vatRate) and tax amount (vatAmount) to Mollie is 0. Result is a conflict: The amount of the order does not match the total amount from the order lines. Expected order amount to be x but got y.

Used versions

To Reproduce Steps to reproduce the behavior:

  1. Enable for example Paypal with the surcharge amount of 3% and configure a tax percentage of 21% on the surcharge amount
  2. Enable the Order API for PayPal.
  3. Create an order and choose PayPal.
  4. In the Mollie logs you can see and error like: The amount of the order does not match the total amount from the order lines. Expected order amount to be x but got y.
  5. Mollie creates an request for the Payment API

Expected behavior The total amount does match

Actual behavior The amount of the order does not match the total amount from the order lines. Expected order amount to be x but got y. vatAmount and vatPercentage is 0 but needs to be percentage and amount of vat of the payment fee

Screenshots If applicable, add screenshots to help explain your problem. image

Additional context Add any other context about the problem here.

Frank-Magmodules commented 2 years ago

HI @erwinschaap , We can't reproduce this issue and I think that this is a conflict between an external plugin and/or custom work within the checkout. We have received your details through the Mollie support team so we will help you investigate and fix this issue asap.

cream-marcel commented 2 years ago

@erwinschaap We have the same issue and have discovered that the combination of the Geissweb euvat module and Mollie payment fee causes problems. Do you also use the euvat module from Geissweb?

erwinschaap commented 2 years ago

@cream-marcel We do not use euvat module from Geissweb. We have changed something with the payment fee problems, see https://github.com/mollie/magento2/issues/518.

erwinschaap commented 2 years ago

We are disabling Cross Border Trade when someone has a valid VAT number, but the issue descripted above is for someone without a valid VAT number. We just made a plugin for disabling Cross Border Trade when the tax percentage is 0

Frank-Magmodules commented 2 years ago

Hi @erwinschaap and @cream-marcel , please supply us with temporary environment details if you need help debugging this issue as we still can't reproduce this on our side.

erwinschaap commented 2 years ago

Hi @Frank-Magmodules we are using the following plugin

<?php

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace <Vendor>\Tax\Plugin;

use Magento\Checkout\Model\SessionFactory;
use Magento\Quote\Api\CartTotalRepositoryInterface;
use Magento\Store\Model\Store;
use Magento\Tax\Model\Config;
use Psr\Log\LoggerInterface;

class ConfigPlugin
{
    protected $_checkout;
    protected $_cartRepository;
    protected $_logger;

public function __construct(\Magento\Customer\Model\Session $session, SessionFactory $checkout, CartTotalRepositoryInterface $cartRepository, LoggerInterface $logger)
    {
        $this->_checkout = $checkout;
        $this->_cartRepository = $cartRepository;
        $this->_logger = $logger;
    }

    /**
     * Return the config value for self::CONFIG_XML_PATH_CROSS_BORDER_TRADE_ENABLED
     *
     * @param null|string|bool|int|Store $store
     * @return bool
     */
    public function aroundCrossBorderTradeEnabled(Config $subject, callable $proceed, $store = null)
    {
        try {
            /** @var \Magento\Checkout\Model\Session $session */
            $session = $this->_checkout->create();
            $id = $session->getQuoteId();

            if ($id == null) {
                return $proceed();
            }

            $totals = $this->_cartRepository->get($id);
            $tax = $totals->getTaxAmount();

            if ($tax == 0) {
                return false;
            }
        } catch (\Exception $e) {
            $this->_logger->debug("aroundCrossBorderTradeEnabled " . $e->getMessage());
        }

        return $proceed();
    }
}

for Magento\Tax\Model\Config

When we are getting the cart with the following code: $this->_cartRepository->get($id);

There are issues.

We discovered the following: Mollie\Payment\Plugin\Sales\Cart\AddPaymentFeeToCart::processCart function sets extension attributes. This is conflicting with this plugin. I think Euvat from Geissweb is also conflicting because they also implemented something for disabling Cross Border Trade when the tax percentage is 0.

When we comment $extensionAttributes->setBaseMolliePaymentFeeTax($cart->getData('base_mollie_payment_fee_tax')); this issue is solved. But we dont think this is the right thing to do.

Can you help?

Frank-Magmodules commented 2 years ago

HI @erwinschaap , do you still encounter this issue within the latest releases?

Frank-Magmodules commented 1 year ago

Hi @erwinschaap ,

We are happy to share that we've just released the new 2.19.0 version where we have fixed this issue.  
Thank you for opening this issue and for the detailed issue report.

We are closing this issue now but please feel free to reopen the issue if this still occurs.