mirror of
https://github.com/bitwarden/server
synced 2025-12-30 15:14:02 +00:00
* Add endpoint to update a provider organization's seats for consolidated billing. * Fixed failing tests
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using Bit.Core.Billing.Models;
|
|
using Bit.Core.Utilities;
|
|
using Stripe;
|
|
|
|
namespace Bit.Api.Billing.Models;
|
|
|
|
public record ProviderSubscriptionDTO(
|
|
string Status,
|
|
DateTime CurrentPeriodEndDate,
|
|
decimal? DiscountPercentage,
|
|
IEnumerable<ProviderPlanDTO> Plans)
|
|
{
|
|
private const string _annualCadence = "Annual";
|
|
private const string _monthlyCadence = "Monthly";
|
|
|
|
public static ProviderSubscriptionDTO From(
|
|
IEnumerable<ConfiguredProviderPlan> providerPlans,
|
|
Subscription subscription)
|
|
{
|
|
var providerPlansDTO = providerPlans
|
|
.Select(providerPlan =>
|
|
{
|
|
var plan = StaticStore.GetPlan(providerPlan.PlanType);
|
|
var cost = (providerPlan.SeatMinimum + providerPlan.PurchasedSeats) * plan.PasswordManager.SeatPrice;
|
|
var cadence = plan.IsAnnual ? _annualCadence : _monthlyCadence;
|
|
return new ProviderPlanDTO(
|
|
plan.Name,
|
|
providerPlan.SeatMinimum,
|
|
providerPlan.PurchasedSeats,
|
|
providerPlan.AssignedSeats,
|
|
cost,
|
|
cadence);
|
|
});
|
|
|
|
return new ProviderSubscriptionDTO(
|
|
subscription.Status,
|
|
subscription.CurrentPeriodEnd,
|
|
subscription.Customer?.Discount?.Coupon?.PercentOff,
|
|
providerPlansDTO);
|
|
}
|
|
}
|
|
|
|
public record ProviderPlanDTO(
|
|
string PlanName,
|
|
int SeatMinimum,
|
|
int PurchasedSeats,
|
|
int AssignedSeats,
|
|
decimal Cost,
|
|
string Cadence);
|