cancel
Showing results for 
Search instead for 
Did you mean: 

Giftcard payment correct in cart but after checkout the whole gift card amount is charged

Giftcard payment correct in cart but after checkout the whole gift card amount is charged

When I use a gift card to pay for an order-- if the grand total amount is more than gift card, that is, if I have to use the whole gift card amount, everything works fine. However when grand total < gift card balance, instead of charging  the gift card the same amount as the grand total, it gets charged the entire value. Basically, every time I use it, the whole gift card is charged but in the cart summary it shows the right value for Gift Card Payment.

The code for handling gift card and updating quote is shown below. In quote, giftcard_amount_used is saved as the entire value of the gift card-which might be causing this issue, but I can't think of how to make it store the right value used.

Thanks in advance!

if($giftCardsAmount > 0) {
      
                    $address->setData("gift_cards_amount_used", $address->getData("grand_total")-$giftCardsAmount);
                    $address->setData("base_gift_cards_amount_used",$address->getData("base_grand_total")- $baseGiftCardsAmount);
                    $address->setData("gift_cards", $giftCards);
                    $address->setData("used_gift_cards", $usedGiftCards);

             
                    $address->setData("grand_total", (float)$address->getData("grand_total"));
                    $address->setData("base_grand_total", (float)$address->getData("base_grand_total"));
                }
 
$address->save();
                $quote->setGiftCardsAmountUsed((float)$address->getData("gift_cards_amount_used"));
                $quote->setBaseGiftCardsAmountUsed((float)$address->getData("base_gift_cards_amount_used"));
                $quote->save();