File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 66use App \Models \User ;
77use Illuminate \Support \Facades \Auth ;
88use Illuminate \Support \Facades \Hash ;
9+ use Illuminate \Support \Facades \Log ;
910use Illuminate \Support \Str ;
1011use Livewire \Component ;
1112
@@ -24,11 +25,25 @@ 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 if the user is
31+ // logged in.
32+ $ user = $ user ?->exists ? $ user : Auth::user ();
33+
34+ if (! $ user ) {
35+ // TODO: return a flash message or notification to the user that there
36+ // was an error.
37+ Log::error ('Failed to create checkout session. User does not exist and user is not authenticated. ' );
38+
2839 return ;
2940 }
3041
3142 if (! ($ subscription = Subscription::tryFrom ($ plan ))) {
43+ // TODO: return a flash message or notification to the user that there
44+ // was an error.
45+ Log::error ('Failed to create checkout session. Invalid subscription plan name provided. ' );
46+
3247 return ;
3348 }
3449
You can’t perform that action at this time.
0 commit comments