1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

APIs for premium. Billing helpers.

This commit is contained in:
Kyle Spearrin
2017-07-06 14:55:58 -04:00
parent 2afef85f85
commit d346ee5169
22 changed files with 789 additions and 313 deletions

View File

@ -7,7 +7,7 @@ using System.Linq;
namespace Bit.Core.Models.Table
{
public class User : IDataObject<Guid>
public class User : IDataObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable
{
private Dictionary<TwoFactorProviderType, TwoFactorProvider> _twoFactorProviders;
@ -30,6 +30,8 @@ namespace Bit.Core.Models.Table
public bool Premium { get; set; }
public long? Storage { get; set; }
public short? MaxStorageGb { get; set; }
public string StripeCustomerId { get; set; }
public string StripeSubscriptionId { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
@ -38,6 +40,16 @@ namespace Bit.Core.Models.Table
Id = CoreHelpers.GenerateComb();
}
public string BillingEmailAddress()
{
return Email;
}
public string BillingName()
{
return Name;
}
public Dictionary<TwoFactorProviderType, TwoFactorProvider> GetTwoFactorProviders()
{
if(string.IsNullOrWhiteSpace(TwoFactorProviders))
@ -110,7 +122,12 @@ namespace Bit.Core.Models.Table
return 0;
}
var maxStorageBytes = MaxStorageGb.Value * 1073741824L;
return StorageBytesRemaining(MaxStorageGb.Value);
}
public long StorageBytesRemaining(short maxStorageGb)
{
var maxStorageBytes = maxStorageGb * 1073741824L;
if(!Storage.HasValue)
{
return maxStorageBytes;