diff --git a/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs b/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs index ebaf7b548..960cd53ea 100644 --- a/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs +++ b/src/Api/Billing/Models/Responses/OrganizationMetadataResponse.cs @@ -5,11 +5,13 @@ namespace Bit.Api.Billing.Models.Responses; public record OrganizationMetadataResponse( bool IsEligibleForSelfHost, bool IsManaged, - bool IsOnSecretsManagerStandalone) + bool IsOnSecretsManagerStandalone, + bool IsSubscriptionUnpaid) { public static OrganizationMetadataResponse From(OrganizationMetadata metadata) => new( metadata.IsEligibleForSelfHost, metadata.IsManaged, - metadata.IsOnSecretsManagerStandalone); + metadata.IsOnSecretsManagerStandalone, + metadata.IsSubscriptionUnpaid); } diff --git a/src/Core/Billing/Models/OrganizationMetadata.cs b/src/Core/Billing/Models/OrganizationMetadata.cs index 6b31b51d0..138fb6aef 100644 --- a/src/Core/Billing/Models/OrganizationMetadata.cs +++ b/src/Core/Billing/Models/OrganizationMetadata.cs @@ -3,4 +3,5 @@ public record OrganizationMetadata( bool IsEligibleForSelfHost, bool IsManaged, - bool IsOnSecretsManagerStandalone); + bool IsOnSecretsManagerStandalone, + bool IsSubscriptionUnpaid); diff --git a/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs b/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs index 5956e3d85..bdcf0fbf6 100644 --- a/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs +++ b/src/Core/Billing/Services/Implementations/OrganizationBillingService.cs @@ -62,18 +62,18 @@ public class OrganizationBillingService( return null; } - var customer = await subscriberService.GetCustomer(organization, new CustomerGetOptions - { - Expand = ["discount.coupon.applies_to"] - }); + var customer = await subscriberService.GetCustomer(organization, + new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] }); var subscription = await subscriberService.GetSubscription(organization); var isEligibleForSelfHost = IsEligibleForSelfHost(organization); var isManaged = organization.Status == OrganizationStatusType.Managed; var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription); + var isSubscriptionUnpaid = IsSubscriptionUnpaid(subscription); - return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone); + return new OrganizationMetadata(isEligibleForSelfHost, isManaged, isOnSecretsManagerStandalone, + isSubscriptionUnpaid); } public async Task UpdatePaymentMethod( @@ -376,5 +376,16 @@ public class OrganizationBillingService( return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any(); } + private static bool IsSubscriptionUnpaid(Subscription subscription) + { + if (subscription == null) + { + return false; + } + + return subscription.Status == "unpaid"; + } + + #endregion } diff --git a/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs b/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs index eadf7e97b..721685c28 100644 --- a/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs +++ b/test/Api.Test/Billing/Controllers/OrganizationBillingControllerTests.cs @@ -52,7 +52,7 @@ public class OrganizationBillingControllerTests { sutProvider.GetDependency().AccessMembersTab(organizationId).Returns(true); sutProvider.GetDependency().GetMetadata(organizationId) - .Returns(new OrganizationMetadata(true, true, true)); + .Returns(new OrganizationMetadata(true, true, true, true)); var result = await sutProvider.Sut.GetMetadataAsync(organizationId);