Skip to content

Bound return gift-card credits to the server-calculated refund total #4787

Open

Description

@jekkos

Problem

The aggregate payments_cover_total check does not limit each individual gift-card payment. A return totaling -100 can pass with a gift-card payment of -200 and another payment of +100. Sale::save_value() then credits the gift card by 200, exceeding the actual refund.

Suggested fix

In postComplete(), before calling save_value(), validate that the sum of all negative gift-card payment amounts does not exceed the server-recalculated return total. Reject the sale if it does.

Context

Raised by CodeRabbit review on #4781. Tracked separately to keep that PR scoped to the #4779 regression fix.

Activity

  1. objecttothis commented on Oct 29, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Status: Still present in master.

    In app/Controllers/Sales.php, postComplete() only validates the aggregate totals before calling Sale::save_value():

    if (!$totals['payments_cover_total'] && !$this->sale_lib->is_invoice_mode() && !$this->sale_lib->is_quote_mode()) {
        $data['error'] = lang('Sales.amount_due_not_covered');
        return $this->reload($data);
    }

    There is no check limiting the sum of individual negative gift-card payment amounts against the server-recalculated return total — $data['payments'] is passed straight into $this->sale->save_value(...) without any per-gift-card or sum-of-gift-card-payments bound. In Sale::save_value() (app/Models/Sale.php), each gift-card payment is applied via $giftcard->decrementGiftcardValue($splitPayment[1], (float) $payment['payment_amount']), which simply decrements (credits, for negative amounts) by whatever amount is submitted — it doesn't cross-check against the overall return total either. So a return of -100 with a gift-card payment of -200 offset by another +100 payment could still pass the aggregate check and over-credit the gift card by 200, as described.

    No related fix commits were found in current master history. This appears to still need the suggested validation in postComplete() before save_value() is called.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions