From 25b79f095beb12a96ffe66434a1a4dfcf064d96f Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Thu, 23 Apr 2026 10:31:07 +0100 Subject: [PATCH] feat: bust plan cache on customer.subscription.updated --- app/Listeners/HandleStripeWebhook.php | 3 ++- tests/Feature/Payments/HandleStripeWebhookTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Listeners/HandleStripeWebhook.php b/app/Listeners/HandleStripeWebhook.php index 401a156..d206929 100644 --- a/app/Listeners/HandleStripeWebhook.php +++ b/app/Listeners/HandleStripeWebhook.php @@ -24,7 +24,8 @@ final class HandleStripeWebhook } match ($type) { - 'customer.subscription.created' => $this->bustPlanCache($user), + 'customer.subscription.created', + 'customer.subscription.updated' => $this->bustPlanCache($user), default => null, }; } diff --git a/tests/Feature/Payments/HandleStripeWebhookTest.php b/tests/Feature/Payments/HandleStripeWebhookTest.php index 4a50c04..3f441d6 100644 --- a/tests/Feature/Payments/HandleStripeWebhookTest.php +++ b/tests/Feature/Payments/HandleStripeWebhookTest.php @@ -28,3 +28,15 @@ it('ignores subscription.created when the user is not found', function (): void expect(true)->toBeTrue(); }); + +it('busts the plan cache on customer.subscription.updated', function (): void { + $user = User::factory()->create(['stripe_id' => 'cus_updated_1']); + Cache::tags(['plans'])->put("plan_for_user_{$user->id}", 'stale', 3600); + + (new HandleStripeWebhook)->handle(new WebhookReceived([ + 'type' => 'customer.subscription.updated', + 'data' => ['object' => ['customer' => 'cus_updated_1']], + ])); + + expect(Cache::tags(['plans'])->get("plan_for_user_{$user->id}"))->toBeNull(); +});