Package.json file
{
"dependencies": {
"@medusajs/framework": "2.18.0",
"@medusajs/medusa": "2.18.0"
}
}
Node.js version
v26.4.0
Database and its version
N/A — pure totals helper
Operating system name and version
macOS 26.5
Browser name
No response
What happended?
With a negative credit line, order.credit_line_total and summary.credit_line_total return
different numbers for the same order, and pending_difference never settles back to 0, so
the same overpayment can be settled to store credit again.
calculateCreditLinesTotal (packages/core/utils/src/totals/credit-lines/index.ts) drops
sub-cent residue with MathBN.lte(creditLinesTotal, currencyEpsilon). The comparison is
one-sided, so every net negative total also satisfies it and is zeroed;
calculate-order-change.ts, which produces summary, has no such clamp.
Negative credit lines are supported: validateOrderCreditLinesStep allows them when
pending_difference < 0, and the admin balance settlement form sends amount: ... * -1 to
settle an overpayment to store credit.
Expected behavior
decorateCartTotals({
currency_code: "usd",
items: [{ unit_price: 50, quantity: 2, tax_lines: [] }],
credit_lines: [{ amount: -106 }],
})
// credit_line_total: -106, total: 206
Actual behavior
credit_line_total: 0 while summary.credit_line_total still reports -106; total: 100.
totals/cart/index.ts already compares MathBN.abs(...) for the sibling
pending_difference clamp. I have a fix ready and can open a PR.
Link to reproduction repo
Not needed — see the snippet above.
Package.json file
{ "dependencies": { "@medusajs/framework": "2.18.0", "@medusajs/medusa": "2.18.0" } }Node.js version
v26.4.0
Database and its version
N/A — pure totals helper
Operating system name and version
macOS 26.5
Browser name
No response
What happended?
With a negative credit line,
order.credit_line_totalandsummary.credit_line_totalreturndifferent numbers for the same order, and
pending_differencenever settles back to 0, sothe same overpayment can be settled to store credit again.
calculateCreditLinesTotal(packages/core/utils/src/totals/credit-lines/index.ts) dropssub-cent residue with
MathBN.lte(creditLinesTotal, currencyEpsilon). The comparison isone-sided, so every net negative total also satisfies it and is zeroed;
calculate-order-change.ts, which producessummary, has no such clamp.Negative credit lines are supported:
validateOrderCreditLinesStepallows them whenpending_difference < 0, and the admin balance settlement form sendsamount: ... * -1tosettle an overpayment to store credit.
Expected behavior
Actual behavior
credit_line_total: 0whilesummary.credit_line_totalstill reports-106;total: 100.totals/cart/index.tsalready comparesMathBN.abs(...)for the siblingpending_differenceclamp. I have a fix ready and can open a PR.Link to reproduction repo
Not needed — see the snippet above.