Skip to content

Commit 864d848

Browse files
committed
Handle Stripe errors, unknown price IDs, and malformed docs URLs gracefully
- Wrap Stripe Connect account creation in try-catch to show user-friendly error instead of 500 - Catch unknown Stripe price IDs in OrderSuccess and report instead of crashing - Catch UrlGenerationException in docs catch-all route for malformed page values like ${NC}
1 parent 82825ef commit 864d848

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

app/Http/Controllers/DeveloperOnboardingController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function start(Request $request): RedirectResponse
3232
$user = $request->user();
3333
$developerAccount = $user->developerAccount;
3434

35-
if (! $developerAccount) {
36-
$developerAccount = $this->stripeConnectService->createConnectAccount($user);
37-
}
38-
3935
try {
36+
if (! $developerAccount) {
37+
$developerAccount = $this->stripeConnectService->createConnectAccount($user);
38+
}
39+
4040
$onboardingUrl = $this->stripeConnectService->createOnboardingLink($developerAccount);
4141

4242
return redirect($onboardingUrl);

app/Livewire/OrderSuccess.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ public function loadData(): void
5959
return;
6060
}
6161

62-
$this->subscription = Subscription::fromStripePriceId($subscriptionItem->stripe_price);
62+
try {
63+
$this->subscription = Subscription::fromStripePriceId($subscriptionItem->stripe_price);
64+
} catch (\RuntimeException $e) {
65+
report($e);
66+
67+
return;
68+
}
69+
6370
$this->email = $subscriptionRecord->user->email;
6471
$this->licenseKey = License::query()
6572
->whereBelongsTo($subscriptionItem)

routes/web.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,19 @@
220220
}
221221
}
222222

223-
return to_route('docs.show', [
224-
'platform' => $platform,
225-
'version' => $version,
226-
'page' => $page,
227-
]);
223+
try {
224+
return to_route('docs.show', [
225+
'platform' => $platform,
226+
'version' => $version,
227+
'page' => $page,
228+
]);
229+
} catch (\Illuminate\Routing\Exceptions\UrlGenerationException) {
230+
return to_route('docs.show', [
231+
'platform' => $platform,
232+
'version' => $version,
233+
'page' => 'introduction',
234+
]);
235+
}
228236
})->name('docs')->where('page', '.*');
229237

230238
Route::get('order/{checkoutSessionId}', App\Livewire\OrderSuccess::class)->name('order.success');

0 commit comments

Comments
 (0)