1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 07:43:54 +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

@@ -42,6 +42,7 @@ namespace Bit.Core.Services
private readonly ILicensingService _licenseService;
private readonly IEventService _eventService;
private readonly IApplicationCacheService _applicationCacheService;
private readonly IPaymentService _paymentService;
private readonly IDataProtector _organizationServiceDataProtector;
private readonly CurrentContext _currentContext;
private readonly GlobalSettings _globalSettings;
@@ -67,6 +68,7 @@ namespace Bit.Core.Services
IEventService eventService,
IApplicationCacheService applicationCacheService,
IDataProtectionProvider dataProtectionProvider,
IPaymentService paymentService,
CurrentContext currentContext,
GlobalSettings globalSettings)
: base(
@@ -94,6 +96,7 @@ namespace Bit.Core.Services
_licenseService = licenseService;
_eventService = eventService;
_applicationCacheService = applicationCacheService;
_paymentService = paymentService;
_organizationServiceDataProtector = dataProtectionProvider.CreateProtector(
"OrganizationServiceDataProtector");
_currentContext = currentContext;
@@ -717,7 +720,7 @@ namespace Bit.Core.Services
paymentMethodType = PaymentMethodType.PayPal;
}
await new StripePaymentService(_globalSettings).PurchasePremiumAsync(user, paymentMethodType,
await _paymentService.PurchasePremiumAsync(user, paymentMethodType,
paymentToken, additionalStorageGb);
}
else
@@ -792,9 +795,8 @@ namespace Bit.Core.Services
{
throw new BadRequestException("Not a premium user.");
}
var paymentService = user.GetPaymentService(_globalSettings);
await BillingHelpers.AdjustStorageAsync(paymentService, user, storageAdjustmentGb, StoragePlanId);
await BillingHelpers.AdjustStorageAsync(_paymentService, user, storageAdjustmentGb, StoragePlanId);
await SaveUserAsync(user);
}
@@ -806,7 +808,6 @@ namespace Bit.Core.Services
}
PaymentMethodType paymentMethodType;
var paymentService = new StripePaymentService(_globalSettings);
if(paymentToken.StartsWith("tok_"))
{
paymentMethodType = PaymentMethodType.Card;
@@ -816,7 +817,7 @@ namespace Bit.Core.Services
paymentMethodType = PaymentMethodType.PayPal;
}
var updated = await paymentService.UpdatePaymentMethodAsync(user, paymentMethodType, paymentToken);
var updated = await _paymentService.UpdatePaymentMethodAsync(user, paymentMethodType, paymentToken);
if(updated)
{
await SaveUserAsync(user);
@@ -825,20 +826,18 @@ namespace Bit.Core.Services
public async Task CancelPremiumAsync(User user, bool? endOfPeriod = null)
{
var paymentService = user.GetPaymentService(_globalSettings);
var eop = endOfPeriod.GetValueOrDefault(true);
if(!endOfPeriod.HasValue && user.PremiumExpirationDate.HasValue &&
user.PremiumExpirationDate.Value < DateTime.UtcNow)
{
eop = false;
}
await paymentService.CancelSubscriptionAsync(user, eop);
await _paymentService.CancelSubscriptionAsync(user, eop);
}
public async Task ReinstatePremiumAsync(User user)
{
var paymentService = user.GetPaymentService(_globalSettings);
await paymentService.ReinstateSubscriptionAsync(user);
await _paymentService.ReinstateSubscriptionAsync(user);
}
public async Task DisablePremiumAsync(Guid userId, DateTime? expirationDate)
@@ -878,8 +877,7 @@ namespace Bit.Core.Services
if(billingInfo == null && user.Gateway != null)
{
var paymentService = user.GetPaymentService(_globalSettings);
billingInfo = await paymentService.GetBillingAsync(user);
billingInfo = await _paymentService.GetBillingAsync(user);
}
return billingInfo == null ? new UserLicense(user, _licenseService) :