From fed01fa9d2fdb1d97e65a1ee16a3438e62336d33 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 12 Feb 2024 11:48:28 +0100 Subject: [PATCH] Fix subscription retrieval and handle missing subscriptions --- routes/webhooks.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routes/webhooks.php b/routes/webhooks.php index 25d438123..d79ff36a3 100644 --- a/routes/webhooks.php +++ b/routes/webhooks.php @@ -861,7 +861,11 @@ Route::post('/payments/stripe/events', function () { $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); if (!$subscription) { Sleep::for(5)->seconds(); - $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); + $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); + } + if (!$subscription) { + send_internal_notification('No subscription found for: ' . $customerId); + return response("No subscription found", 400); } $trialEndedAlready = data_get($subscription, 'stripe_trial_already_ended'); $cancelAtPeriodEnd = data_get($data, 'cancel_at_period_end');