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 #5228

Merged
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
38 changes: 37 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,37 @@

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 289 in src/Api/Billing/Controllers/OrganizationBillingController.cs

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

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

var organization = await organizationRepository.GetByIdAsync(organizationId);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L305 was not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

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

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

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

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationBillingController.cs#L311-L313

Added lines #L311 - L313 were not covered by tests

return TypedResults.Ok();
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L315 - L316 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
bool IsSubscriptionUnpaid,
bool HasSubscription,
bool HasOpenInvoice,
bool IsSubscriptionCanceled,

Check warning on line 12 in src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs#L12

Added line #L12 was not covered by tests
DateTime? InvoiceDueDate,
DateTime? InvoiceCreatedDate,
DateTime? SubPeriodEndDate)
Expand All @@ -21,6 +22,7 @@
metadata.IsSubscriptionUnpaid,
metadata.HasSubscription,
metadata.HasOpenInvoice,
metadata.IsSubscriptionCanceled,
metadata.InvoiceDueDate,
metadata.InvoiceCreatedDate,
metadata.SubPeriodEndDate);
Expand Down
1 change: 1 addition & 0 deletions src/Core/Billing/Models/OrganizationMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public record OrganizationMetadata(
bool IsSubscriptionUnpaid,
bool HasSubscription,
bool HasOpenInvoice,
bool IsSubscriptionCanceled,
DateTime? InvoiceDueDate,
DateTime? InvoiceCreatedDate,
DateTime? SubPeriodEndDate);
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
if (string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
{
return new OrganizationMetadata(isEligibleForSelfHost, isManaged, false,
false, false, false, null, null, null);
false, false, false, false, null, null, null);

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L72 was not covered by tests
}

var customer = await subscriberService.GetCustomer(organization,
Expand All @@ -79,6 +79,7 @@

var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription);
var isSubscriptionUnpaid = IsSubscriptionUnpaid(subscription);
var isSubscriptionCanceled = IsSubscriptionCanceled(subscription);
var hasSubscription = true;
var openInvoice = await HasOpenInvoiceAsync(subscription);
var hasOpenInvoice = openInvoice.HasOpenInvoice;
Expand All @@ -87,7 +88,7 @@
var subPeriodEndDate = subscription?.CurrentPeriodEnd;

return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone,
isSubscriptionUnpaid, hasSubscription, hasOpenInvoice, invoiceDueDate, invoiceCreatedDate, subPeriodEndDate);
isSubscriptionUnpaid, hasSubscription, hasOpenInvoice, isSubscriptionCanceled, invoiceDueDate, invoiceCreatedDate, subPeriodEndDate);
}

public async Task UpdatePaymentMethod(
Expand Down Expand Up @@ -437,5 +438,15 @@
? (true, invoice.Created, invoice.DueDate)
: (false, null, null);
}

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, true, null, null, null));
.Returns(new OrganizationMetadata(true, true, true, true, true, true, true, null, null, null));

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

Expand Down
Loading