Skip to content

fix(billing): convert cents to units in dispute credit#3625

Merged
PierreBrisorgueil merged 1 commit intomasterfrom
fix/billing-v8-credit-dispute-units
May 7, 2026
Merged

fix(billing): convert cents to units in dispute credit#3625
PierreBrisorgueil merged 1 commit intomasterfrom
fix/billing-v8-credit-dispute-units

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

Summary

  • V8 audit C5: creditDisputeReinstated was passing amountCents directly to creditCompensation instead of converting to meter units via dollarsToUnitRatio
  • Fix adds Math.round((amountCents / 100) * getDollarsToUnitRatio()) conversion (~3 LOC) before the creditCompensation call
  • Audit-trail log now includes both amountCents and creditUnits for traceability
  • JSDoc updated to clarify the conversion: 5000 cents = 50,000 units at default ratio 1000

Test plan

  • Existing test updated: applies credit and returns applied:true + ledgerEntry — now asserts creditCompensation called with creditUnits=20000 (not raw amountCents=2000)
  • New regression test: converts amountCents to creditUnits using dollarsToUnitRatio (V8 audit C5) — asserts 5000 cents → 50000 units at ratio 1000
  • All 64 unit tests pass (billing.admin.service.unit.tests.js)
  • ESLint: 0 issues

V8 audit C5: amountCents was passed directly to creditCompensation
instead of being converted to meter units. Adds getDollarsToUnitRatio()
conversion (default 1000 → 5000 cents = 50,000 units) + audit-trail
logging of both amountCents and creditUnits for traceability.
Copilot AI review requested due to automatic review settings May 7, 2026 10:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 35 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 925f474e-e017-4f95-ab2d-cfe61b78e4b4

📥 Commits

Reviewing files that changed from the base of the PR and between ddb0285 and aeaf963.

📒 Files selected for processing (2)
  • modules/billing/services/billing.admin.service.js
  • modules/billing/tests/billing.admin.service.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/billing-v8-credit-dispute-units

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes billing dispute crediting so creditDisputeReinstated converts amountCents into meter units using config.billing.meter.dollarsToUnitRatio (instead of treating cents as units), and improves audit logging/test coverage around the conversion.

Changes:

  • Convert dispute amountCentscreditUnits via getDollarsToUnitRatio() before calling creditCompensation.
  • Extend audit log payload to include creditUnits alongside amountCents.
  • Update/add unit tests to assert the conversion behavior and prevent regressions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
modules/billing/services/billing.admin.service.js Converts dispute cents to meter units using getDollarsToUnitRatio() and logs creditUnits.
modules/billing/tests/billing.admin.service.unit.tests.js Updates existing assertion for converted units and adds a regression test for cents→units conversion.

Comment on lines +341 to +343
// Convert cents to meter units using the configured dollarsToUnitRatio.
const creditUnits = Math.round((amountCents / 100) * getDollarsToUnitRatio());
const result = await BillingExtraBalanceRepository.creditCompensation(orgId, creditUnits, refId, reason);
// amountCents is used directly as the credit unit — ops chooses the proportional amount.
const result = await BillingExtraBalanceRepository.creditCompensation(orgId, amountCents, refId, reason);
// Convert cents to meter units using the configured dollarsToUnitRatio.
const creditUnits = Math.round((amountCents / 100) * getDollarsToUnitRatio());
Comment on lines +455 to +456
// amountCents=2000, default dollarsToUnitRatio=1000 → creditUnits = Math.round((2000/100)*1000) = 20000
const expectedCreditUnits = Math.round((amountCents / 100) * 1000);
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.82%. Comparing base (ddb0285) to head (aeaf963).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3625   +/-   ##
=======================================
  Coverage   88.82%   88.82%           
=======================================
  Files         134      134           
  Lines        4616     4617    +1     
  Branches     1423     1423           
=======================================
+ Hits         4100     4101    +1     
  Misses        403      403           
  Partials      113      113           
Flag Coverage Δ
integration 59.30% <0.00%> (-0.02%) ⬇️
unit 62.85% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ddb0285...aeaf963. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil PierreBrisorgueil merged commit cd3ec29 into master May 7, 2026
11 checks passed
@PierreBrisorgueil PierreBrisorgueil deleted the fix/billing-v8-credit-dispute-units branch May 7, 2026 12:00
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.

2 participants