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.