Repository navigation
fix(charges): persist fiat payment amounts - #4779
Conversation
📝 WalkthroughWalkthroughPayment settlements now expose ChangesFiat amount settlement alignment
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CreditPurchase
participant ExternalAuthorization
participant PaymentPersistence
CreditPurchase->>ExternalAuthorization: credit amount and settlement
ExternalAuthorization->>ExternalAuthorization: calculate rounded fiat amount
ExternalAuthorization->>PaymentPersistence: create payment with FiatAmount
PaymentPersistence-->>CreditPurchase: persisted settlement
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
| @@ -0,0 +1,59 @@ | |||
| -- Repair invoiced credit-purchase payments that stored the purchased credit amount | |||
There was a problem hiding this comment.
Backfill lacks migration coverage
This hand-written data repair has no dedicated migration test covering representative existing rows and its abort conditions, leaving upgrade behavior and destructive backfill mistakes outside the repository's migration test safeguards.
Knowledge Base Used: Data layer: ent schema, migrations, and generated client
Prompt To Fix With AI
This is a comment left during a code review.
Path: tools/migrate/migrations/20260724082957_backfill_credit_purchase_invoice_fiat_amount.up.sql
Line: 1
Comment:
**Backfill lacks migration coverage**
This hand-written data repair has no dedicated migration test covering representative existing rows and its abort conditions, leaving upgrade behavior and destructive backfill mistakes outside the repository's migration test safeguards.
**Knowledge Base Used:** [Data layer: ent schema, migrations, and generated client](https://app.greptile.com/openmeter/-/custom-context/knowledge-base/openmeterio/openmeter/-/docs/data-layer.md)
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Leaving a dedicated migration test out intentionally per maintainer direction for this change. The SQL consistency guards remain in place, and Atlas migration validation and lint both pass locally.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
openmeter/billing/charges/creditpurchase/service/external_test.go (1)
155-158: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winKeep an assertion for the created payment’s fiat amount.
This test no longer verifies the behavior introduced by this PR. With a rounded credit amount of
100.12and a cost basis of0.5, the external payment should receive50.06; regressions in multiplication or settlement-currency rounding would currently pass.Suggested assertion
err = stateMachine.FireAndActivate(t.Context(), billing.TriggerAuthorized) require.NoError(t, err) +require.Equal(t, 50.06, adapter.createdExternalPayment.Base.FiatAmount.InexactFloat64()) handler.AssertExpectations(t)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@openmeter/billing/charges/creditpurchase/service/external_test.go` around lines 155 - 158, The payment authorization test should continue asserting the created external payment’s fiat amount. In the flow around stateMachine.FireAndActivate, retrieve the created payment from the existing test setup and assert its fiat amount is 50.06, covering multiplication and settlement-currency rounding.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@openmeter/billing/charges/creditpurchase/service/external_test.go`:
- Around line 155-158: The payment authorization test should continue asserting
the created external payment’s fiat amount. In the flow around
stateMachine.FireAndActivate, retrieve the created payment from the existing
test setup and assert its fiat amount is 50.06, covering multiplication and
settlement-currency rounding.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cbd8c5dd-3ffe-4ee0-859a-30b1bf8c4f16
⛔ Files ignored due to path filters (23)
openmeter/ent/db/chargecreditpurchaseexternalpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseexternalpayment/chargecreditpurchaseexternalpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseexternalpayment/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseexternalpayment_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseexternalpayment_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseinvoicedpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseinvoicedpayment/chargecreditpurchaseinvoicedpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseinvoicedpayment/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseinvoicedpayment_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargecreditpurchaseinvoicedpayment_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerunpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerunpayment/chargeflatfeerunpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerunpayment/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerunpayment_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeflatfeerunpayment_update.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrunpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrunpayment/chargeusagebasedrunpayment.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrunpayment/where.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrunpayment_create.gois excluded by!**/ent/db/**openmeter/ent/db/chargeusagebasedrunpayment_update.gois excluded by!**/ent/db/**openmeter/ent/db/entmixinaccessor.gois excluded by!**/ent/db/**openmeter/ent/db/mutation.gois excluded by!**/ent/db/**tools/migrate/migrations/atlas.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (12)
openmeter/billing/charges/creditpurchase/service/external_test.goopenmeter/billing/charges/creditpurchase/service/invoice.goopenmeter/billing/charges/creditpurchase/service/realizations/service.goopenmeter/billing/charges/flatfee/service/payment.goopenmeter/billing/charges/models/payment/mixin.goopenmeter/billing/charges/models/payment/models.goopenmeter/billing/charges/service/creditpurchase_test.goopenmeter/billing/charges/usagebased/service/run/payment.goopenmeter/billing/charges/usagebased/service/run/payment_test.goopenmeter/ledger/chargeadapter/usagebased_test.gotools/migrate/migrations/20260724082957_backfill_credit_purchase_invoice_fiat_amount.down.sqltools/migrate/migrations/20260724082957_backfill_credit_purchase_invoice_fiat_amount.up.sql
|
Addressed the external fiat-amount coverage suggestion in 2d2fec9 by extending the ledger-backed integration scenario instead of restoring the service unit assertion. The scenario supplies 100.123 credits, exercises normalization to 100.12 through the production path, and asserts a 50.06 fiat payment. |
Summary
Testing
Summary by CodeRabbit
Bug Fixes
Data Updates
Greptile Summary
This PR corrects persisted payment amounts to represent fiat value consistently.
AmounttoFiatAmountwhile retaining the existing database column.Confidence Score: 5/5
The PR appears safe to merge, with no blocking failures remaining from the reviewed follow-up threads.
No blocking failure remains.
Important Files Changed
amountdatabase column.Reviews (2): Last reviewed commit: "fix(charges): address payment review fee..." | Re-trigger Greptile
Context used: