@enamulislamjisan
Updating only the qty on a refund item is not enough. The collectTotals() methods do not recalculate item amounts from the quantity—they only sum the values already stored on the refund items.
Because of this, changing refund_item.qty alone leaves fields such as total, base_total, tax_amount, and discount_amount unchanged, so the refund and order totals remain the same.
Recommended approach
If you're modifying the refund quantity for a partial refund, update the quantity before creating the refund. The RefundRepository::create() method calculates all refund item amounts, refund totals, order totals, and inventory adjustments based on the quantities provided in the input data.
For example:
$data['refund']['items'][$orderItemId] = $newQty;
$refund = $refundRepository->create($data);
This ensures all related calculations are performed correctly.
If the refund has already been created
If you need to modify an existing refund, changing the qty alone is insufficient. You must also recalculate the refund item's monetary fields (such as total, base_total, tax_amount, and discount_amount) based on the new quantity, then call the appropriate collectTotals() methods to update the refund and order aggregates.
Keep in mind that if the refund quantity changes after creation, you may also need to adjust inventory manually, as inventory updates are handled during refund creation and are not recalculated by collectTotals().