Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-15808]Show suspended org modals for orgs in 'unpaid' & 'canceled' status #5173

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/Api/Billing/Controllers/OrganizationBillingController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#nullable enable
using Bit.Api.AdminConsole.Models.Request.Organizations;
using Bit.Api.Billing.Models.Requests;
using Bit.Api.Billing.Models.Responses;
using Bit.Core;
using Bit.Core.Billing.Models.Sales;
using Bit.Core.Billing.Services;
using Bit.Core.Context;
using Bit.Core.Repositories;
Expand All @@ -21,7 +23,8 @@ public class OrganizationBillingController(
IOrganizationRepository organizationRepository,
IPaymentService paymentService,
ISubscriberService subscriberService,
IPaymentHistoryService paymentHistoryService) : BaseBillingController
IPaymentHistoryService paymentHistoryService,
IUserService userService) : BaseBillingController
{
[HttpGet("metadata")]
public async Task<IResult> GetMetadataAsync([FromRoute] Guid organizationId)
Expand Down Expand Up @@ -278,4 +281,36 @@ public async Task<IResult> UpdateTaxInformationAsync(

return TypedResults.Ok();
}

[HttpPost("restart-subscription")]
public async Task<IResult> RestartSubscriptionAsync([FromRoute] Guid organizationId, [FromBody] OrganizationCreateRequestModel model)
{
var user = await userService.GetUserByPrincipalAsync(User);
if (user == null)
{
throw new UnauthorizedAccessException();
}

if (!featureService.IsEnabled(FeatureFlagKeys.AC2476_DeprecateStripeSourcesAPI))
{
return Error.NotFound();
}

if (!await currentContext.EditPaymentMethods(organizationId))
{
return Error.Unauthorized();
}

var organization = await organizationRepository.GetByIdAsync(organizationId);

if (organization == null)
{
return Error.NotFound();
}
var organizationSignup = model.ToOrganizationSignup(user);
var sale = OrganizationSale.From(organization, organizationSignup);
await organizationBillingService.Finalize(sale);

return TypedResults.Ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ public record OrganizationMetadataResponse(
bool IsManaged,
bool IsOnSecretsManagerStandalone,
bool IsSubscriptionUnpaid,
bool HasSubscription)
bool HasSubscription,
bool IsSubscriptionCanceled)
{
public static OrganizationMetadataResponse From(OrganizationMetadata metadata)
=> new(
metadata.IsEligibleForSelfHost,
metadata.IsManaged,
metadata.IsOnSecretsManagerStandalone,
metadata.IsSubscriptionUnpaid,
metadata.HasSubscription);
metadata.HasSubscription,
metadata.IsSubscriptionCanceled);
}
3 changes: 2 additions & 1 deletion src/Core/Billing/Models/OrganizationMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public record OrganizationMetadata(
bool IsManaged,
bool IsOnSecretsManagerStandalone,
bool IsSubscriptionUnpaid,
bool HasSubscription);
bool HasSubscription,
bool IsSubscriptionCanceled);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
IOrganizationRepository organizationRepository,
ISetupIntentCache setupIntentCache,
IStripeAdapter stripeAdapter,
ISubscriberService subscriberService) : IOrganizationBillingService
ISubscriberService subscriberService,
IPaymentService paymentService,

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Run tests

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Quality scan

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (win-x64)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (osx-x64)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Setup, ./util)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (MsSqlMigratorUtility, ./util, true)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Api, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Notifications, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (EventsProcessor, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Events, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Identity, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Icons, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Sso, ./bitwarden_license/src, true)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Scim, ./bitwarden_license/src, true)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Billing, ./src)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Admin, ./src, true)

Parameter 'paymentService' is unread.

Check warning on line 32 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Upload

Parameter 'paymentService' is unread.
IFeatureService featureService) : IOrganizationBillingService

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Run tests

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Quality scan

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (win-x64)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (osx-x64)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build MSSQL migrator utility (linux-x64)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Setup, ./util)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (MsSqlMigratorUtility, ./util, true)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Api, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Notifications, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (EventsProcessor, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Events, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Identity, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Icons, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Sso, ./bitwarden_license/src, true)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Scim, ./bitwarden_license/src, true)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Billing, ./src)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Build artifacts (Admin, ./src, true)

Parameter 'featureService' is unread.

Check warning on line 33 in src/Core/Billing/Services/Implementations/OrganizationBillingService.cs

View workflow job for this annotation

GitHub Actions / Upload

Parameter 'featureService' is unread.
{
public async Task Finalize(OrganizationSale sale)
{
Expand Down Expand Up @@ -68,7 +70,7 @@
if (string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
{
return new OrganizationMetadata(isEligibleForSelfHost, isManaged, false,
false, false);
false, false, false);
}

var customer = await subscriberService.GetCustomer(organization,
Expand All @@ -77,10 +79,11 @@
var subscription = await subscriberService.GetSubscription(organization);
var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription);
var isSubscriptionUnpaid = IsSubscriptionUnpaid(subscription);
var isSubscriptionCanceled = IsSubscriptionCanceled(subscription);
var hasSubscription = true;

return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone,
isSubscriptionUnpaid, hasSubscription);
isSubscriptionUnpaid, hasSubscription, isSubscriptionCanceled);
}

public async Task UpdatePaymentMethod(
Expand Down Expand Up @@ -393,6 +396,16 @@
return subscription.Status == "unpaid";
}

private static bool IsSubscriptionCanceled(Subscription subscription)
{
if (subscription == null)
{
return false;
}

return subscription.Status == "canceled";
}


#endregion
}
Loading