1
0
mirror of https://github.com/bitwarden/server synced 2025-12-18 01:03:17 +00:00

inject stripepaymentservice

This commit is contained in:
Kyle Spearrin
2019-02-08 23:53:09 -05:00
parent a97a6216d7
commit d568b86e1e
12 changed files with 58 additions and 464 deletions

View File

@@ -7,6 +7,7 @@ using Bit.Core.Exceptions;
using System.Linq;
using Bit.Core.Models.Business;
using Bit.Core.Enums;
using Bit.Core.Repositories;
namespace Bit.Core.Services
{
@@ -15,9 +16,11 @@ namespace Bit.Core.Services
private const string PremiumPlanId = "premium-annually";
private const string StoragePlanId = "storage-gb-annually";
private readonly ITransactionRepository _transactionRepository;
private readonly Braintree.BraintreeGateway _btGateway;
public StripePaymentService(
ITransactionRepository transactionRepository,
GlobalSettings globalSettings)
{
_btGateway = new Braintree.BraintreeGateway
@@ -28,6 +31,7 @@ namespace Bit.Core.Services
PublicKey = globalSettings.Braintree.PublicKey,
PrivateKey = globalSettings.Braintree.PrivateKey
};
_transactionRepository = transactionRepository;
}
public async Task PurchaseOrganizationAsync(Organization org, PaymentMethodType paymentMethodType,
@@ -912,6 +916,22 @@ namespace Bit.Core.Services
public async Task<BillingInfo> GetBillingAsync(ISubscriber subscriber)
{
var billingInfo = new BillingInfo();
ICollection<Transaction> transactions = null;
if(subscriber is User)
{
transactions = await _transactionRepository.GetManyByUserIdAsync(subscriber.Id);
}
else if(subscriber is Organization)
{
transactions = await _transactionRepository.GetManyByOrganizationIdAsync(subscriber.Id);
}
if(transactions != null)
{
billingInfo.Transactions = transactions?.OrderByDescending(i => i.CreationDate)
.Select(t => new BillingInfo.BillingTransaction(t));
}
var customerService = new CustomerService();
var subscriptionService = new SubscriptionService();
var chargeService = new ChargeService();