mirror of
https://github.com/bitwarden/server.git
synced 2025-04-21 04:55:08 -05:00
cancel subscription service
This commit is contained in:
parent
18d2715c71
commit
52dcd6d6ab
@ -10,6 +10,7 @@ namespace Bit.Core.Services
|
|||||||
{
|
{
|
||||||
Task<OrganizationBilling> GetBillingAsync(Organization organization);
|
Task<OrganizationBilling> GetBillingAsync(Organization organization);
|
||||||
Task ReplacePaymentMethodAsync(Guid organizationId, string paymentToken);
|
Task ReplacePaymentMethodAsync(Guid organizationId, string paymentToken);
|
||||||
|
Task CancelSubscriptionAsync(Guid organizationId, bool endOfPeriod = false);
|
||||||
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
|
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
|
||||||
Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email,
|
Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email,
|
||||||
Enums.OrganizationUserType type, IEnumerable<SubvaultUser> subvaults);
|
Enums.OrganizationUserType type, IEnumerable<SubvaultUser> subvaults);
|
||||||
|
@ -127,6 +127,39 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task CancelSubscriptionAsync(Guid organizationId, bool endOfPeriod = false)
|
||||||
|
{
|
||||||
|
var organization = await _organizationRepository.GetByIdAsync(organizationId);
|
||||||
|
if(organization == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(string.IsNullOrWhiteSpace(organization.StripeSubscriptionId))
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Organization has no subscription.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var subscriptionService = new StripeSubscriptionService();
|
||||||
|
var sub = await subscriptionService.GetAsync(organization.StripeCustomerId);
|
||||||
|
|
||||||
|
if(sub == null)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Organization subscription was not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sub.Status == "canceled")
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Organization subscription is already canceled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var canceledSub = await subscriptionService.CancelAsync(sub.Id, endOfPeriod);
|
||||||
|
if(canceledSub?.Status != "canceled")
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Unable to cancel subscription.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup signup)
|
public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup signup)
|
||||||
{
|
{
|
||||||
var plan = StaticStore.Plans.FirstOrDefault(p => p.Type == signup.Plan && !p.Disabled);
|
var plan = StaticStore.Plans.FirstOrDefault(p => p.Type == signup.Plan && !p.Disabled);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user