1
0
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:
Kyle Spearrin 2018-12-31 13:34:02 -05:00
parent 5fa5634a50
commit 6d173385b0
6 changed files with 21 additions and 8 deletions

View File

@ -547,7 +547,7 @@ namespace Bit.Api.Controllers
throw new UnauthorizedAccessException();
}
await _userService.CancelPremiumAsync(user, true);
await _userService.CancelPremiumAsync(user);
}
[HttpPost("reinstate-premium")]

View File

@ -284,7 +284,7 @@ namespace Bit.Api.Controllers
throw new NotFoundException();
}
await _organizationService.CancelSubscriptionAsync(orgIdGuid, true);
await _organizationService.CancelSubscriptionAsync(orgIdGuid);
}
[HttpPost("{id}/reinstate")]

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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)