mirror of
https://github.com/bitwarden/server
synced 2025-12-24 04:03:25 +00:00
* Add PlanSponsorshipType to static store * Add sponsorship type to token and creates sponsorship * PascalCase properties * Require sponsorship for remove * Create subscription sponsorship helper class * Handle Sponsored subscription changes * Add sponsorship id to subscription metadata * Make sponsoring references nullable This state indicates that a sponsorship has lapsed, but was not able to be reverted for billing reasons * WIP: Validate and remove subscriptions * Update sponsorships on organization and org user delete * Add friendly name to organization sponsorship
40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using Bit.Core.Models.Table;
|
|
|
|
namespace Bit.Core.Models.Business
|
|
{
|
|
public class SponsoredOrganizationSubscription
|
|
{
|
|
public const string OrganizationSponsorhipIdMetadataKey = "OrganizationSponsorshipId";
|
|
private readonly string _customerId;
|
|
private readonly Organization _org;
|
|
private readonly StaticStore.Plan _plan;
|
|
private readonly List<Stripe.TaxRate> _taxRates;
|
|
|
|
public SponsoredOrganizationSubscription(Organization org, Stripe.Subscription existingSubscription)
|
|
{
|
|
_org = org;
|
|
_customerId = org.GatewayCustomerId;
|
|
_plan = Utilities.StaticStore.GetPlan(org.PlanType);
|
|
_taxRates = existingSubscription.DefaultTaxRates;
|
|
}
|
|
|
|
public SponsorOrganizationSubscriptionOptions GetSponsorSubscriptionOptions(OrganizationSponsorship sponsorship,
|
|
int additionalSeats = 0, int additionalStorageGb = 0, bool premiumAccessAddon = false)
|
|
{
|
|
var sponsoredPlan = Utilities.StaticStore.GetSponsoredPlan(sponsorship.PlanSponsorshipType.Value);
|
|
|
|
var subCreateOptions = new SponsorOrganizationSubscriptionOptions(_customerId, _org, _plan,
|
|
sponsoredPlan, _taxRates, additionalSeats, additionalStorageGb, premiumAccessAddon);
|
|
|
|
subCreateOptions.Metadata.Add(OrganizationSponsorhipIdMetadataKey, sponsorship.Id.ToString());
|
|
return subCreateOptions;
|
|
}
|
|
|
|
public OrganizationUpgradeSubscriptionOptions RemoveOrganizationSubscriptionOptions(int additionalSeats = 0,
|
|
int additionalStorageGb = 0, bool premiumAccessAddon = false) =>
|
|
new OrganizationUpgradeSubscriptionOptions(_customerId, _org, _plan, _taxRates,
|
|
additionalSeats, additionalStorageGb, premiumAccessAddon);
|
|
}
|
|
}
|