mirror of
https://github.com/bitwarden/server
synced 2026-01-04 01:23:25 +00:00
[AC-1904] Implement endpoint to retrieve Provider subscription (#3921)
* Refactor Core.Billing prior to adding new logic * Add ProviderBillingQueries.GetSubscriptionData * Add ProviderBillingController.GetSubscriptionAsync
This commit is contained in:
47
src/Api/Billing/Models/ProviderSubscriptionDTO.cs
Normal file
47
src/Api/Billing/Models/ProviderSubscriptionDTO.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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,
|
||||
cost,
|
||||
cadence);
|
||||
});
|
||||
|
||||
return new ProviderSubscriptionDTO(
|
||||
subscription.Status,
|
||||
subscription.CurrentPeriodEnd,
|
||||
subscription.Customer?.Discount?.Coupon?.PercentOff,
|
||||
providerPlansDTO);
|
||||
}
|
||||
}
|
||||
|
||||
public record ProviderPlanDTO(
|
||||
string PlanName,
|
||||
int SeatMinimum,
|
||||
int PurchasedSeats,
|
||||
decimal Cost,
|
||||
string Cadence);
|
||||
Reference in New Issue
Block a user