diff --git a/src/Api/Controllers/OrganizationsController.cs b/src/Api/Controllers/OrganizationsController.cs index fae6c3f07..2aaef3309 100644 --- a/src/Api/Controllers/OrganizationsController.cs +++ b/src/Api/Controllers/OrganizationsController.cs @@ -111,7 +111,7 @@ namespace Bit.Api.Controllers throw new NotFoundException(); } - await _organizationRepository.ReplaceAsync(model.ToOrganization(organization)); + await _organizationService.UpdateAsync(model.ToOrganization(organization), true); return new OrganizationResponseModel(organization); } diff --git a/src/Core/Services/IOrganizationService.cs b/src/Core/Services/IOrganizationService.cs index de28cb724..354815ba4 100644 --- a/src/Core/Services/IOrganizationService.cs +++ b/src/Core/Services/IOrganizationService.cs @@ -16,6 +16,7 @@ namespace Bit.Core.Services Task UpgradePlanAsync(Guid organizationId, PlanType plan, int additionalSeats); Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment); Task> SignUpAsync(OrganizationSignup organizationSignup); + Task UpdateAsync(Organization organization, bool updateBilling = false); Task InviteUserAsync(Guid organizationId, Guid invitingUserId, string email, Enums.OrganizationUserType type, IEnumerable subvaults); Task ResendInviteAsync(Guid organizationId, Guid invitingUserId, Guid organizationUserId); diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index c66494739..79a3f4caa 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -621,6 +621,26 @@ namespace Bit.Core.Services } } + public async Task UpdateAsync(Organization organization, bool updateBilling = false) + { + if(organization.Id == default(Guid)) + { + throw new ApplicationException("Cannot create org this way. Call SignUpAsync."); + } + + await _organizationRepository.ReplaceAsync(organization); + + if(updateBilling && !string.IsNullOrWhiteSpace(organization.StripeCustomerId)) + { + var customerService = new StripeCustomerService(); + await customerService.UpdateAsync(organization.StripeCustomerId, new StripeCustomerUpdateOptions + { + Email = organization.BillingEmail, + Description = organization.BusinessName + }); + } + } + public async Task InviteUserAsync(Guid organizationId, Guid invitingUserId, string email, Enums.OrganizationUserType type, IEnumerable subvaults) {