From 05356248eb46e737b53ecca6d6ebfebffcb4d318 Mon Sep 17 00:00:00 2001 From: Jonas Hendrickx Date: Wed, 6 Nov 2024 15:46:20 +0100 Subject: [PATCH] [PM-13450] Change Client Plan when Provider's Plan changes. (#4980) --- .../Billing/ProviderBillingService.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bitwarden_license/src/Commercial.Core/Billing/ProviderBillingService.cs b/bitwarden_license/src/Commercial.Core/Billing/ProviderBillingService.cs index e02160b06..7b1d33599 100644 --- a/bitwarden_license/src/Commercial.Core/Billing/ProviderBillingService.cs +++ b/bitwarden_license/src/Commercial.Core/Billing/ProviderBillingService.cs @@ -481,6 +481,23 @@ public class ProviderBillingService( }; await stripeAdapter.SubscriptionUpdateAsync(command.GatewaySubscriptionId, updateOptions); + + // Refactor later to ?ChangeClientPlanCommand? (ProviderPlanId, ProviderId, OrganizationId) + // 1. Retrieve PlanType and PlanName for ProviderPlan + // 2. Assign PlanType & PlanName to Organization + var providerOrganizations = await providerOrganizationRepository.GetManyDetailsByProviderAsync(plan.ProviderId); + + foreach (var providerOrganization in providerOrganizations) + { + var organization = await organizationRepository.GetByIdAsync(providerOrganization.OrganizationId); + if (organization == null) + { + throw new ConflictException($"Organization '{providerOrganization.Id}' not found."); + } + organization.PlanType = command.NewPlan; + organization.Plan = StaticStore.GetPlan(command.NewPlan).Name; + await organizationRepository.ReplaceAsync(organization); + } } public async Task UpdateSeatMinimums(UpdateProviderSeatMinimumsCommand command)