Skip to content

pr: [Nightly Fix] - Bug - Fix Double Tax Amount in Coupon Discount Calculation#58

Open
jewel-claw wants to merge 1 commit into
masterfrom
nightly-fix/fix-double-tax-in-coupon-discount-calculation
Open

pr: [Nightly Fix] - Bug - Fix Double Tax Amount in Coupon Discount Calculation#58
jewel-claw wants to merge 1 commit into
masterfrom
nightly-fix/fix-double-tax-in-coupon-discount-calculation

Conversation

@jewel-claw

Copy link
Copy Markdown

Summary

Bug: Tax is double-counted in the transaction record when a coupon is applied.

Root cause

In SubmissionHandler::handleSubmission(), $paymentTotal is built by summing all line items including tax line items:

foreach ($paymentItems as $paymentItem) {
    $paymentTotal += $paymentItem['line_total'];
    if ($paymentItem['type'] == 'tax_line') {
        $taxTotal += $paymentItem['line_total'];
    }
}

So $paymentTotal = subtotal + tax.

When a coupon was applied, the old formula was:

$paymentTotal = ($paymentTotal - ($paymentTotal * $discountPercent)/100) + $taxTotal;

This re-adds $taxTotal after applying the discount — double-counting tax in the stored transaction.

Example: $100 subtotal, $10 tax, 10% coupon

  • $paymentTotal before = $110
  • After discount: $110 - $11 = $99 ✅
  • Old code: $99 + $10 (taxTotal) = $109 ❌ (overcharge)

The original developer even commented //issue on bottom line flagging the problem.

Fix: Remove the erroneous + $taxTotal. Tax is already included in $paymentTotal and is correctly discounted proportionally.

…lculation

$paymentTotal is accumulated from all line items in the loop above, which
includes tax line items ($paymentItem['type'] == 'tax_line'). So $paymentTotal
already equals (subtotal + tax).

When a coupon is applied, the old formula was:
  $paymentTotal = ($paymentTotal - $paymentTotal * $discountPercent/100) + $taxTotal

This re-adds $taxTotal after the discount, causing tax to be counted twice in
the transaction record. For example, with a $100 subtotal, $10 tax, and 10%
coupon: correct total = $99, but old code produced $99 + $10 = $109.

The original comment even flagged this: '//issue on bottom line'.

Fix: remove the erroneous $taxTotal addition. Tax is already included in
$paymentTotal and should be discounted proportionally along with the rest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant