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 all commits
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 @@
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 @@

return TypedResults.Ok();
}

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

Check warning on line 288 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L287-L288

Added lines #L287 - L288 were not covered by tests
if (user == null)
{
throw new UnauthorizedAccessException();

Check warning on line 291 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L290-L291

Added lines #L290 - L291 were not covered by tests
}

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

Check warning on line 296 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L295-L296

Added lines #L295 - L296 were not covered by tests
}

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

Check warning on line 301 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L300-L301

Added lines #L300 - L301 were not covered by tests
}

var organization = await organizationRepository.GetByIdAsync(organizationId);

Check warning on line 304 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L304

Added line #L304 was not covered by tests

if (organization == null)
{
return Error.NotFound();

Check warning on line 308 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L307-L308

Added lines #L307 - L308 were not covered by tests
}
var organizationSignup = model.ToOrganizationSignup(user);
var sale = OrganizationSale.From(organization, organizationSignup);
await organizationBillingService.Finalize(sale);

Check warning on line 312 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L310-L312

Added lines #L310 - L312 were not covered by tests

return TypedResults.Ok();
}

Check warning on line 315 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L314-L315

Added lines #L314 - L315 were not covered by tests
}
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 / 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 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 (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 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 / 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 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 / 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 / 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 / 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 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 (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 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 / 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 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 / 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 / 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);

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

View check run for this annotation

Codecov / codecov/patch

src/Core/Billing/Services/Implementations/OrganizationBillingService.cs#L73

Added line #L73 was not covered by tests
}

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task GetMetadataAsync_OK(
{
sutProvider.GetDependency<ICurrentContext>().OrganizationUser(organizationId).Returns(true);
sutProvider.GetDependency<IOrganizationBillingService>().GetMetadata(organizationId)
.Returns(new OrganizationMetadata(true, true, true, true, true));
.Returns(new OrganizationMetadata(true, true, true, true, true, true));

var result = await sutProvider.Sut.GetMetadataAsync(organizationId);

Expand Down
Loading