diff --git a/vendor/payuindia/payu/Helper/Payu.php b/vendor/payuindia/payu/Helper/Payu.php
index 1a3dcd3..9aff440 100644
--- a/vendor/payuindia/payu/Helper/Payu.php
+++ b/vendor/payuindia/payu/Helper/Payu.php
@@ -231,49 +231,70 @@ class Payu extends AbstractHelper
 
     }
 
-    public function setDiscount($order,$customDiscount,$discountDescription)
+    public function setDiscount($order, $customDiscount, $discountDescription)
     {
-        $total=$order->getBaseSubtotal();
-        $order->setDiscountAmount($customDiscount);
-        $order->setBaseDiscountAmount($customDiscount);
-        $order->setBaseGrandTotal($order->getBaseGrandTotal()-$customDiscount);
-        $order->setGrandTotal($order->getGrandTotal()-$customDiscount);
-        $order->setDiscountDescription($discountDescription);
+        $total = $order->getGrandTotal();
+        $existingDiscount = $order->getDiscountAmount();
+        $newDiscount = $existingDiscount - $customDiscount; // Adding the custom discount
+        $order->setDiscountAmount($newDiscount);
+        $order->setBaseDiscountAmount($newDiscount);
+        $order->setGrandTotal($order->getGrandTotal() - $customDiscount);
+        $order->setBaseGrandTotal($order->getBaseGrandTotal() - $customDiscount);
+        $order->setDiscountDescription($order->getDiscountDescription() . '|||payu :-' . $discountDescription);
         $shippingAddress = $order->getShippingAddress();
         if ($shippingAddress) {
             $shippingAddress->setDiscountAmount($customDiscount);
             $shippingAddress->setDiscountDescription($discountDescription);
             $shippingAddress->setBaseDiscountAmount($customDiscount);
         }
-        $orderBillingAddress = $order->getBillingAddress();
-        $orderBillingAddress->setDiscountAmount($customDiscount);
-        $orderBillingAddress->setDiscountDescription($discountDescription);
-        $orderBillingAddress->setBaseDiscountAmount($customDiscount);
+        // Apply discount to billing address if exists
+        $billingAddress = $order->getBillingAddress();
+        if ($billingAddress) {
+            $billingAddress->setDiscountAmount($customDiscount);
+            $billingAddress->setDiscountDescription($discountDescription);
+            $billingAddress->setBaseDiscountAmount($customDiscount);
+        }
 
         $order->setSubtotal((float) $order->getSubTotal());
         $order->setBaseSubtotal((float) $order->getBaseSubtotal());
-        $order->setGrandTotal((float)  $order->getGrandTotal());
+        $order->setGrandTotal((float) $order->getGrandTotal());
         $order->setBaseGrandTotal((float) $order->getBaseGrandTotal());
-        $order ->save();
-      
+        $order->addStatusHistoryComment('discount-' . $existingDiscount . 'payu discount-' . $customDiscount);
+        $order->save();
 
         $order->setBaseTotalInvoiced($order->getGrandTotal());
         $order->setTotalInvoiced($order->getGrandTotal());
-        $payment=$order->getpayment();
+
+        $payment = $order->getPayment();
         $payment->setBaseAmountPaid($order->getGrandTotal());
         $payment->setAmountPaid($order->getGrandTotal());
         $payment->setBaseAmountOrdered($order->getGrandTotal());
         $payment->setAmountOrdered($order->getGrandTotal());
         $payment->save();
-        foreach($order->getAllItems() as $item){
-            $rat=$item->getPriceInclTax()/$total;
-            $ratdisc=abs($customDiscount)*$rat;
-            $discountAmt=($item->getDiscountAmount()+$ratdisc) * $item->getQtyOrdered();
-            $base=($item->getBaseDiscountAmount()+$ratdisc) * $item->getQtyOrdered();
-            $item->setBaseDiscountAmount($base);
-            $item->setDiscountAmount($discountAmt);
-            $item->save();
+        $totalNew = 0;
+        $orderParent = [];
+        foreach ($order->getAllItems() as $item) {
+                $orderParent[$item->getItemId()] = $item;
+                if($item->getProductType() !="bundle" && $item->getProductType() !="soft") {
+                     if($item->getParentItemId() == null || ($orderParent[$item->getParentItemId()]->getProductType() =="bundle" || $orderParent[$item->getParentItemId()]->getProductType() =="soft"))
+                         $totalNew=$totalNew+($item->getPriceInclTax()*$item->getQtyOrdered())-$item->getDiscountAmount();
+               }
         }
+        // Distribute the discount proportionally among items
+        foreach ($order->getAllItems() as $item) {
+             if($item->getProductType() !="bundle" && $item->getProductType() !="soft") {
+                     if($item->getParentItemId() == null || ($orderParent[$item->getParentItemId()]->getProductType() =="bundle" || $orderParent[$item->getParentItemId()]->getProductType() =="soft"))
+                     { 
+                        $itemPriceInclTax = ($item->getPriceInclTax() * $item->getQtyOrdered()) - $item->getDiscountAmount();
+                        $discountRatio = $itemPriceInclTax / $totalNew;
+                        $itemDiscountAmount = $discountRatio * abs($customDiscount);
+                        $item->setBaseDiscountAmount($item->getBaseDiscountAmount() + $itemDiscountAmount);
+                        $item->setDiscountAmount($item->getDiscountAmount() + $itemDiscountAmount);
+                        $item->save();
+                     }
+             }
+        }
+
         $order->save();
     }
 
