fix(billing): enforce currency match on wallet credit/debit#1325
Open
marcelo-maciel wants to merge 1 commit into
Open
fix(billing): enforce currency match on wallet credit/debit#1325marcelo-maciel wants to merge 1 commit into
marcelo-maciel wants to merge 1 commit into
Conversation
Wallet.Credit/Debit took a raw decimal and stamped the wallet's own currency, so MarkInvoicePaidAsync crediting invoice.SubtotalAmount.Amount silently treated a foreign-currency invoice as a wallet-currency credit at face value. Latent while single-currency, but wrong the moment a pre-existing wallet's currency diverges from a later invoice. Both sides are now Money: Credit/Debit take Money and route the balance through Money.Add/Subtract, which throw on a currency mismatch. BillingService guards the top-up credit with a Conflict CustomException so the mismatch surfaces as a meaningful error instead of a raw 500 from deep in Money. Adds Credit_rejects_currency_mismatch as a regression guard.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Wallet.CreditandWallet.Debittook a rawdecimaland stamped the wallet's own currency onto the resultingMoney.BillingService.MarkInvoicePaidAsynccredited a top-up by passinginvoice.SubtotalAmount.Amount, droppinginvoice.Currencyon the way in.The effect: a top-up invoice in one currency credited to a wallet in another currency was applied at face value with the wallet's currency label. For example, a 100 EUR invoice paid against a pre-existing USD wallet credited 100 USD. The
Money.Add/Money.Subtractcurrency guard never fired, because by the time it ran both operands had already been forced to the wallet's currency.This is latent while the product is single-currency (a freshly created wallet at line 255 inherits
invoice.Currency, so it always matches). It becomes a real, silent balance error the moment a pre-existing wallet's currency diverges from a later invoice.Fix
Now that both sides are
Money(following the recent Money value-object adoption in Billing):Wallet.Credit/Wallet.Debittake aMoneyinstead of adecimaland route the balance throughMoney.Add/Money.Subtract, which throw on a currency mismatch. The hole closes at the domain boundary.BillingServicepassesinvoice.SubtotalAmountthrough unchanged and guards the top-up credit: if a pre-existing wallet's currency differs from the invoice, it throws aCustomExceptionwithHttpStatusCode.Conflictand a clear message, so the mismatch surfaces as a meaningful error rather than a raw 500 bubbling out ofMoney.Testing
dotnet buildclean, 0 warnings (TreatWarningsAsErrors).Billing.Testssuite: 124 passed, 0 failed. AddsCredit_rejects_currency_mismatchas a regression guard for the closed hole; existing Wallet tests migrated to theMoneysignature.WalletTopupServiceTests) were not run in this environment (require Docker/Testcontainers); the change to the credit path is value-preserving on the happy path and the new guard only fires on a currency mismatch those tests do not set up.Notes
Wallet.Credit/Debitsignature changesdecimal->Money.Walletis internal domain, so no public HTTP surface changes; no endpoint, config, or docs change is required. Flagging the signature change for reviewer awareness.