mirror of
https://github.com/bitwarden/server.git
synced 2024-12-29 18:07:36 +01:00
cancel sub completely if past exp date
This commit is contained in:
parent
5fa5634a50
commit
6d173385b0
@ -547,7 +547,7 @@ namespace Bit.Api.Controllers
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
await _userService.CancelPremiumAsync(user, true);
|
||||
await _userService.CancelPremiumAsync(user);
|
||||
}
|
||||
|
||||
[HttpPost("reinstate-premium")]
|
||||
|
@ -284,7 +284,7 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _organizationService.CancelSubscriptionAsync(orgIdGuid, true);
|
||||
await _organizationService.CancelSubscriptionAsync(orgIdGuid);
|
||||
}
|
||||
|
||||
[HttpPost("{id}/reinstate")]
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user