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(); +});