Custom-Fee-Magento2 icon indicating copy to clipboard operation
Custom-Fee-Magento2 copied to clipboard

Custom Fee adding Twice.

Open ashokshrestha2012 opened this issue 7 years ago • 5 comments

In the backend, I have set the Custom Fee Amount for 10. Then I added product of value 100 and with shipping charge 5. In the checkout page, i have checked custom fee so that extra fee will be added in the order. But In payment page custom fee is adding twice. The total value should be 115, but displaying 125.When i remove the custom fee the calculation is fine.

ashokshrestha2012 avatar Feb 09 '18 11:02 ashokshrestha2012

Yes, I have the same issue but I found solution,

Update grandTotal in bellow files

app/code/Sivajik34/CustomFee/Model/Total/Fee.php

app/code/Sivajik34/CustomFee/Model/Quote/Total/Fee.php

 Change 
 $total->setGrandTotal($total->getGrandTotal() + $fee);
 $total->setBaseGrandTotal($total->getBaseGrandTotal() + $fee);

TO
 $total->setGrandTotal($total->getGrandTotal());
 $total->setBaseGrandTotal($total->getBaseGrandTotal());

because it's already update in this file,

app/code/Sivajik34/CustomFee/Plugin/Checkout/Model/ShippingInformationManagement.php

Clean cache and check, hope it helps you.

dhrumin44 avatar Feb 21 '18 07:02 dhrumin44

I have checked your code and still double additional fees issue occur. Please let us know anything remaining from our end.

Thanks

ketantambekar avatar Jan 03 '19 09:01 ketantambekar

Delete the cart items and add items again and check.

bineshdobhal avatar Jun 20 '19 04:06 bineshdobhal

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).

nitaipanda avatar Aug 08 '19 11:08 nitaipanda

Hello @nitaipanda It's magento paypal default issue, paypal doesn't support extra cost in cart, this module added additional fee as your requirement.

Now if in an order you added some custom fee, and want to pay the payment by magento’s default paypal payment method, then it throws the error that, amount is not same as order amount.

solve this issue you have to manage that custom feefor the paypal process below step.

Add an observer in your module:

file path: app/code/Sivajik34/CustomFee/etc/events.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="payment_cart_collect_items_and_amounts">
        <observer name="Sivajik34_CustomFee_payment_collect_total" instance="Sivajik34\CustomFee\Observer\AddCustomAmountItem" />
    </event>
</config>

Now define this observer, at path:

app/code/Sivajik34/CustomFee/Observer/AddCustomAmountItem.php

<?php

namespace Sivajik34\CustomFee\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
 * Add Weee item to Payment Cart amount.
 */
class AddCustomAmountItem implements ObserverInterface
{
    /**
     * 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();
        $customAmount = 246;
        $cart->addCustomItem(__('Custom Fee'), 1, -1.00 * $customAmount, 'customfee');
    }
}

Here, addCustomItem() function is added your custom amount field in cart, and then paypal manages the amount as well.

in this, first parameter is, the field name, i.e. amount field name.

second parameter is, quantity for the field.

third parameter is, amount, which you want to add, in example i added (-1.00 *), because i want to pass negative value.

forth parameter is, identifier, i.e. id of your custom amount field.

After this code your order will get placed using paypal payment method without any error.

Hope this solution will help you.

dhrumin44 avatar Aug 10 '19 05:08 dhrumin44