Fix Phase 16 code review issues#224
Merged
Merged
Conversation
- P1: Wrap handleInvoicePaid in DB::transaction + lockForUpdate to prevent race condition on concurrent invoice webhook delivery - P2: billing_webhook_events unique constraint changed to composite (provider, provider_event_id) to prevent cross-provider collisions; BillingWebhookEventRecorder updated to use composite key - P2: billing/success and billing/cancel views now extend x-layouts.app with navigation and app styling - P2: Removed string fallbacks from billing_plans.php config; test price IDs moved to phpunit.xml - P2: BillingPaymentService guards against empty-string Stripe price IDs using blank() instead of === null Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes 6 code review violations from Phase 16
P1 — Race condition in monthly credit grant (SubscriptionWebhookHandler.php:38)
Root cause:
alreadyGrantedForInvoice()check andgrant()call were not atomic — two concurrent webhook workers could both pass the check before either wrote.Fix: Wrapped
handleInvoicePaidbody inDB::transaction()withlockForUpdate()on the credit account row. Under MySQL/Postgres this serializes concurrent requests for the same user via row-level locking. Under SQLite (tests) transactions are already serialized at the connection level.P2 — Cross-provider collision in webhook event unique index
Root cause:
billing_webhook_events.provider_event_idwas globally unique, so identical event IDs from two different payment providers would silently drop one.Fix: New migration drops the single-column unique index and replaces it with a composite
(provider, provider_event_id)unique.BillingWebhookEventRecorder::recordIfNew()andwasProcessed()updated to use both columns.P2 — Billing views render as unstyled HTML
Root cause: Both views were created as plain HTML stubs to unblock route registration in CONV-245.
Fix: Both views now extend
<x-layouts.app>with title, navigation, app styling, and a "Go to dashboard" link.P2 — Config fallbacks mask missing Stripe price IDs
Root cause:
env('STRIPE_PRO_PRICE_ID', 'price_test_pro')silently returns a fake ID in any environment where the var isn't set.Fix: Removed string fallbacks —
env()now returnsnullwhen the var is absent. Test price IDs moved tophpunit.xmlso tests remain green.BillingPaymentServicealready blocks onblank()price IDs before calling Stripe.P2 — Empty string Stripe price IDs slip through guard
Root cause:
$plan->stripePriceId === nulldoes not catch''.Fix: Changed to
blank($plan->stripePriceId)which catchesnull,'', and' '.Test plan
composer testpasses (459 tests)composer lintpassesnpm run buildpasses🤖 Generated with Claude Code
Summary by cubic
Fix billing race conditions and webhook uniqueness, improve billing views, and tighten Stripe price ID handling to prevent invalid checkouts.
Bug Fixes
Migration
billing_webhook_eventsunique index to composite(provider, provider_event_id).STRIPE_PRO_PRICE_IDandSTRIPE_MAX_PRICE_IDare set in environment variables (defaults were removed).Written for commit fe467be. Summary will update on new commits.