mirror of
https://github.com/bitwarden/server.git
synced 2026-02-19 07:13:17 +08:00
* Replace SubscriberQueries with SubscriberService * Replace OrganizationBillingQueries with OrganizationBillingService * Replace ProviderBillingQueries with ProviderBillingService, move to Commercial * Replace AssignSeatsToClientOrganizationCommand with ProviderBillingService, move to commercial * Replace ScaleSeatsCommand with ProviderBillingService and move to Commercial * Replace CancelSubscriptionCommand with SubscriberService * Replace CreateCustomerCommand with ProviderBillingService and move to Commercial * Replace StartSubscriptionCommand with ProviderBillingService and moved to Commercial * Replaced RemovePaymentMethodCommand with SubscriberService * Formatting * Used dotnet format this time * Changing ProviderBillingService to scoped * Found circular dependency' * One more time with feeling * Formatting * Fix error in remove org from provider * Missed test fix in conflit * [AC-1937] Server: Implement endpoint to retrieve provider payment information (#4107) * Move the gettax and paymentmethod from stripepayment class Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add the method to retrieve the tax and payment details Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add unit tests for the paymentInformation method Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add the endpoint to retrieve paymentinformation Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add unit tests to the SubscriberService Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Remove the getTaxInfoAsync update reference Signed-off-by: Cy Okeke <cokeke@bitwarden.com> --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com> --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com> Co-authored-by: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com>
66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Constants;
|
|
using Bit.Core.Billing.Models;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Utilities;
|
|
using Stripe;
|
|
|
|
namespace Bit.Core.Billing.Services.Implementations;
|
|
|
|
public class OrganizationBillingService(
|
|
IOrganizationRepository organizationRepository,
|
|
ISubscriberService subscriberService) : IOrganizationBillingService
|
|
{
|
|
public async Task<OrganizationMetadataDTO> GetMetadata(Guid organizationId)
|
|
{
|
|
var organization = await organizationRepository.GetByIdAsync(organizationId);
|
|
|
|
if (organization == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var customer = await subscriberService.GetCustomer(organization, new CustomerGetOptions
|
|
{
|
|
Expand = ["discount.coupon.applies_to"]
|
|
});
|
|
|
|
var subscription = await subscriberService.GetSubscription(organization);
|
|
|
|
if (customer == null || subscription == null)
|
|
{
|
|
return OrganizationMetadataDTO.Default();
|
|
}
|
|
|
|
var isOnSecretsManagerStandalone = IsOnSecretsManagerStandalone(organization, customer, subscription);
|
|
|
|
return new OrganizationMetadataDTO(isOnSecretsManagerStandalone);
|
|
}
|
|
|
|
private static bool IsOnSecretsManagerStandalone(
|
|
Organization organization,
|
|
Customer customer,
|
|
Subscription subscription)
|
|
{
|
|
var plan = StaticStore.GetPlan(organization.PlanType);
|
|
|
|
if (!plan.SupportsSecretsManager)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var hasCoupon = customer.Discount?.Coupon?.Id == StripeConstants.CouponIDs.SecretsManagerStandalone;
|
|
|
|
if (!hasCoupon)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var subscriptionProductIds = subscription.Items.Data.Select(item => item.Plan.ProductId);
|
|
|
|
var couponAppliesTo = customer.Discount?.Coupon?.AppliesTo?.Products;
|
|
|
|
return subscriptionProductIds.Intersect(couponAppliesTo ?? []).Any();
|
|
}
|
|
}
|