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

billing fixes and added gateway to subscriber

This commit is contained in:
Kyle Spearrin
2017-07-28 14:24:07 -04:00
parent 082b53e133
commit cfc80f8d1e
19 changed files with 269 additions and 123 deletions

View File

@ -55,7 +55,7 @@ namespace Bit.Core.Models.Api
EndDate = sub.EndDate;
CancelledDate = sub.CancelledDate;
CancelAtEndDate = sub.CancelAtEndDate;
Cancelled = Cancelled;
Cancelled = sub.Cancelled;
if(sub.Items != null)
{
Items = sub.Items.Select(i => new BillingSubscriptionItem(i));

View File

@ -1,10 +1,15 @@
namespace Bit.Core.Models.Table
using Bit.Core.Enums;
using Bit.Core.Services;
namespace Bit.Core.Models.Table
{
public interface ISubscriber
{
string StripeCustomerId { get; set; }
string StripeSubscriptionId { get; set; }
GatewayType? Gateway { get; set; }
string GatewayCustomerId { get; set; }
string GatewaySubscriptionId { get; set; }
string BillingEmailAddress();
string BillingName();
IPaymentService GetPaymentService(GlobalSettings globalSettings);
}
}

View File

@ -1,6 +1,8 @@
using System;
using Bit.Core.Utilities;
using Bit.Core.Enums;
using Bit.Core.Services;
using Bit.Core.Exceptions;
namespace Bit.Core.Models.Table
{
@ -19,8 +21,9 @@ namespace Bit.Core.Models.Table
public bool UseTotp { get; set; }
public long? Storage { get; set; }
public short? MaxStorageGb { get; set; }
public string StripeCustomerId { get; set; }
public string StripeSubscriptionId { get; set; }
public GatewayType? Gateway { get; set; }
public string GatewayCustomerId { get; set; }
public string GatewaySubscriptionId { get; set; }
public bool Enabled { get; set; } = true;
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
@ -63,5 +66,28 @@ namespace Bit.Core.Models.Table
return maxStorageBytes - Storage.Value;
}
public IPaymentService GetPaymentService(GlobalSettings globalSettings)
{
if(Gateway == null)
{
throw new BadRequestException("No gateway.");
}
IPaymentService paymentService = null;
switch(Gateway)
{
case GatewayType.Stripe:
paymentService = new StripePaymentService();
break;
case GatewayType.Braintree:
paymentService = new BraintreePaymentService(globalSettings);
break;
default:
throw new NotSupportedException("Unsupported gateway.");
}
return paymentService;
}
}
}

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using Newtonsoft.Json;
using System.Linq;
using Bit.Core.Services;
using Bit.Core.Exceptions;
namespace Bit.Core.Models.Table
{
@ -31,8 +32,9 @@ 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 GatewayType? Gateway { get; set; }
public string GatewayCustomerId { get; set; }
public string GatewaySubscriptionId { get; set; }
public DateTime CreationDate { get; internal set; } = DateTime.UtcNow;
public DateTime RevisionDate { get; internal set; } = DateTime.UtcNow;
@ -139,14 +141,22 @@ namespace Bit.Core.Models.Table
public IPaymentService GetPaymentService(GlobalSettings globalSettings)
{
IPaymentService paymentService = null;
if(StripeSubscriptionId.StartsWith("sub_"))
if(Gateway == null)
{
paymentService = new StripePaymentService();
throw new BadRequestException("No gateway.");
}
else
IPaymentService paymentService = null;
switch(Gateway)
{
paymentService = new BraintreePaymentService(globalSettings);
case GatewayType.Stripe:
paymentService = new StripePaymentService();
break;
case GatewayType.Braintree:
paymentService = new BraintreePaymentService(globalSettings);
break;
default:
throw new NotSupportedException("Unsupported gateway.");
}
return paymentService;