Skip to content

Round CC surcharge immediately after calculating for event-based payments #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wdst-gcet
Copy link

@wdst-gcet wdst-gcet commented Jan 29, 2025

Issue

Accounts with a credit card and auto-billing enabled would occasionally show a balance of 1 cent when a credit card surcharge percentage was applied during the nightly cron job. However, this issue did not occur when billed manually.

Cause

The issue arises in edge cases where small rounding variations accumulate, leading to a 1-cent difference for some transactions.

Scenario 1: $85.00 with a 2.3% surcharge

  1. Surcharge calculation: $85.00 × 2.3% = $1.955
  2. Adding the surcharge: $85.00 + $1.955 = $86.955
  3. Rounded total: $86.96

Now, if the system later recalculates the total without first rounding the surcharge, it might continue using the unrounded surcharge value ($1.955). This can cause minor rounding discrepancies at certain steps, potentially leading to a missing cent.

Scenario 2: $155.07 with a 2.3% surcharge

  1. Surcharge calculation: $155.07 × 2.3% = $3.56661
  2. Adding the surcharge: $155.07 + $3.56661 = $158.63661
  3. Rounded total: $158.64

In this case, despite the surcharge having multiple decimal places, when it is added and rounded, the final total remains accurate. The rounding difference is too small to cause a discrepancy, meaning the total aligns correctly.

Fix

The fix ensures that the surcharge is rounded to two decimal places immediately after calculation, preventing rounding errors and ensuring the total remains accurate to the nearest cent, preventing rounding discrepancies

…hopefully, this doesn’t introduce any new issues.

@wdst-gcet wdst-gcet marked this pull request as ready for review February 14, 2025 21:37
Copy link
Author

@wdst-gcet wdst-gcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After waiting for a full billing cycle I think this fix is good.

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