1
0
mirror of https://github.com/bitwarden/server synced 2026-01-01 08:03:23 +00:00

[PM-27849] Check for sm-standalone on subscription (#6545)

* Fix coupon check

* Fixed in FF off scenario

* Run dotnet format
This commit is contained in:
Alex Morask
2025-11-11 16:01:48 -06:00
committed by GitHub
parent ea233580d2
commit 691047039b
4 changed files with 107 additions and 113 deletions

View File

@@ -22,11 +22,6 @@ public class GetOrganizationMetadataQuery(
{
public async Task<OrganizationMetadata?> Run(Organization organization)
{
if (organization == null)
{
return null;
}
if (globalSettings.SelfHosted)
{
return OrganizationMetadata.Default;
@@ -42,10 +37,12 @@ public class GetOrganizationMetadataQuery(
};
}
var customer = await subscriberService.GetCustomer(organization,
new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] });
var customer = await subscriberService.GetCustomer(organization);
var subscription = await subscriberService.GetSubscription(organization);
var subscription = await subscriberService.GetSubscription(organization, new SubscriptionGetOptions
{
Expand = ["discounts.coupon.applies_to"]
});
if (customer == null || subscription == null)
{
@@ -79,16 +76,17 @@ public class GetOrganizationMetadataQuery(
return false;
}
var hasCoupon = customer.Discount?.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone;
var coupon = subscription.Discounts?.FirstOrDefault(discount =>
discount.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone)?.Coupon;
if (!hasCoupon)
if (coupon == null)
{
return false;
}
var subscriptionProductIds = subscription.Items.Data.Select(item => item.Plan.ProductId);
var couponAppliesTo = customer.Discount?.Coupon?.AppliesTo?.Products;
var couponAppliesTo = coupon.AppliesTo?.Products;
return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any();
}

View File

@@ -79,10 +79,12 @@ public class OrganizationBillingService(
};
}
var customer = await subscriberService.GetCustomer(organization,
new CustomerGetOptions { Expand = ["discount.coupon.applies_to"] });
var customer = await subscriberService.GetCustomer(organization);
var subscription = await subscriberService.GetSubscription(organization);
var subscription = await subscriberService.GetSubscription(organization, new SubscriptionGetOptions
{
Expand = ["discounts.coupon.applies_to"]
});
if (customer == null || subscription == null)
{
@@ -542,16 +544,17 @@ public class OrganizationBillingService(
return false;
}
var hasCoupon = customer.Discount?.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone;
var coupon = subscription.Discounts?.FirstOrDefault(discount =>
discount.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone)?.Coupon;
if (!hasCoupon)
if (coupon == null)
{
return false;
}
var subscriptionProductIds = subscription.Items.Data.Select(item => item.Plan.ProductId);
var couponAppliesTo = customer.Discount?.Coupon?.AppliesTo?.Products;
var couponAppliesTo = coupon.AppliesTo?.Products;
return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any();
}