Skip to content

[Bug]: Return refunded to a gift card cannot be completed and shows no error #4779

Closed

Description

@Iweisc

Watch in BugReels (the gift card refund is added at 1:59 with "remaining value is Rs. 30.00!", Complete reloads the same return with no message at 2:12 and again at 2:39, and Gift Cards still shows the card at Rs. 6.00 at 2:58)

🐛 Bug Description

A return that is refunded to a gift card cannot be completed. In Return mode, after a Gift Card payment is added, the register announces the card's new value. Clicking Complete then posts to /sales/complete and shows the same register again, with the return and the gift card payment still listed and no message. The card is not credited and no return sale is recorded. Clicking Complete again gives the same result. The same return with a Cash payment completes normally.

This is a regression from #4683 (f5f9052, 1 September 2026).

Cause

A return's gift card payment is negative by design. postAddPayment() skips the balance check outside sale mode and adds min(amount_due, value), which is the negative amount due (Sales.php#L482, #L490). Sale::save_value() sends every gift card payment to decrementGiftcardValue() and rolls back when it returns false:

if ($paymentPrefix === lang('Sales.giftcard')) {
if (empty($splitPayment[1]) || ! $giftcard->decrementGiftcardValue($splitPayment[1], (float) $payment['payment_amount'])) {
$this->db->transRollback();
return INSUFFICIENT_GIFTCARD_BALANCE;
}

Since #4683, decrementGiftcardValue() returns false for any amount at or below zero:

if ($amount <= 0.0) {
return false;
}

Before that commit the same query ran value - (-24) and credited the card. The guard was added to stop forged negative payments in sales, so a fix likely has to allow the negative amount only for returns. save_value() already receives $saleType, which is SALE_TYPE_RETURN here. I have not written or tested a patch.

The failure is also silent. postComplete() sets $data['error_message'] and calls reload() (Sales.php#L1008-L1016, and the same pattern at L894, L934 and L974), but the register view only renders $error, $warning and $success:

if (isset($error)) {
echo '<div class="alert alert-dismissible alert-danger">' . esc($error) . '</div>';
}
if (!empty($warning)) {
echo '<div class="alert alert-dismissible alert-warning">' . esc($warning) . '</div>';
}
if (isset($success)) {
echo '<div class="alert alert-dismissible alert-success">' . esc($success) . '</div>';
}

So "Insufficient gift card balance for this payment." and the reward points and transaction failure messages never reach the cashier.

📋 Steps to Reproduce

Reproduced on https://demo.opensourcepos.org (3.4.3-dev, 35b682) as admin / pointofsale. The test data was deleted afterwards, so step 1 creates it.

  1. Create an item with Retail Price 24.00 and some stock (both tax names have to be filled because of [Bug]: Cannot save new item with empty Tax 2 row – "Tax Name contains disallowed characters" / "Tax Percent must be a non-negative value" #4773). Create a gift card with Value 6.00.
  2. Open Sales and change the register mode from "Sales Receipt" to "Return".
  3. Add the item in "Find or Scan Item or Receipt". The line shows quantity -1 and total -24.00.
  4. Set Payment Type to "Gift Card", type the card number in the gift card field and click Add Payment. The page shows "Gift Card remaining value is 30.00!", the payment line "Gift Card: -24.00" and Amount Due 0.00.
  5. Click Complete.
  6. Open Gift Cards and look at the card.

✅ Expected Behavior

The return completes with a return receipt, and the gift card value goes from 6.00 to 30.00, as the message in step 4 says.

Actual: Complete shows the register again at /sales/complete with the return and "Gift Card: -24.00" still listed and no alert. Gift Cards still lists the card at 6.00, and no return sale is recorded.

📦 OpenSourcePOS Version

development (unreleased)

🔧 PHP Version

PHP 8.2

🌐 Browser(s)

Chrome

🖥️ Server Operating System

Linux 5.4.0-216-generic (demo.opensourcepos.org, from its System Info)

🗄️ Database

10.5.29-MariaDB-ubu2004 (demo.opensourcepos.org)

🌍 Web Server

Apache/2.4.69 (Debian) (demo.opensourcepos.org)

📊 System Information Report

OSPOS Installation Info: 3.4.3-dev - 35b682
Language Code: en
Extensions & Modules: GD, BC Math, intl, OpenSSL, Multibyte String, cURL, JSON, XML enabled
Server Software: Apache/2.4.69 (Debian)
PHP Version: 8.2.35
DB Version: 10.5.29-MariaDB-ubu2004
OS: Linux 5.4.0-216-generic

(Taken from the demo's System Info tab and trimmed. The permissions section is left out.)

📜 Relevant Log Output

No console errors. I have no access to the demo's server logs.

📸 Screenshots

The BugReels link at the top is a recording of the return, both Complete attempts and the Gift Cards list.

✓ Confirmation

  • I certify that this is an unmodified copy of OpenSourcePOS
  • I have searched existing issues to ensure this bug has not already been reported
  • I have provided all the information requested above

This report was drafted with Claude Code (Claude Opus 5.5). The bug was reproduced on the demo, and the cause was checked against the linked source and the code before f5f9052.

Activity

  1. objecttothis commented on Oct 26, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Investigated against current master.

    Status: Still present (not yet merged).

    The root cause described in this issue matches master exactly:

    • app/Models/Giftcard.php::decrementGiftcardValue() guards with if ($amount <= 0.0) { return false; } before any DB update.
    • app/Models/Sale.php::save_value() calls $giftcard->decrementGiftcardValue($splitPayment[1], (float) $payment['payment_amount']) directly on the raw payment amount (no abs()/sign normalization for returns), and rolls back the whole transaction with INSUFFICIENT_GIFTCARD_BALANCE whenever it returns false.
    • Since a return's gift card payment amount is negative by design (as noted in the issue), this <= 0.0 guard will always reject it, so postComplete() will always fail silently for this flow exactly as reported.

    No PR is currently open or merged addressing this (the issue author explicitly notes they haven't written a patch). This bug is reproducible on master as described.

  2. added 3 commits that reference this issue on Oct 27, 2026
    3d440da
    d3e6681
    8620ff7
  3. Iweisc commented on Nov 2, 2026

    @Iweisc
    Author

    @jekkos Btw, was this bug report helpful? 😛

  4. added a commit that references this issue on Nov 2, 2026
    fa0fa53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions