Repository navigation
fix: credit purchase adapter issues - #4068
Conversation
📝 WalkthroughWalkthroughAdds Settlement.GetCostBasis() to return a settlement's cost basis by type. Consolidates credit-purchase logic into a shared issueCreditPurchase helper and updates handlers (initiated, promotional, payment-authorized, payment-settled) to use the new getter and unified issuance/settlement flows. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Handler as CreditPurchaseHandler
participant Charge as Charge (credit purchase)
participant Settlement
participant Templates
participant Transactions
participant Ledger
Client->>Handler: Trigger credit-purchase event (initiated/authorized/settled)
Handler->>Charge: read charge, intent, settlement
Charge->>Settlement: GetCostBasis()
Settlement-->>Handler: costBasis (or error)
Handler->>Templates: fill attribution/translation/issue/fund/settle templates with costBasis
Templates-->>Transactions: build transaction(s)
Transactions->>Ledger: commit transaction group
Ledger-->>Handler: GroupReference / result
Handler-->>Client: return GroupReference / error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Fixes two bugs: - no credit realization for negative credit was done on promotional credits - add support for invoice settlement type (and simplify type handling)
09d90d6 to
740e44a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openmeter/ledger/chargeadapter/creditpurchase.go (1)
191-194: Consider adding a brief comment explaining why accrued attribution is bounded by advance attribution.The calculation
accruedAttributionAmount := advanceAttributionAmountcreates a coupling where accrued attribution can never exceed advance attribution. This might be intentional accounting logic, but it's not immediately obvious from reading the code. A short comment here would help future readers understand the business reasoning.+ // Accrued attribution is bounded by advance attribution because [explain domain reason] accruedAttributionAmount := advanceAttributionAmount if accruedAttributionAmount.GreaterThan(unattributedAccrued) { accruedAttributionAmount = unattributedAccrued }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/ledger/chargeadapter/creditpurchase.go` around lines 191 - 194, Add a short clarifying comment above the bounding logic for accruedAttributionAmount that explains the business/accounting reason why accrued attribution is capped by advanceAttributionAmount (i.e., to prevent attributing more than was advanced) and mention the role of unattributedAccrued in the cap; update the block around accruedAttributionAmount, advanceAttributionAmount and unattributedAccrued to include that comment so future readers understand the intent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/ledger/chargeadapter/creditpurchase.go`:
- Around line 191-194: Add a short clarifying comment above the bounding logic
for accruedAttributionAmount that explains the business/accounting reason why
accrued attribution is capped by advanceAttributionAmount (i.e., to prevent
attributing more than was advanced) and mention the role of unattributedAccrued
in the cap; update the block around accruedAttributionAmount,
advanceAttributionAmount and unattributedAccrued to include that comment so
future readers understand the intent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e8cdbf9d-c100-4eb4-99ae-e3e8d635a864
📒 Files selected for processing (2)
openmeter/billing/charges/creditpurchase/settlement.goopenmeter/ledger/chargeadapter/creditpurchase.go
Overview
Fixes two bugs:
Notes for reviewer
Summary by CodeRabbit
Refactor
Bug Fixes