mirror of
https://github.com/bitwarden/server.git
synced 2025-05-28 23:04:50 -05:00
disable premium membership
This commit is contained in:
parent
65a7d0001e
commit
b7e8852250
@ -14,15 +14,18 @@ namespace Bit.Billing.Controllers
|
|||||||
private readonly BillingSettings _billingSettings;
|
private readonly BillingSettings _billingSettings;
|
||||||
private readonly IHostingEnvironment _hostingEnvironment;
|
private readonly IHostingEnvironment _hostingEnvironment;
|
||||||
private readonly IOrganizationService _organizationService;
|
private readonly IOrganizationService _organizationService;
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
public StripeController(
|
public StripeController(
|
||||||
IOptions<BillingSettings> billingSettings,
|
IOptions<BillingSettings> billingSettings,
|
||||||
IHostingEnvironment hostingEnvironment,
|
IHostingEnvironment hostingEnvironment,
|
||||||
IOrganizationService organizationService)
|
IOrganizationService organizationService,
|
||||||
|
IUserService userService)
|
||||||
{
|
{
|
||||||
_billingSettings = billingSettings?.Value;
|
_billingSettings = billingSettings?.Value;
|
||||||
_hostingEnvironment = hostingEnvironment;
|
_hostingEnvironment = hostingEnvironment;
|
||||||
_organizationService = organizationService;
|
_organizationService = organizationService;
|
||||||
|
_userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("webhook")]
|
[HttpPost("webhook")]
|
||||||
@ -48,10 +51,18 @@ namespace Bit.Billing.Controllers
|
|||||||
{
|
{
|
||||||
var subscription = Mapper<StripeSubscription>.MapFromJson(parsedEvent.Data.Object.ToString())
|
var subscription = Mapper<StripeSubscription>.MapFromJson(parsedEvent.Data.Object.ToString())
|
||||||
as StripeSubscription;
|
as StripeSubscription;
|
||||||
if(subscription?.Status == "canceled" && (subscription.Metadata?.ContainsKey("organizationId") ?? false))
|
if(subscription?.Status == "canceled")
|
||||||
{
|
{
|
||||||
var orgIdGuid = new Guid(subscription.Metadata["organizationId"]);
|
if(subscription.Metadata?.ContainsKey("organizationId") ?? false)
|
||||||
await _organizationService.DisableAsync(orgIdGuid);
|
{
|
||||||
|
var orgIdGuid = new Guid(subscription.Metadata["organizationId"]);
|
||||||
|
await _organizationService.DisableAsync(orgIdGuid);
|
||||||
|
}
|
||||||
|
else if(subscription.Metadata?.ContainsKey("userId") ?? false)
|
||||||
|
{
|
||||||
|
var userIdGuid = new Guid(subscription.Metadata["userId"]);
|
||||||
|
await _userService.DisablePremiumAsync(userIdGuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -43,5 +43,6 @@ namespace Bit.Core.Services
|
|||||||
Task ReplacePaymentMethodAsync(User user, string paymentToken);
|
Task ReplacePaymentMethodAsync(User user, string paymentToken);
|
||||||
Task CancelPremiumAsync(User user, bool endOfPeriod = false);
|
Task CancelPremiumAsync(User user, bool endOfPeriod = false);
|
||||||
Task ReinstatePremiumAsync(User user);
|
Task ReinstatePremiumAsync(User user);
|
||||||
|
Task DisablePremiumAsync(Guid userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -610,6 +610,17 @@ namespace Bit.Core.Services
|
|||||||
await BillingHelpers.ReinstateSubscriptionAsync(user);
|
await BillingHelpers.ReinstateSubscriptionAsync(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DisablePremiumAsync(Guid userId)
|
||||||
|
{
|
||||||
|
var user = await _userRepository.GetByIdAsync(userId);
|
||||||
|
if(user != null && user.Premium)
|
||||||
|
{
|
||||||
|
user.Premium = false;
|
||||||
|
user.RevisionDate = DateTime.UtcNow;
|
||||||
|
await _userRepository.ReplaceAsync(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<IdentityResult> UpdatePasswordHash(User user, string newPassword, bool validatePassword = true)
|
private async Task<IdentityResult> UpdatePasswordHash(User user, string newPassword, bool validatePassword = true)
|
||||||
{
|
{
|
||||||
if(validatePassword)
|
if(validatePassword)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user