From e583beb753d07355b75b94418900d726d7401714 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 3 Nov 2023 14:51:29 +0100 Subject: [PATCH] fix: invoice.paid should sleep for 5 seconds --- routes/webhooks.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes/webhooks.php b/routes/webhooks.php index dc1caa7c4..fc5d0d592 100644 --- a/routes/webhooks.php +++ b/routes/webhooks.php @@ -12,6 +12,7 @@ use App\Models\Waitlist; use App\Models\Webhook; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Sleep; use Illuminate\Support\Str; use Visus\Cuid2\Cuid2; @@ -281,7 +282,11 @@ Route::post('/payments/stripe/events', function () { break; case 'invoice.paid': $customerId = data_get($data, 'customer'); - $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); + $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); + if (!$subscription) { + Sleep::for(5); + $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); + } $planId = data_get($data, 'lines.data.0.plan.id'); $subscription->update([ 'stripe_plan_id' => $planId,