Repository navigation
feat(subscription): dual read/write taxcode on subscription items - #4011
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR wires a Changes
Sequence DiagramsequenceDiagram
participant Client
participant Service as SubscriptionService
participant TaxSvc as TaxCodeService
participant Repo as ItemRepository
participant DB as Database
Client->>Service: CreateSubscriptionItem(RateCard with Stripe code)
activate Service
Service->>Service: resolveTaxCode()
Service->>TaxSvc: GetOrCreateByAppMapping(stripe_code)
activate TaxSvc
TaxSvc->>DB: Query/Create TaxCode
DB-->>TaxSvc: TaxCode(entity with ID)
TaxSvc-->>Service: TaxCode(entity)
deactivate TaxSvc
Service->>Service: Update RateCard.TaxConfig.TaxCodeID
Service->>Repo: Create(item with TaxCodeID & TaxBehavior)
activate Repo
Repo->>DB: Persist subscription_item (+tax fields)
DB-->>Repo: Success
Repo-->>Service: Created item
Service->>Repo: GetByID (WithTaxCode)
Repo->>DB: Query item + TaxCode edge
DB-->>Repo: Item + TaxCode entity
Repo->>Repo: BackfillTaxConfig(TaxConfig, TaxBehavior, TaxCode)
Repo-->>Service: Hydrated SubscriptionItem
Service-->>Client: SubscriptionItem (TaxCodeID populated)
deactivate Service
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 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.
🧹 Nitpick comments (1)
openmeter/subscription/service/synchelpers.go (1)
119-121: Consider memoizing Stripe tax-code resolution per create flow.Line 119 triggers resolution per item, and Lines 198-202 can hit the DB repeatedly for the same Stripe code. A small in-request cache keyed by Stripe code would keep behavior the same and cut extra round-trips.
As per coding guidelines
**/*.go: “Performance should be a priority in critical code paths... database operations ... should be vetted for potential performance bottlenecks.”Also applies to: 198-202
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: be4b0734-9840-4916-ac99-2b37f1911ec4
📒 Files selected for processing (14)
app/common/subscription.gocmd/billing-worker/wire_gen.gocmd/jobs/internal/wire_gen.gocmd/server/wire_gen.goopenmeter/productcatalog/adapter/taxconfig.goopenmeter/productcatalog/addon/adapter/mapping.goopenmeter/productcatalog/plan/adapter/mapping.goopenmeter/productcatalog/tax.goopenmeter/subscription/repo/mapping.goopenmeter/subscription/repo/subscriptionitemrepo.goopenmeter/subscription/service/service.goopenmeter/subscription/service/service_test.goopenmeter/subscription/service/synchelpers.goopenmeter/subscription/testutils/service.go
💤 Files with no reviewable changes (1)
- openmeter/productcatalog/adapter/taxconfig.go
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/subscription/testutils/compare.go`:
- Around line 85-93: The test may panic because foundMeta.TaxConfig can be nil
while specMeta has a Stripe code; before accessing foundMeta.TaxConfig.TaxCodeID
in the block that checks specMeta.TaxConfig.Stripe.Code, first require that
foundMeta.TaxConfig is not nil (e.g., require.NotNil(t, foundMeta.TaxConfig,
"...", specItem.ItemKey, specPhase.PhaseKey)) and only then require/ assert on
foundMeta.TaxConfig.TaxCodeID and equality with specMeta.TaxConfig.TaxCodeID;
keep the existing else branch that asserts foundMeta.TaxConfig == nil for items
without a Stripe tax code.
🪄 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: a43f7c6b-11ed-4758-94e4-57a17fb94915
📒 Files selected for processing (1)
openmeter/subscription/testutils/compare.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/subscription/testutils/compare.go`:
- Around line 88-93: The current conditional in compare.go checks TaxCodeID
equality only when specMeta.TaxConfig.Stripe.Code is present, which is incorrect
because TaxCodeID may be backfilled independently; change the logic to first
branch on whether specMeta.TaxConfig.TaxCodeID is set: if
specMeta.TaxConfig.TaxCodeID != "" then require foundMeta.TaxConfig and assert
equality between specMeta.TaxConfig.TaxCodeID and foundMeta.TaxConfig.TaxCodeID;
else if specMeta.TaxConfig != nil && specMeta.TaxConfig.Stripe != nil &&
specMeta.TaxConfig.Stripe.Code != "" then require foundMeta.TaxConfig and
require foundMeta.TaxConfig.TaxCodeID to be non-nil (backfilled) but do not
assert equality to the Stripe code; otherwise assert
foundMeta.TaxConfig.TaxCodeID is nil. Use the existing symbols
specMeta.TaxConfig, specMeta.TaxConfig.Stripe.Code, specMeta.TaxConfig.TaxCodeID
and foundMeta.TaxConfig.TaxCodeID to locate and update the branches.
🪄 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: f9509cb8-b7e9-4f92-a6e1-25f69af27f40
📒 Files selected for processing (1)
openmeter/subscription/testutils/compare.go
Summary by CodeRabbit