File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 6
6
use App \Models \User ;
7
7
use Illuminate \Support \Facades \Auth ;
8
8
use Illuminate \Support \Facades \Hash ;
9
+ use Illuminate \Support \Facades \Log ;
9
10
use Illuminate \Support \Str ;
10
11
use Livewire \Component ;
11
12
@@ -24,11 +25,24 @@ public function handlePurchaseRequest(array $data)
24
25
25
26
public function createCheckoutSession (string $ plan , ?User $ user = null )
26
27
{
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
+
28
38
return ;
29
39
}
30
40
31
41
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
+
32
46
return ;
33
47
}
34
48
You can’t perform that action at this time.
0 commit comments