10000 Merge pull request #141 from NativePHP/improve-state-logic-mobile-pri… · rinodrummer/nativephp.com@26e9003 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26e9003

Browse files
authored
Merge pull request NativePHP#141 from NativePHP/improve-state-logic-mobile-pricing
Improve $user handling and add error logging in MobilePricing
2 parents 08ec0fd + fd08934 commit 26e9003

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

app/Livewire/MobilePricing.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Models\User;
77
use Illuminate\Support\Facades\Auth;
88
use Illuminate\Support\Facades\Hash;
9+
use Illuminate\Support\Facades\Log;
910
use Illuminate\Support\Str;
1011
use Livewire\Component;
1112

@@ -24,11 +25,24 @@ public function handlePurchaseRequest(array $data)
2425

2526
public function createCheckoutSession(string $plan, ?User $user = null)
2627
{
27-
if (! ($user ??= Auth::user())) {
28+
// If a user isn't passed into this method, Livewire will instantiate
29+
// a new User. So we need to check that the user exists before using it,
30+
// and then use the authenticated user as a fallback.
31+
$user = $user?->exists ? $user : Auth::user();
32+
33+
if (! $user) {
34+
// TODO: return a flash message or notification to the user that there
35+
// was an error.
36+
Log::error('Failed to create checkout session. User does not exist and user is not authenticated.');
37+
2838
return;
2939
}
3040

3141
if (! ($subscription = Subscription::tryFrom($plan))) {
42+
// TODO: return a flash message or notification to the user that there
43+
// was an error.
44+
Log::error('Failed to create checkout session. Invalid subscription plan name provided.');
45+
3246
return;
3347
}
3448

0 commit comments

Comments
 (0)
0