feat(statemachine): promotional credit purchase statemachine#4457
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)
📝 WalkthroughWalkthroughAdds a promotional credit-purchase state machine with persistence wiring, Charge accessor methods, an EntryFunc helper, replaces the prior promotional handler call in Create with state-machine advancement, and adds comprehensive tests for promotional flows and constructor validation. ChangesPromotional Credit Purchase State Machine
Sequence DiagramsequenceDiagram
participant CreateService
participant PromotionalStateMachine
participant RuntimeService
participant Adapter
CreateService->>PromotionalStateMachine: NewPromotionalCreditPurchaseStateMachine(config)
PromotionalStateMachine->>PromotionalStateMachine: AdvanceUntilStateStable(ctx)
PromotionalStateMachine->>RuntimeService: GrantPromotionalCredit(ctx)
RuntimeService->>Adapter: CreateCreditGrant / UpdateCharge
Adapter-->>RuntimeService: persisted charge / credit-grant ref
RuntimeService-->>PromotionalStateMachine: updated Charge
PromotionalStateMachine-->>CreateService: advanced Charge (optional)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
6f8a027 to
183525e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@openmeter/billing/charges/creditpurchase/service/promotional.go`:
- Around line 53-60: NewPromotionalCreditPurchaseStateMachine must validate that
the runtime Service is non-nil before constructing the state machine because
GrantPromotionalCredit dereferences s.Service (used when reaching StatusFinal);
update NewPromotionalCreditPurchaseStateMachine to check config.Service (or the
specific field that provides s.Service) and return a descriptive error if nil so
the machine is not created with a nil Service.
In `@openmeter/billing/charges/creditpurchase/service/statemachine.go`:
- Around line 34-38: The Validate method on StateMachineConfig currently only
checks Charge.ID and allows a nil Adapter through; update
StateMachineConfig.Validate to also check that c.Adapter is not nil and return a
descriptive error (e.g. "adapter is required") so construction fails fast
instead of causing panics later in methods like UpdateBase or Refetch; reference
the StateMachineConfig.Validate function and the Adapter field to locate where
to add this nil-check and error return.
🪄 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: 3f95e466-817d-4084-b55c-9e426c71694b
📒 Files selected for processing (6)
openmeter/billing/charges/creditpurchase/charge.goopenmeter/billing/charges/creditpurchase/service/create.goopenmeter/billing/charges/creditpurchase/service/promotional.goopenmeter/billing/charges/creditpurchase/service/promotional_test.goopenmeter/billing/charges/creditpurchase/service/statemachine.gopkg/statelessx/actions.go
7ada3c1 to
1bc5a97
Compare
1bc5a97 to
81e00dd
Compare
81e00dd to
1cba13a
Compare
Summary by CodeRabbit
Refactor
Bug Fixes
Improvements
Tests