1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

handle cases when sub is already cancelled

This commit is contained in:
Kyle Spearrin 2017-08-10 09:12:55 -04:00
parent 789636b394
commit c802292098
2 changed files with 17 additions and 11 deletions

View File

@ -518,12 +518,7 @@ namespace Bit.Core.Services
{
if(!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
{
var subscriptionService = new StripeSubscriptionService();
var canceledSub = await subscriptionService.CancelAsync(organization.GatewaySubscriptionId, false);
if(!canceledSub.CanceledAt.HasValue)
{
throw new BadRequestException("Unable to cancel subscription.");
}
await _stripePaymentService.CancelSubscriptionAsync(organization, false);
}
await _organizationRepository.DeleteAsync(organization);

View File

@ -191,15 +191,26 @@ namespace Bit.Core.Services
throw new GatewayException("Subscription was not found.");
}
if(sub.CanceledAt.HasValue)
if(sub.CanceledAt.HasValue || sub.Status == "cancelled")
{
throw new GatewayException("Subscription is already canceled.");
// Already cancelled
return;
}
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
if(!canceledSub.CanceledAt.HasValue)
try
{
throw new GatewayException("Unable to cancel subscription.");
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
if(!canceledSub.CanceledAt.HasValue)
{
throw new GatewayException("Unable to cancel subscription.");
}
}
catch(StripeException e)
{
if(e.Message != $"No such subscription: {subscriber.GatewaySubscriptionId}")
{
throw e;
}
}
}