mirror of
https://github.com/bitwarden/server.git
synced 2024-12-24 17:17:40 +01:00
license dates
This commit is contained in:
parent
b1443b4f94
commit
ee9ec680a9
@ -10,7 +10,6 @@ using Bit.Core.Services;
|
||||
using Bit.Core;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Api.Utilities;
|
||||
using Bit.Core.Models.Business;
|
||||
|
||||
@ -114,7 +113,9 @@ namespace Bit.Api.Controllers
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return new OrganizationLicense(organization, installationId, _licensingService);
|
||||
var paymentService = new StripePaymentService();
|
||||
var billingInfo = await paymentService.GetBillingAsync(organization);
|
||||
return new OrganizationLicense(organization, billingInfo, installationId, _licensingService);
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
|
@ -67,7 +67,8 @@ namespace Bit.Core.Models.Api
|
||||
Status = sub.Status;
|
||||
TrialStartDate = sub.TrialStartDate;
|
||||
TrialEndDate = sub.TrialEndDate;
|
||||
EndDate = sub.EndDate;
|
||||
PeriodStartDate = sub.PeriodStartDate;
|
||||
PeriodEndDate = sub.PeriodEndDate;
|
||||
CancelledDate = sub.CancelledDate;
|
||||
CancelAtEndDate = sub.CancelAtEndDate;
|
||||
Cancelled = sub.Cancelled;
|
||||
@ -79,7 +80,8 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public DateTime? TrialStartDate { get; set; }
|
||||
public DateTime? TrialEndDate { get; set; }
|
||||
public DateTime? EndDate { 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; }
|
||||
|
@ -95,7 +95,8 @@ namespace Bit.Core.Models.Business
|
||||
Status = sub.Status;
|
||||
TrialStartDate = sub.TrialStart;
|
||||
TrialEndDate = sub.TrialEnd;
|
||||
EndDate = sub.CurrentPeriodEnd;
|
||||
PeriodStartDate = sub.CurrentPeriodStart;
|
||||
PeriodEndDate = sub.CurrentPeriodEnd;
|
||||
CancelledDate = sub.CanceledAt;
|
||||
CancelAtEndDate = sub.CancelAtPeriodEnd;
|
||||
Cancelled = sub.Status == "cancelled";
|
||||
@ -122,7 +123,8 @@ namespace Bit.Core.Models.Business
|
||||
}
|
||||
}
|
||||
|
||||
EndDate = sub.BillingPeriodEndDate;
|
||||
PeriodStartDate = sub.BillingPeriodStartDate;
|
||||
PeriodEndDate = sub.BillingPeriodEndDate;
|
||||
|
||||
CancelAtEndDate = !sub.NeverExpires.GetValueOrDefault();
|
||||
Cancelled = sub.Status == SubscriptionStatus.CANCELED;
|
||||
@ -146,7 +148,9 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public DateTime? TrialStartDate { get; set; }
|
||||
public DateTime? TrialEndDate { get; set; }
|
||||
public DateTime? EndDate { get; set; }
|
||||
public DateTime? PeriodStartDate { get; set; }
|
||||
public DateTime? PeriodEndDate { get; set; }
|
||||
public TimeSpan? PeriodDuration => PeriodEndDate - PeriodStartDate;
|
||||
public DateTime? CancelledDate { get; set; }
|
||||
public bool CancelAtEndDate { get; set; }
|
||||
public string Status { get; set; }
|
||||
|
@ -13,8 +13,10 @@ namespace Bit.Core.Models.Business
|
||||
public OrganizationLicense()
|
||||
{ }
|
||||
|
||||
public OrganizationLicense(Organization org, Guid installationId, ILicensingService licenseService)
|
||||
public OrganizationLicense(Organization org, BillingInfo billingInfo, Guid installationId,
|
||||
ILicensingService licenseService)
|
||||
{
|
||||
Version = 1;
|
||||
LicenseKey = org.LicenseKey;
|
||||
InstallationId = installationId;
|
||||
Id = org.Id;
|
||||
@ -29,10 +31,41 @@ namespace Bit.Core.Models.Business
|
||||
UseTotp = org.UseTotp;
|
||||
MaxStorageGb = org.MaxStorageGb;
|
||||
SelfHost = org.SelfHost;
|
||||
Version = 1;
|
||||
Issued = DateTime.UtcNow;
|
||||
Expires = Issued.AddYears(1);
|
||||
|
||||
if(billingInfo?.Subscription == null)
|
||||
{
|
||||
Expires = Refresh = Issued.AddDays(7);
|
||||
Trial = true;
|
||||
}
|
||||
else if(billingInfo.Subscription.TrialEndDate.HasValue &&
|
||||
billingInfo.Subscription.TrialEndDate.Value < DateTime.UtcNow)
|
||||
{
|
||||
Expires = Refresh = billingInfo.Subscription.TrialEndDate.Value;
|
||||
Trial = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(org.ExpirationDate.HasValue && org.ExpirationDate.Value < DateTime.UtcNow)
|
||||
{
|
||||
// expired
|
||||
Expires = Refresh = org.ExpirationDate.Value;
|
||||
}
|
||||
else if(billingInfo?.Subscription?.PeriodDuration != null &&
|
||||
billingInfo.Subscription.PeriodDuration > TimeSpan.FromDays(180))
|
||||
{
|
||||
Refresh = DateTime.UtcNow.AddDays(30);
|
||||
Expires = billingInfo?.Subscription.PeriodEndDate.Value.AddDays(60);
|
||||
}
|
||||
else
|
||||
{
|
||||
Expires = org.ExpirationDate.HasValue ? org.ExpirationDate.Value.AddMonths(11) : Issued.AddYears(1);
|
||||
Refresh = DateTime.UtcNow - Expires > TimeSpan.FromDays(30) ? DateTime.UtcNow.AddDays(30) : Expires;
|
||||
}
|
||||
|
||||
Trial = false;
|
||||
}
|
||||
|
||||
Signature = Convert.ToBase64String(licenseService.SignLicense(this));
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@ namespace Bit.Core.Models.Business
|
||||
Premium = user.Premium;
|
||||
MaxStorageGb = user.MaxStorageGb;
|
||||
Issued = DateTime.UtcNow;
|
||||
Expires = billingInfo?.UpcomingInvoice?.Date;
|
||||
Expires = billingInfo?.UpcomingInvoice?.Date?.AddDays(7);
|
||||
Refresh = billingInfo?.UpcomingInvoice?.Date;
|
||||
Trial = (billingInfo?.Subscription?.TrialEndDate.HasValue ?? false) &&
|
||||
billingInfo.Subscription.TrialEndDate.Value > DateTime.UtcNow;
|
||||
Signature = Convert.ToBase64String(licenseService.SignLicense(this));
|
||||
|
Loading…
Reference in New Issue
Block a user