1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 17: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

@ -0,0 +1,10 @@
using System;
namespace Bit.Core.Models.Table
{
public interface IRevisable
{
DateTime CreationDate { get; }
DateTime RevisionDate { get; }
}
}

View File

@ -0,0 +1,10 @@
namespace Bit.Core.Models.Table
{
public interface IStorable
{
long? Storage { get; set; }
short? MaxStorageGb { get; set; }
long StorageBytesRemaining();
long StorageBytesRemaining(short maxStorageGb);
}
}

View File

@ -0,0 +1,5 @@
namespace Bit.Core.Models.Table
{
public interface IStorableSubscriber : IStorable, ISubscriber
{ }
}

View File

@ -0,0 +1,10 @@
namespace Bit.Core.Models.Table
{
public interface ISubscriber
{
string StripeCustomerId { get; set; }
string StripeSubscriptionId { get; set; }
string BillingEmailAddress();
string BillingName();
}
}

View File

@ -4,7 +4,7 @@ using Bit.Core.Enums;
namespace Bit.Core.Models.Table
{
public class Organization : IDataObject<Guid>
public class Organization : IDataObject<Guid>, ISubscriber, IStorable, IStorableSubscriber, IRevisable
{
public Guid Id { get; set; }
public string Name { get; set; }
@ -32,6 +32,16 @@ namespace Bit.Core.Models.Table
}
}
public string BillingEmailAddress()
{
return BillingEmail;
}
public string BillingName()
{
return BusinessName;
}
public long StorageBytesRemaining()
{
if(!MaxStorageGb.HasValue)
@ -39,7 +49,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;

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;