1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

Fix stripe invoice time on seat adjust (#1564)

* Finalize and void subscription updates

Stripe does not allow deletion of invoices created as subscription updates.
Instead, finalize it and void it out without sending to the customer.

* Store and Restore invoice days until due

Currently, we're overwriting customer invoice lead times whenever they
attempt to update their seat count. Changes are now updated to previous
behavior after our seat adjustment work

* PR Comments
This commit is contained in:
Matt Gibson 2021-09-03 09:55:29 -04:00 committed by GitHub
parent 1d3c7cc936
commit db0ef226c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -414,8 +414,9 @@ namespace Bit.Core.Services
var prorationDate = DateTime.UtcNow;
var seatItem = sub.Items?.Data?.FirstOrDefault(i => i.Plan.Id == plan.StripeSeatPlanId);
// Retain original collection method
// Retain original collection method and days util due
var collectionMethod = sub.CollectionMethod;
var daysUntilDue = sub.DaysUntilDue;
var subUpdateOptions = new SubscriptionUpdateOptions
{
@ -430,8 +431,8 @@ namespace Bit.Core.Services
}
},
ProrationBehavior = "always_invoice",
DaysUntilDue = 1,
CollectionMethod = "send_invoice",
DaysUntilDue = daysUntilDue ?? 1,
ProrationDate = prorationDate,
};
@ -485,17 +486,19 @@ namespace Bit.Core.Services
// being applied forward to the next month's invoice
ProrationBehavior = "none",
CollectionMethod = collectionMethod,
DaysUntilDue = daysUntilDue,
});
throw;
}
}
// Change back the subscription collection method
if (collectionMethod != "send_invoice")
// Change back the subscription collection method and/or days until due
if (collectionMethod != "send_invoice" || daysUntilDue == null)
{
await subscriptionService.UpdateAsync(sub.Id, new SubscriptionUpdateOptions
{
CollectionMethod = collectionMethod,
DaysUntilDue = daysUntilDue,
});
}

View File

@ -889,7 +889,18 @@ namespace Bit.Core.Services
if (cardPaymentMethodId == null)
{
// We're going to delete this draft invoice, it can't be paid
await invoiceService.DeleteAsync(invoice.Id);
try
{
await invoiceService.DeleteAsync(invoice.Id);
}
catch
{
await invoiceService.FinalizeInvoiceAsync(invoice.Id, new InvoiceFinalizeOptions
{
AutoAdvance = false
});
await invoiceService.VoidInvoiceAsync(invoice.Id);
}
throw new BadRequestException("No payment method is available.");
}
}