chore: allow enabling credit then invoice seperately#4136
Conversation
📝 WalkthroughWalkthroughThe PR introduces an Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.go (1)
34-86: Consider adding one more matrix case for flag precedence.This suite is strong already. I’d just add the
credits disabled + CTI enabledcombo to lock in the!creditsEnabledshort-circuit path explicitly forCreditThenInvoiceSettlementMode.Suggested test case addition
{ + name: "credit then invoice with credits disabled falls back to invoice lines", + settlementMode: productcatalog.CreditThenInvoiceSettlementMode, + enableCredits: false, + enableCreditThenInvoice: true, + rateCard: usageRateCard, + expectedCollection: &lineInvoicePatchCollection{}, + }, + { name: "credit then invoice enabled flat fee uses flat fee charges", settlementMode: productcatalog.CreditThenInvoiceSettlementMode, enableCredits: true,As per coding guidelines "
**/*_test.go: Make sure the tests are comprehensive and cover the changes."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.go` around lines 34 - 86, Add a test case to the testCases slice in patch_test.go that covers the "credits disabled + CreditThenInvoice enabled" precedence: create an entry with settlementMode set to productcatalog.CreditThenInvoiceSettlementMode, enableCredits: false, enableCreditThenInvoice: true, pick any rateCard (e.g., flatRateCard) and set expectedCollection to &lineInvoicePatchCollection{} to assert the !enableCredits short-circuit; insert it alongside the other cases in the testCases slice so the suite explicitly validates that CreditThenInvoice does not enable credits when enableCredits is false.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/billing/worker/subscriptionsync/service/reconciler/patch.go`:
- Around line 75-77: The current validation in the reconciler erroneously treats
a zero capacity as invalid (if c.capacity <= 0) which makes legitimate no-op
reconciliations fail; update the check in the function containing the "if
c.capacity <= 0" guard to only reject negative capacities (e.g., use c.capacity
< 0) or remove the check so zero is accepted, and keep the error message/context
tied to the same symbol (c.capacity) so callers still get an error for truly
invalid negative values.
---
Nitpick comments:
In `@openmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.go`:
- Around line 34-86: Add a test case to the testCases slice in patch_test.go
that covers the "credits disabled + CreditThenInvoice enabled" precedence:
create an entry with settlementMode set to
productcatalog.CreditThenInvoiceSettlementMode, enableCredits: false,
enableCreditThenInvoice: true, pick any rateCard (e.g., flatRateCard) and set
expectedCollection to &lineInvoicePatchCollection{} to assert the !enableCredits
short-circuit; insert it alongside the other cases in the testCases slice so the
suite explicitly validates that CreditThenInvoice does not enable credits when
enableCredits is false.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9c4072fd-1b50-4b75-a12c-d00447cf1661
📒 Files selected for processing (11)
app/common/billing.goapp/config/config_test.goapp/config/credits.gocmd/billing-worker/wire_gen.gocmd/jobs/internal/wire_gen.goconfig.example.yamle2e/config.yamlopenmeter/billing/worker/subscriptionsync/service/reconciler/patch.goopenmeter/billing/worker/subscriptionsync/service/reconciler/patch_test.goopenmeter/billing/worker/subscriptionsync/service/reconciler/reconciler.goopenmeter/billing/worker/subscriptionsync/service/service.go
Overview
Allow controling credit_then_invoice seperately of credit_only. If disabled credit_then_invoice falls back to invoice only.
Notes for reviewer
Summary by CodeRabbit
New Features
enable_credit_then_invoiceconfiguration option to enable an alternative billing settlement mode that processes credit operations alongside invoice generation.Chores
Tests