cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Discount is adding Twice in Paypal Express Magento 2

Custom Discount is adding Twice in Paypal Express Magento 2

I am using Magento 2.2.5 Enterprise Edition. I need to pass Custom Discount to Paypal express. That is My warranty discount. For this I am using payment_cart_collect_items_and_amounts Observer.

<event name="payment_cart_collect_items_and_amounts"> <observer name="warranty_paypal_express" instance="Vendor\Module\Observer\Addamounttopaypal" /> </event>

This is my Observer code

public function execute(Observer $observer)
{
    /** @var \Magento\Payment\Model\Cart $cart */
    $cart = $observer->getEvent()->getCart();
    $customAmount = $this->helper->getBaseWarrantyAmt();
    $handlingfee = $this->extafeehelper->getExtrafee();
    $discounntWarranty = $this->helper->getWarrayDiscountAmt();
    if($customAmount && $customAmount>0){
        $cart->addCustomItem(__('Warranty Amount'), 1, $customAmount, 'basewarranty');
    }
    if($discounntWarranty){
        $cart->setDiscount($discounntWarranty);
        $discountnamt = -1.00 * $discounntWarranty;
        $cart->addCustomItem(__('Warranty Discount'), 1,$discountnamt,'warrantydiscount');
    }
    if($handlingfee){
        $cart->addCustomItem(__('Environment Handling Fees'), 1, $handlingfee, 'fee');
    }
}

Custom Amount is adding fine. But the issue is with Discount. For the Discount i am adding negative value.

'$cart->addCustomItem(__('Warranty Discount'), 1,$discountnamt,'warrantydiscount');'

But the Amount is getting passed. and got error for total mismatch. Then I add the following code

'$cart->setDiscount($discounntWarranty);
$discountnamt = -1.00 * $discounntWarranty; $cart->addCustomItem(__('Warranty Discount'), 1,$discountnamt,'warrantydiscount');'

Now Warranty Discount and discount is adding. But i only need Warranty Discount. Custom Discount is not adding without $cart->setDiscount($discounntWarranty);

4 REPLIES 4

Re: Custom Discount is adding Twice in Paypal Express Magento 2

@ankurkinex - did you manage to resolve this problem?

Re: Custom Discount is adding Twice in Paypal Express Magento 2

@Saggitator  Yes

Re: Custom Discount is adding Twice in Paypal Express Magento 2

Can you please share how did you manage to solve?

Re: Custom Discount is adding Twice in Paypal Express Magento 2

Can you please share your code?