diff --git a/src/Api/Controllers/AccountsController.cs b/src/Api/Controllers/AccountsController.cs index 740019795..703f7a8df 100644 --- a/src/Api/Controllers/AccountsController.cs +++ b/src/Api/Controllers/AccountsController.cs @@ -547,7 +547,7 @@ namespace Bit.Api.Controllers throw new UnauthorizedAccessException(); } - await _userService.CancelPremiumAsync(user, true); + await _userService.CancelPremiumAsync(user); } [HttpPost("reinstate-premium")] diff --git a/src/Api/Controllers/OrganizationsController.cs b/src/Api/Controllers/OrganizationsController.cs index 7f657db49..340b07908 100644 --- a/src/Api/Controllers/OrganizationsController.cs +++ b/src/Api/Controllers/OrganizationsController.cs @@ -284,7 +284,7 @@ namespace Bit.Api.Controllers throw new NotFoundException(); } - await _organizationService.CancelSubscriptionAsync(orgIdGuid, true); + await _organizationService.CancelSubscriptionAsync(orgIdGuid); } [HttpPost("{id}/reinstate")] diff --git a/src/Core/Services/IOrganizationService.cs b/src/Core/Services/IOrganizationService.cs index 181da0eb5..257cb5d1c 100644 --- a/src/Core/Services/IOrganizationService.cs +++ b/src/Core/Services/IOrganizationService.cs @@ -11,7 +11,7 @@ namespace Bit.Core.Services public interface IOrganizationService { Task ReplacePaymentMethodAsync(Guid organizationId, string paymentToken); - Task CancelSubscriptionAsync(Guid organizationId, bool endOfPeriod = false); + Task CancelSubscriptionAsync(Guid organizationId, bool? endOfPeriod = null); Task ReinstateSubscriptionAsync(Guid organizationId); Task UpgradePlanAsync(Guid organizationId, PlanType plan, int additionalSeats); Task AdjustStorageAsync(Guid organizationId, short storageAdjustmentGb); diff --git a/src/Core/Services/IUserService.cs b/src/Core/Services/IUserService.cs index cb763065b..0ee83ce77 100644 --- a/src/Core/Services/IUserService.cs +++ b/src/Core/Services/IUserService.cs @@ -47,7 +47,7 @@ namespace Bit.Core.Services Task UpdateLicenseAsync(User user, UserLicense license); Task AdjustStorageAsync(User user, short storageAdjustmentGb); Task ReplacePaymentMethodAsync(User user, string paymentToken); - Task CancelPremiumAsync(User user, bool endOfPeriod = false); + Task CancelPremiumAsync(User user, bool? endOfPeriod = null); Task ReinstatePremiumAsync(User user); Task DisablePremiumAsync(Guid userId, DateTime? expirationDate); Task DisablePremiumAsync(User user, DateTime? expirationDate); diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index 8776b49db..da6a5c8f6 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -85,7 +85,7 @@ namespace Bit.Core.Services } } - public async Task CancelSubscriptionAsync(Guid organizationId, bool endOfPeriod = false) + public async Task CancelSubscriptionAsync(Guid organizationId, bool? endOfPeriod = null) { var organization = await GetOrgById(organizationId); if(organization == null) @@ -93,7 +93,14 @@ namespace Bit.Core.Services throw new NotFoundException(); } - await _stripePaymentService.CancelSubscriptionAsync(organization, endOfPeriod); + var eop = endOfPeriod.GetValueOrDefault(true); + if(!endOfPeriod.HasValue && organization.ExpirationDate.HasValue && + organization.ExpirationDate.Value < DateTime.UtcNow) + { + eop = false; + } + + await _stripePaymentService.CancelSubscriptionAsync(organization, eop); } public async Task ReinstateSubscriptionAsync(Guid organizationId) diff --git a/src/Core/Services/Implementations/UserService.cs b/src/Core/Services/Implementations/UserService.cs index fb6c46921..c7386cf92 100644 --- a/src/Core/Services/Implementations/UserService.cs +++ b/src/Core/Services/Implementations/UserService.cs @@ -820,10 +820,16 @@ namespace Bit.Core.Services } } - public async Task CancelPremiumAsync(User user, bool endOfPeriod = false) + public async Task CancelPremiumAsync(User user, bool? endOfPeriod = null) { var paymentService = user.GetPaymentService(_globalSettings); - await paymentService.CancelSubscriptionAsync(user, endOfPeriod); + var eop = endOfPeriod.GetValueOrDefault(true); + if(!endOfPeriod.HasValue && user.PremiumExpirationDate.HasValue && + user.PremiumExpirationDate.Value < DateTime.UtcNow) + { + eop = false; + } + await paymentService.CancelSubscriptionAsync(user, eop); } public async Task ReinstatePremiumAsync(User user)