mirror of
https://github.com/bitwarden/server.git
synced 2025-05-23 04:21:05 -05:00
handle cases when sub is already cancelled
This commit is contained in:
parent
789636b394
commit
c802292098
@ -518,12 +518,7 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
if(!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
|
if(!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
|
||||||
{
|
{
|
||||||
var subscriptionService = new StripeSubscriptionService();
|
await _stripePaymentService.CancelSubscriptionAsync(organization, false);
|
||||||
var canceledSub = await subscriptionService.CancelAsync(organization.GatewaySubscriptionId, false);
|
|
||||||
if(!canceledSub.CanceledAt.HasValue)
|
|
||||||
{
|
|
||||||
throw new BadRequestException("Unable to cancel subscription.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await _organizationRepository.DeleteAsync(organization);
|
await _organizationRepository.DeleteAsync(organization);
|
||||||
|
@ -191,17 +191,28 @@ namespace Bit.Core.Services
|
|||||||
throw new GatewayException("Subscription was not found.");
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
|
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
|
||||||
if(!canceledSub.CanceledAt.HasValue)
|
if(!canceledSub.CanceledAt.HasValue)
|
||||||
{
|
{
|
||||||
throw new GatewayException("Unable to cancel subscription.");
|
throw new GatewayException("Unable to cancel subscription.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(StripeException e)
|
||||||
|
{
|
||||||
|
if(e.Message != $"No such subscription: {subscriber.GatewaySubscriptionId}")
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task ReinstateSubscriptionAsync(ISubscriber subscriber)
|
public async Task ReinstateSubscriptionAsync(ISubscriber subscriber)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user