1
0
mirror of https://github.com/bitwarden/server synced 2025-12-14 15:23:42 +00:00

payment intent/method support for incomplete status

This commit is contained in:
Kyle Spearrin
2019-08-09 23:56:26 -04:00
parent efcf626999
commit 00e808d731
10 changed files with 173 additions and 39 deletions

View File

@@ -679,8 +679,8 @@ namespace Bit.Core.Services
return true;
}
public async Task SignUpPremiumAsync(User user, string paymentToken, PaymentMethodType paymentMethodType,
short additionalStorageGb, UserLicense license)
public async Task<Tuple<bool, string>> SignUpPremiumAsync(User user, string paymentToken,
PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license)
{
if(user.Premium)
{
@@ -692,6 +692,7 @@ namespace Bit.Core.Services
throw new BadRequestException("You can't subtract storage!");
}
string paymentIntentClientSecret = null;
IPaymentService paymentService = null;
if(_globalSettings.SelfHosted)
{
@@ -711,7 +712,8 @@ namespace Bit.Core.Services
}
else
{
await _paymentService.PurchasePremiumAsync(user, paymentMethodType, paymentToken, additionalStorageGb);
paymentIntentClientSecret = await _paymentService.PurchasePremiumAsync(user, paymentMethodType,
paymentToken, additionalStorageGb);
}
user.Premium = true;
@@ -739,6 +741,8 @@ namespace Bit.Core.Services
await paymentService.CancelAndRecoverChargesAsync(user);
throw;
}
return new Tuple<bool, string>(string.IsNullOrWhiteSpace(paymentIntentClientSecret),
paymentIntentClientSecret);
}
public async Task UpdateLicenseAsync(User user, UserLicense license)
@@ -816,6 +820,23 @@ namespace Bit.Core.Services
await _paymentService.ReinstateSubscriptionAsync(user);
}
public async Task EnablePremiumAsync(Guid userId, DateTime? expirationDate)
{
var user = await _userRepository.GetByIdAsync(userId);
await EnablePremiumAsync(user, expirationDate);
}
public async Task EnablePremiumAsync(User user, DateTime? expirationDate)
{
if(user != null && !user.Premium)
{
user.Premium = true;
user.PremiumExpirationDate = expirationDate;
user.RevisionDate = DateTime.UtcNow;
await _userRepository.ReplaceAsync(user);
}
}
public async Task DisablePremiumAsync(Guid userId, DateTime? expirationDate)
{
var user = await _userRepository.GetByIdAsync(userId);