1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 17:12:49 -05: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

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