Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/Livewire/MobilePricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Livewire\Component;

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

public function createCheckoutSession(string $plan, ?User $user = null)
{
if (! ($user ??= Auth::user())) {
// If a user isn't passed into this method, Livewire will instantiate
// a new User. So we need to check that the user exists before using it,
// and then use the authenticated user as a fallback.
$user = $user?->exists ? $user : Auth::user();

if (! $user) {
// TODO: return a flash message or notification to the user that there
// was an error.
Log::error('Failed to create checkout session. User does not exist and user is not authenticated.');

return;
}

if (! ($subscription = Subscription::tryFrom($plan))) {
// TODO: return a flash message or notification to the user that there
// was an error.
Log::error('Failed to create checkout session. Invalid subscription plan name provided.');

return;
}

Expand Down