From 5ccb4072a36789ce914e61f6896f617d1c144ff9 Mon Sep 17 00:00:00 2001 From: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:51:04 -0400 Subject: [PATCH] [AC-2766] famlies sponsorship upcoming invoice email (#4181) * Getting the fresh invoice if the subscription was updated when validation the families sponsorship * Getting fresh invoice after validation families sponsorship fails * Also updating invoice line items --- .../Implementations/UpcomingInvoiceHandler.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs b/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs index 6b54fd9af4..aaa06b9f47 100644 --- a/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs +++ b/src/Billing/Services/Implementations/UpcomingInvoiceHandler.cs @@ -77,7 +77,18 @@ public class UpcomingInvoiceHandler : IUpcomingInvoiceHandler { if (_stripeEventUtilityService.IsSponsoredSubscription(updatedSubscription)) { - await _validateSponsorshipCommand.ValidateSponsorshipAsync(organizationId.Value); + var sponsorshipIsValid = + await _validateSponsorshipCommand.ValidateSponsorshipAsync(organizationId.Value); + if (!sponsorshipIsValid) + { + // If the sponsorship is invalid, then the subscription was updated to use the regular families plan + // price. Given that this is the case, we need the new invoice amount + subscription = await _stripeFacade.GetSubscription(subscription.Id, + new SubscriptionGetOptions { Expand = ["latest_invoice"] }); + + invoice = subscription.LatestInvoice; + invoiceLineItemDescriptions = invoice.Lines.Select(i => i.Description).ToList(); + } } var organization = await _organizationRepository.GetByIdAsync(organizationId.Value);