cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 Payment Fee not added in paypal express checkout

Magento2 Payment Fee not added in paypal express checkout

Hello

im devloping one extension to add extra fee,
but  when i select paypal express checkout payment method,
it added charge to grandtotal

 

but when it redirect to paypal
the payment fee is not added

ill try to solve it out using

below link

http://www.ibnab.com/en/blog/magento-2/magento-2-paypal-fee-charge-and-life-cycle

 

but it gives 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).

 

Please Help.

4 REPLIES 4

Re: Magento2 Payment Fee not added in paypal express checkout

We had the similar issue with iban extension and we emailed support several times with no reply so ended up using the following module.

 

https://www.scommerce-mage.com/magento2-surcharge-or-additional-fee.html

 

Hope it helps!

Re: Magento2 Payment Fee not added in paypal express checkout

Im not want to use any extension,

im devloping new extension of payment fee,

and issue is in that module when i payment through paypal express checkout

Re: Magento2 Payment Fee not added in paypal express checkout

I am also getting below 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).
 Any solution?

Re: Magento2 Payment Fee not added in paypal express checkout

You get this error because of "Your item total and cart total does not match" 

 

In Magento 2 Paypal is implemented with the module name Paypal, If the customer selects Paypal method for the payment then Magento\Paypal\Model\Cart will call instead of Magento\Payment\Model\Cart  it used for collect items and amount and validate the info collected before sending to PayPal.

 

I also faced this issue and resolved using preference.

 

First, you need to debug this what is the reason for total is not match, to debug you have to check var/log/payment.log find 'AMT' => see the value of this and compare with your current cart total. if your 'AMT' =>  is higher then cart total then you have to minus value and if 'AMT' =>  is lower then cart total then you have to plus in total.

 

Use below preference to plus or minus value in total.

Add below code to event.xml

<event name="payment_cart_collect_items_and_amounts">
        <observer name="paymentfee" instance="Namespace\Modulename\Observer\AddCustomAmountItem" />
    </event>

Add below code to observer file.

<?php
 
namespace Namespace\Modulename\Observer;
 
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Checkout\Model\Session;
 
/**
 * Add Weee item to Payment Cart amount.
 */
class AddCustomAmountItem implements ObserverInterface
{
    public $checkout;

    public function __construct(Session $checkout)
    {
        $this->checkout = $checkout;
    }
    /**
     * Add custom amount as custom item to payment cart totals.
     *
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
        /** @var \Magento\Payment\Model\Cart $cart */
        $cart = $observer->getEvent()->getCart();
        $quote = $this->checkout->getQuote();
        
        $address = $quote->getIsVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
        if ($customAmount = $quote->getFee())
        {
            $cart->addCustomItem(__('Fee title'), 1, -1.00 * -$quote->getFee(), 'fee');
        }
    }
}

I hope it helps!

If Issue Solved, Click Kudos/Accept As solutions.