mirror of
https://github.com/bitwarden/server
synced 2025-12-18 01:03:17 +00:00
[PM-24551] remove feature flag code for pm-199566-update-msp-to-charge-automatically (#6188)
* [PM-24551] remove feature flag code * undoing constructor refactors * reverting changes the refactor made
This commit is contained in:
@@ -7,7 +7,6 @@ using Bit.Admin.AdminConsole.Models;
|
|||||||
using Bit.Admin.Enums;
|
using Bit.Admin.Enums;
|
||||||
using Bit.Admin.Services;
|
using Bit.Admin.Services;
|
||||||
using Bit.Admin.Utilities;
|
using Bit.Admin.Utilities;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.AdminConsole.Entities.Provider;
|
using Bit.Core.AdminConsole.Entities.Provider;
|
||||||
using Bit.Core.AdminConsole.Enums.Provider;
|
using Bit.Core.AdminConsole.Enums.Provider;
|
||||||
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
|
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
|
||||||
@@ -39,28 +38,26 @@ namespace Bit.Admin.AdminConsole.Controllers;
|
|||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public class ProvidersController : Controller
|
public class ProvidersController : Controller
|
||||||
{
|
{
|
||||||
|
private readonly string _stripeUrl;
|
||||||
|
private readonly string _braintreeMerchantUrl;
|
||||||
|
private readonly string _braintreeMerchantId;
|
||||||
private readonly IOrganizationRepository _organizationRepository;
|
private readonly IOrganizationRepository _organizationRepository;
|
||||||
private readonly IResellerClientOrganizationSignUpCommand _resellerClientOrganizationSignUpCommand;
|
private readonly IResellerClientOrganizationSignUpCommand _resellerClientOrganizationSignUpCommand;
|
||||||
private readonly IProviderRepository _providerRepository;
|
private readonly IProviderRepository _providerRepository;
|
||||||
private readonly IProviderUserRepository _providerUserRepository;
|
private readonly IProviderUserRepository _providerUserRepository;
|
||||||
private readonly IProviderOrganizationRepository _providerOrganizationRepository;
|
private readonly IProviderOrganizationRepository _providerOrganizationRepository;
|
||||||
|
private readonly IProviderService _providerService;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
private readonly IApplicationCacheService _applicationCacheService;
|
private readonly IApplicationCacheService _applicationCacheService;
|
||||||
private readonly IProviderService _providerService;
|
|
||||||
private readonly ICreateProviderCommand _createProviderCommand;
|
private readonly ICreateProviderCommand _createProviderCommand;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
private readonly IProviderPlanRepository _providerPlanRepository;
|
private readonly IProviderPlanRepository _providerPlanRepository;
|
||||||
private readonly IProviderBillingService _providerBillingService;
|
private readonly IProviderBillingService _providerBillingService;
|
||||||
private readonly IPricingClient _pricingClient;
|
private readonly IPricingClient _pricingClient;
|
||||||
private readonly IStripeAdapter _stripeAdapter;
|
private readonly IStripeAdapter _stripeAdapter;
|
||||||
private readonly IAccessControlService _accessControlService;
|
private readonly IAccessControlService _accessControlService;
|
||||||
private readonly ISubscriberService _subscriberService;
|
private readonly ISubscriberService _subscriberService;
|
||||||
private readonly string _stripeUrl;
|
|
||||||
private readonly string _braintreeMerchantUrl;
|
|
||||||
private readonly string _braintreeMerchantId;
|
|
||||||
|
|
||||||
public ProvidersController(
|
public ProvidersController(IOrganizationRepository organizationRepository,
|
||||||
IOrganizationRepository organizationRepository,
|
|
||||||
IResellerClientOrganizationSignUpCommand resellerClientOrganizationSignUpCommand,
|
IResellerClientOrganizationSignUpCommand resellerClientOrganizationSignUpCommand,
|
||||||
IProviderRepository providerRepository,
|
IProviderRepository providerRepository,
|
||||||
IProviderUserRepository providerUserRepository,
|
IProviderUserRepository providerUserRepository,
|
||||||
@@ -69,7 +66,6 @@ public class ProvidersController : Controller
|
|||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
IApplicationCacheService applicationCacheService,
|
IApplicationCacheService applicationCacheService,
|
||||||
ICreateProviderCommand createProviderCommand,
|
ICreateProviderCommand createProviderCommand,
|
||||||
IFeatureService featureService,
|
|
||||||
IProviderPlanRepository providerPlanRepository,
|
IProviderPlanRepository providerPlanRepository,
|
||||||
IProviderBillingService providerBillingService,
|
IProviderBillingService providerBillingService,
|
||||||
IWebHostEnvironment webHostEnvironment,
|
IWebHostEnvironment webHostEnvironment,
|
||||||
@@ -87,15 +83,14 @@ public class ProvidersController : Controller
|
|||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
_applicationCacheService = applicationCacheService;
|
_applicationCacheService = applicationCacheService;
|
||||||
_createProviderCommand = createProviderCommand;
|
_createProviderCommand = createProviderCommand;
|
||||||
_featureService = featureService;
|
|
||||||
_providerPlanRepository = providerPlanRepository;
|
_providerPlanRepository = providerPlanRepository;
|
||||||
_providerBillingService = providerBillingService;
|
_providerBillingService = providerBillingService;
|
||||||
_pricingClient = pricingClient;
|
_pricingClient = pricingClient;
|
||||||
_stripeAdapter = stripeAdapter;
|
_stripeAdapter = stripeAdapter;
|
||||||
|
_accessControlService = accessControlService;
|
||||||
_stripeUrl = webHostEnvironment.GetStripeUrl();
|
_stripeUrl = webHostEnvironment.GetStripeUrl();
|
||||||
_braintreeMerchantUrl = webHostEnvironment.GetBraintreeMerchantUrl();
|
_braintreeMerchantUrl = webHostEnvironment.GetBraintreeMerchantUrl();
|
||||||
_braintreeMerchantId = globalSettings.Braintree.MerchantId;
|
_braintreeMerchantId = globalSettings.Braintree.MerchantId;
|
||||||
_accessControlService = accessControlService;
|
|
||||||
_subscriberService = subscriberService;
|
_subscriberService = subscriberService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,21 +339,17 @@ public class ProvidersController : Controller
|
|||||||
]);
|
]);
|
||||||
await _providerBillingService.UpdateSeatMinimums(updateMspSeatMinimumsCommand);
|
await _providerBillingService.UpdateSeatMinimums(updateMspSeatMinimumsCommand);
|
||||||
|
|
||||||
if (_featureService.IsEnabled(FeatureFlagKeys.PM199566_UpdateMSPToChargeAutomatically))
|
var customer = await _stripeAdapter.CustomerGetAsync(provider.GatewayCustomerId);
|
||||||
|
if (model.PayByInvoice != customer.ApprovedToPayByInvoice())
|
||||||
{
|
{
|
||||||
var customer = await _stripeAdapter.CustomerGetAsync(provider.GatewayCustomerId);
|
var approvedToPayByInvoice = model.PayByInvoice ? "1" : "0";
|
||||||
|
await _stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
||||||
if (model.PayByInvoice != customer.ApprovedToPayByInvoice())
|
|
||||||
{
|
{
|
||||||
var approvedToPayByInvoice = model.PayByInvoice ? "1" : "0";
|
Metadata = new Dictionary<string, string>
|
||||||
await _stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions
|
|
||||||
{
|
{
|
||||||
Metadata = new Dictionary<string, string>
|
[StripeConstants.MetadataKeys.InvoiceApproved] = approvedToPayByInvoice
|
||||||
{
|
}
|
||||||
[StripeConstants.MetadataKeys.InvoiceApproved] = approvedToPayByInvoice
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProviderType.BusinessUnit:
|
case ProviderType.BusinessUnit:
|
||||||
@@ -403,8 +394,7 @@ public class ProvidersController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
var providerPlans = await _providerPlanRepository.GetByProviderId(id);
|
var providerPlans = await _providerPlanRepository.GetByProviderId(id);
|
||||||
var payByInvoice = _featureService.IsEnabled(FeatureFlagKeys.PM199566_UpdateMSPToChargeAutomatically) &&
|
var payByInvoice = ((await _subscriberService.GetCustomer(provider))?.ApprovedToPayByInvoice() ?? false);
|
||||||
((await _subscriberService.GetCustomer(provider))?.ApprovedToPayByInvoice() ?? false);
|
|
||||||
|
|
||||||
return new ProviderEditModel(
|
return new ProviderEditModel(
|
||||||
provider, users, providerOrganizations,
|
provider, users, providerOrganizations,
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
@using Bit.Admin.Enums;
|
@inject IAccessControlService AccessControlService
|
||||||
@using Bit.Core
|
|
||||||
|
@using Bit.Admin.Enums
|
||||||
|
@using Bit.Admin.Services
|
||||||
@using Bit.Core.AdminConsole.Enums.Provider
|
@using Bit.Core.AdminConsole.Enums.Provider
|
||||||
@using Bit.Core.Billing.Enums
|
@using Bit.Core.Billing.Enums
|
||||||
@using Bit.Core.Billing.Extensions
|
@using Bit.Core.Billing.Extensions
|
||||||
@using Microsoft.AspNetCore.Mvc.TagHelpers
|
@using Bit.Core.Enums
|
||||||
@inject Bit.Admin.Services.IAccessControlService AccessControlService
|
|
||||||
@inject Bit.Core.Services.IFeatureService FeatureService
|
|
||||||
|
|
||||||
@model ProviderEditModel
|
@model ProviderEditModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Provider: " + Model.Provider.DisplayName();
|
ViewData["Title"] = "Provider: " + Model.Provider.DisplayName();
|
||||||
@@ -114,7 +113,7 @@
|
|||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label asp-for="Gateway" class="form-label"></label>
|
<label asp-for="Gateway" class="form-label"></label>
|
||||||
<select class="form-control" asp-for="Gateway" asp-items="Html.GetEnumSelectList<Bit.Core.Enums.GatewayType>()">
|
<select class="form-control" asp-for="Gateway" asp-items="Html.GetEnumSelectList<GatewayType>()">
|
||||||
<option value="">--</option>
|
<option value="">--</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -144,7 +143,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@if (FeatureService.IsEnabled(FeatureFlagKeys.PM199566_UpdateMSPToChargeAutomatically) && Model.Provider.Type == ProviderType.Msp && Model.Provider.IsBillable())
|
@if (Model.Provider.Type == ProviderType.Msp && Model.Provider.IsBillable())
|
||||||
{
|
{
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
|
|||||||
@@ -2,12 +2,10 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using Bit.Billing.Constants;
|
using Bit.Billing.Constants;
|
||||||
using Bit.Core;
|
|
||||||
using Bit.Core.AdminConsole.Enums.Provider;
|
using Bit.Core.AdminConsole.Enums.Provider;
|
||||||
using Bit.Core.AdminConsole.Repositories;
|
using Bit.Core.AdminConsole.Repositories;
|
||||||
using Bit.Core.Billing.Constants;
|
using Bit.Core.Billing.Constants;
|
||||||
using Bit.Core.Billing.Extensions;
|
using Bit.Core.Billing.Extensions;
|
||||||
using Bit.Core.Services;
|
|
||||||
using Stripe;
|
using Stripe;
|
||||||
using Event = Stripe.Event;
|
using Event = Stripe.Event;
|
||||||
|
|
||||||
@@ -19,41 +17,22 @@ public class PaymentMethodAttachedHandler : IPaymentMethodAttachedHandler
|
|||||||
private readonly IStripeEventService _stripeEventService;
|
private readonly IStripeEventService _stripeEventService;
|
||||||
private readonly IStripeFacade _stripeFacade;
|
private readonly IStripeFacade _stripeFacade;
|
||||||
private readonly IStripeEventUtilityService _stripeEventUtilityService;
|
private readonly IStripeEventUtilityService _stripeEventUtilityService;
|
||||||
private readonly IFeatureService _featureService;
|
|
||||||
private readonly IProviderRepository _providerRepository;
|
private readonly IProviderRepository _providerRepository;
|
||||||
|
|
||||||
public PaymentMethodAttachedHandler(
|
public PaymentMethodAttachedHandler(ILogger<PaymentMethodAttachedHandler> logger,
|
||||||
ILogger<PaymentMethodAttachedHandler> logger,
|
|
||||||
IStripeEventService stripeEventService,
|
IStripeEventService stripeEventService,
|
||||||
IStripeFacade stripeFacade,
|
IStripeFacade stripeFacade,
|
||||||
IStripeEventUtilityService stripeEventUtilityService,
|
IStripeEventUtilityService stripeEventUtilityService,
|
||||||
IFeatureService featureService,
|
|
||||||
IProviderRepository providerRepository)
|
IProviderRepository providerRepository)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_stripeEventService = stripeEventService;
|
_stripeEventService = stripeEventService;
|
||||||
_stripeFacade = stripeFacade;
|
_stripeFacade = stripeFacade;
|
||||||
_stripeEventUtilityService = stripeEventUtilityService;
|
_stripeEventUtilityService = stripeEventUtilityService;
|
||||||
_featureService = featureService;
|
|
||||||
_providerRepository = providerRepository;
|
_providerRepository = providerRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleAsync(Event parsedEvent)
|
public async Task HandleAsync(Event parsedEvent)
|
||||||
{
|
|
||||||
var updateMSPToChargeAutomatically =
|
|
||||||
_featureService.IsEnabled(FeatureFlagKeys.PM199566_UpdateMSPToChargeAutomatically);
|
|
||||||
|
|
||||||
if (updateMSPToChargeAutomatically)
|
|
||||||
{
|
|
||||||
await HandleVNextAsync(parsedEvent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await HandleVCurrentAsync(parsedEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleVNextAsync(Event parsedEvent)
|
|
||||||
{
|
{
|
||||||
var paymentMethod = await _stripeEventService.GetPaymentMethod(parsedEvent, true, ["customer.subscriptions.data.latest_invoice"]);
|
var paymentMethod = await _stripeEventService.GetPaymentMethod(parsedEvent, true, ["customer.subscriptions.data.latest_invoice"]);
|
||||||
|
|
||||||
@@ -136,42 +115,6 @@ public class PaymentMethodAttachedHandler : IPaymentMethodAttachedHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleVCurrentAsync(Event parsedEvent)
|
|
||||||
{
|
|
||||||
var paymentMethod = await _stripeEventService.GetPaymentMethod(parsedEvent);
|
|
||||||
if (paymentMethod is null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Attempted to handle the event payment_method.attached but paymentMethod was null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var subscriptionListOptions = new SubscriptionListOptions
|
|
||||||
{
|
|
||||||
Customer = paymentMethod.CustomerId,
|
|
||||||
Status = StripeSubscriptionStatus.Unpaid,
|
|
||||||
Expand = ["data.latest_invoice"]
|
|
||||||
};
|
|
||||||
|
|
||||||
StripeList<Subscription> unpaidSubscriptions;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
unpaidSubscriptions = await _stripeFacade.ListSubscriptions(subscriptionListOptions);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError(e,
|
|
||||||
"Attempted to get unpaid invoices for customer {CustomerId} but encountered an error while calling Stripe",
|
|
||||||
paymentMethod.CustomerId);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var unpaidSubscription in unpaidSubscriptions)
|
|
||||||
{
|
|
||||||
await AttemptToPayOpenSubscriptionAsync(unpaidSubscription);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task AttemptToPayOpenSubscriptionAsync(Subscription unpaidSubscription)
|
private async Task AttemptToPayOpenSubscriptionAsync(Subscription unpaidSubscription)
|
||||||
{
|
{
|
||||||
var latestInvoice = unpaidSubscription.LatestInvoice;
|
var latestInvoice = unpaidSubscription.LatestInvoice;
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ public static class FeatureFlagKeys
|
|||||||
public const string UsePricingService = "use-pricing-service";
|
public const string UsePricingService = "use-pricing-service";
|
||||||
public const string PM12276Breadcrumbing = "pm-12276-breadcrumbing-for-business-features";
|
public const string PM12276Breadcrumbing = "pm-12276-breadcrumbing-for-business-features";
|
||||||
public const string PM19422_AllowAutomaticTaxUpdates = "pm-19422-allow-automatic-tax-updates";
|
public const string PM19422_AllowAutomaticTaxUpdates = "pm-19422-allow-automatic-tax-updates";
|
||||||
public const string PM199566_UpdateMSPToChargeAutomatically = "pm-199566-update-msp-to-charge-automatically";
|
|
||||||
public const string UseOrganizationWarningsService = "use-organization-warnings-service";
|
public const string UseOrganizationWarningsService = "use-organization-warnings-service";
|
||||||
public const string PM21881_ManagePaymentDetailsOutsideCheckout = "pm-21881-manage-payment-details-outside-checkout";
|
public const string PM21881_ManagePaymentDetailsOutsideCheckout = "pm-21881-manage-payment-details-outside-checkout";
|
||||||
public const string PM21821_ProviderPortalTakeover = "pm-21821-provider-portal-takeover";
|
public const string PM21821_ProviderPortalTakeover = "pm-21821-provider-portal-takeover";
|
||||||
|
|||||||
Reference in New Issue
Block a user