1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

[fix] Only cancel premium subscriptions after failed payments (#2075)

This commit is contained in:
Addison Beck 2022-06-24 12:17:58 -07:00 committed by GitHub
parent daeaa42851
commit 75ab5826e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);