From ebe665534940abe788d9e48d9065bfa1f9d0df8f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 27 Oct 2023 10:28:43 +0200 Subject: [PATCH] update invoice paid --- routes/webhooks.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/routes/webhooks.php b/routes/webhooks.php index dc1caa7c4..4c39905e7 100644 --- a/routes/webhooks.php +++ b/routes/webhooks.php @@ -281,12 +281,25 @@ Route::post('/payments/stripe/events', function () { break; case 'invoice.paid': $customerId = data_get($data, 'customer'); - $subscription = Subscription::where('stripe_customer_id', $customerId)->firstOrFail(); - $planId = data_get($data, 'lines.data.0.plan.id'); - $subscription->update([ - 'stripe_plan_id' => $planId, - 'stripe_invoice_paid' => true, - ]); + $email = data_get($data, 'customer_email'); + $subscription = Subscription::where('stripe_customer_id', $customerId)->first(); + if ($subscription) { + $planId = data_get($data, 'lines.data.0.plan.id'); + $subscription->update([ + 'stripe_plan_id' => $planId, + 'stripe_invoice_paid' => true, + ]); + break; + } + $team = Team::where('email', $email)->first(); + if ($team) { + $subscription = data_get($team, 'subscription'); + $planId = data_get($data, 'lines.data.0.plan.id'); + $subscription->update([ + 'stripe_plan_id' => $planId, + 'stripe_invoice_paid' => true, + ]); + } break; case 'payment_intent.payment_failed': $customerId = data_get($data, 'customer');