mirror of
https://github.com/bitwarden/server.git
synced 2025-04-09 15:18:13 -05:00

* [AC-1423] Add AddonProduct and BitwardenProduct properties to BillingSubscriptionItem (#3037) * [AC-1423] Add AddonProduct and BitwardenProduct properties to BillingSubscriptionItem * [AC-1423] Add helper to StaticStore.cs to find a Plan by StripePlanId * [AC-1423] Use the helper method to set SubscriptionInfo.BitwardenProduct * Add SecretsManagerBilling feature flag to Constants * [AC 1409] Secrets Manager Subscription Stripe Integration (#3019) * [AC-1418] Add missing SecretsManagerPlan property to OrganizationResponseModel (#3055) * [AC 1460] Update Stripe Configuration (#3070) * [AC 1410] Secrets Manager subscription adjustment back-end changes (#3036) * Create UpgradeSecretsManagerSubscription command * [AC-1495] Extract UpgradePlanAsync into a command (#3081) * This is a pure lift & shift with no refactors * [AC-1503] Fix Stripe integration on organization upgrade (#3084) * Fix SM parameters not being passed to Stripe * [AC-1504] Allow SM max autoscale limits to be disabled (#3085) * [AC-1488] Changed SM Signup and Upgrade paths to set SmServiceAccounts to include the plan BaseServiceAccount (#3086) * [AC-1510] Enable access to Secrets Manager to Organization owner for new Subscription (#3089) * Revert changes to ReferenceEvent code (#3091) This will be done in AC-1481 * Add UsePasswordManager to sync data (#3114) * [AC-1522] Fix service account check on upgrading (#3111) * [AC-1521] Address checkmarx security feedback (#3124) * Reinstate target attribute but add noopener noreferrer * Update date on migration script --------- Co-authored-by: Shane Melton <smelton@bitwarden.com> Co-authored-by: Thomas Rittson <trittson@bitwarden.com> Co-authored-by: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Co-authored-by: cyprain-okeke <cokeke@bitwarden.com> Co-authored-by: Rui Tomé <108268980+r-tome@users.noreply.github.com> Co-authored-by: Conner Turnbull <cturnbull@bitwarden.com> Co-authored-by: Rui Tome <rtome@bitwarden.com>
111 lines
4.1 KiB
C#
111 lines
4.1 KiB
C#
using Bit.Core.Entities;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Models.Api;
|
|
using Bit.Core.Models.Business;
|
|
using Bit.Core.Utilities;
|
|
|
|
namespace Bit.Api.Models.Response;
|
|
|
|
public class SubscriptionResponseModel : ResponseModel
|
|
{
|
|
public SubscriptionResponseModel(User user, SubscriptionInfo subscription, UserLicense license)
|
|
: base("subscription")
|
|
{
|
|
Subscription = subscription.Subscription != null ? new BillingSubscription(subscription.Subscription) : null;
|
|
UpcomingInvoice = subscription.UpcomingInvoice != null ?
|
|
new BillingSubscriptionUpcomingInvoice(subscription.UpcomingInvoice) : null;
|
|
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
|
|
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
|
|
MaxStorageGb = user.MaxStorageGb;
|
|
License = license;
|
|
Expiration = License.Expires;
|
|
UsingInAppPurchase = subscription.UsingInAppPurchase;
|
|
}
|
|
|
|
public SubscriptionResponseModel(User user, UserLicense license = null)
|
|
: base("subscription")
|
|
{
|
|
StorageName = user.Storage.HasValue ? CoreHelpers.ReadableBytesSize(user.Storage.Value) : null;
|
|
StorageGb = user.Storage.HasValue ? Math.Round(user.Storage.Value / 1073741824D, 2) : 0; // 1 GB
|
|
MaxStorageGb = user.MaxStorageGb;
|
|
Expiration = user.PremiumExpirationDate;
|
|
|
|
if (license != null)
|
|
{
|
|
License = license;
|
|
}
|
|
}
|
|
|
|
public string StorageName { get; set; }
|
|
public double? StorageGb { get; set; }
|
|
public short? MaxStorageGb { get; set; }
|
|
public BillingSubscriptionUpcomingInvoice UpcomingInvoice { get; set; }
|
|
public BillingSubscription Subscription { get; set; }
|
|
public UserLicense License { get; set; }
|
|
public DateTime? Expiration { get; set; }
|
|
public bool UsingInAppPurchase { get; set; }
|
|
}
|
|
|
|
public class BillingSubscription
|
|
{
|
|
public BillingSubscription(SubscriptionInfo.BillingSubscription sub)
|
|
{
|
|
Status = sub.Status;
|
|
TrialStartDate = sub.TrialStartDate;
|
|
TrialEndDate = sub.TrialEndDate;
|
|
PeriodStartDate = sub.PeriodStartDate;
|
|
PeriodEndDate = sub.PeriodEndDate;
|
|
CancelledDate = sub.CancelledDate;
|
|
CancelAtEndDate = sub.CancelAtEndDate;
|
|
Cancelled = sub.Cancelled;
|
|
if (sub.Items != null)
|
|
{
|
|
Items = sub.Items.Select(i => new BillingSubscriptionItem(i));
|
|
}
|
|
}
|
|
|
|
public DateTime? TrialStartDate { get; set; }
|
|
public DateTime? TrialEndDate { get; set; }
|
|
public DateTime? PeriodStartDate { get; set; }
|
|
public DateTime? PeriodEndDate { get; set; }
|
|
public DateTime? CancelledDate { get; set; }
|
|
public bool CancelAtEndDate { get; set; }
|
|
public string Status { get; set; }
|
|
public bool Cancelled { get; set; }
|
|
public IEnumerable<BillingSubscriptionItem> Items { get; set; } = new List<BillingSubscriptionItem>();
|
|
|
|
public class BillingSubscriptionItem
|
|
{
|
|
public BillingSubscriptionItem(SubscriptionInfo.BillingSubscription.BillingSubscriptionItem item)
|
|
{
|
|
Name = item.Name;
|
|
Amount = item.Amount;
|
|
Interval = item.Interval;
|
|
Quantity = item.Quantity;
|
|
SponsoredSubscriptionItem = item.SponsoredSubscriptionItem;
|
|
AddonSubscriptionItem = item.AddonSubscriptionItem;
|
|
BitwardenProduct = item.BitwardenProduct;
|
|
}
|
|
|
|
public string Name { get; set; }
|
|
public decimal Amount { get; set; }
|
|
public int Quantity { get; set; }
|
|
public string Interval { get; set; }
|
|
public bool SponsoredSubscriptionItem { get; set; }
|
|
public bool AddonSubscriptionItem { get; set; }
|
|
public BitwardenProductType BitwardenProduct { get; set; }
|
|
}
|
|
}
|
|
|
|
public class BillingSubscriptionUpcomingInvoice
|
|
{
|
|
public BillingSubscriptionUpcomingInvoice(SubscriptionInfo.BillingUpcomingInvoice inv)
|
|
{
|
|
Amount = inv.Amount;
|
|
Date = inv.Date;
|
|
}
|
|
|
|
public decimal? Amount { get; set; }
|
|
public DateTime? Date { get; set; }
|
|
}
|