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:
10
src/Core/Models/Table/IRevisable.cs
Normal file
10
src/Core/Models/Table/IRevisable.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Bit.Core.Models.Table
|
||||
{
|
||||
public interface IRevisable
|
||||
{
|
||||
DateTime CreationDate { get; }
|
||||
DateTime RevisionDate { get; }
|
||||
}
|
||||
}
|
10
src/Core/Models/Table/IStorable.cs
Normal file
10
src/Core/Models/Table/IStorable.cs
Normal 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);
|
||||
}
|
||||
}
|
5
src/Core/Models/Table/IStorableSubscriber.cs
Normal file
5
src/Core/Models/Table/IStorableSubscriber.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Bit.Core.Models.Table
|
||||
{
|
||||
public interface IStorableSubscriber : IStorable, ISubscriber
|
||||
{ }
|
||||
}
|
10
src/Core/Models/Table/ISubscriber.cs
Normal file
10
src/Core/Models/Table/ISubscriber.cs
Normal 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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user