Repository navigation
Description
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:
opensourcepos/app/Models/Sale.php
Lines 584 to 589 in d4b96f5
| 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:
opensourcepos/app/Models/Giftcard.php
Lines 316 to 318 in d4b96f5
| 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:
opensourcepos/app/Views/sales/register.php
Lines 49 to 59 in d4b96f5
| 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.
- Create an item with Retail Price
24.00and 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 Value6.00. - Open Sales and change the register mode from "Sales Receipt" to "Return".
- Add the item in "Find or Scan Item or Receipt". The line shows quantity -1 and total -24.00.
- 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.
- Click Complete.
- 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
objecttothis commentedon Oct 26, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Still present (not yet merged).
The root cause described in this issue matches
masterexactly:app/Models/Giftcard.php::decrementGiftcardValue()guards withif ($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 (noabs()/sign normalization for returns), and rolls back the whole transaction withINSUFFICIENT_GIFTCARD_BALANCEwhenever it returnsfalse.<= 0.0guard will always reject it, sopostComplete()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
masteras described.fix(sales): allow gift card credit for returns + surface errors
fix(sales): allow gift card credit for returns + surface errors
fix(sales): allow gift card credit for returns + surface errors
Iweisc commentedon Nov 2, 2026
@jekkos Btw, was this bug report helpful? 😛
fix(sales): allow gift card credit for returns + surface errors (open…