From 75ab5826e026ff2c662d7a1ad86f810ea910f1f7 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Fri, 24 Jun 2022 12:17:58 -0700 Subject: [PATCH] [fix] Only cancel premium subscriptions after failed payments (#2075) --- src/Billing/Controllers/StripeController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index 15742a39de..5e824d8a81 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -437,7 +437,7 @@ namespace Bit.Billing.Controllers } else if (parsedEvent.Type.Equals(HandledStripeWebhook.PaymentFailed)) { - await HandlePaymentFailed(await GetInvoiceAsync(parsedEvent, true)); + await HandlePaymentFailed(await GetInvoiceAsync(parsedEvent, true), await GetSubscriptionAsync(parsedEvent)); } else if (parsedEvent.Type.Equals(HandledStripeWebhook.InvoiceCreated)) { @@ -802,12 +802,12 @@ namespace Bit.Billing.Controllers private static bool IsSponsoredSubscription(Subscription subscription) => StaticStore.SponsoredPlans.Any(p => p.StripePlanId == subscription.Id); - private async Task HandlePaymentFailed(Invoice invoice) + private async Task HandlePaymentFailed(Invoice invoice, Subscription subscription) { if (!invoice.Paid && invoice.AttemptCount > 1 && UnpaidAutoChargeInvoiceForSubscriptionCycle(invoice)) { // attempt count 4 = 11 days after initial failure - if (invoice.AttemptCount > 3) + if (invoice.AttemptCount > 3 && subscription.Items.Any(i => i.Plan.Id == PremiumPlanId)) { await CancelSubscription(invoice.SubscriptionId); await VoidOpenInvoices(invoice.SubscriptionId);