Fix null Stripe invoice crash in upgrade preview#387
Merged
Conversation
…eled-in-grace subscribers Cashier's Subscription::previewInvoice() returns null when Stripe has no upcoming invoice (e.g. canceled subscription in grace period) — the call to asStripeInvoice() on null threw an Error that the \Exception catch didn't catch, surfacing as a 500. Add a null guard, widen the catch to \Throwable, and for canceled-but- in-grace users skip Stripe entirely and show a degraded preview based on configured plan price. Stripe still computes proration correctly at swapAndInvoice time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #63:
Error: Call to a member function asStripeInvoice() on nullthrown fromapp/Livewire/MobilePricing.php:121when a user opens the upgrade modal.Root cause
Cashier's
Subscription::previewInvoice()returnsnullwhen Stripe has no upcoming invoice (canceled subscription, missing customer, etc.). The existingtry/catch (\Exception)didn't catch the resulting\Error(PHPErrordoesn't extendException), so it surfaced as a 500.Fix
previewInvoice()so the existing "Unable to load pricing preview" fallback UI renders gracefully.\Exceptionto\Throwableas a defense-in-depth for any future PHP errors on this path.swapAndInvoicetime, so the charge stays correct.Test plan
preview_upgrade_sets_preview_to_null_when_stripe_has_no_upcoming_invoice).MobilePricingTestcases pass; broader Livewire/Stripe test sweep (185 tests) passes.🤖 Generated with Claude Code