mirror of
https://github.com/bitwarden/server.git
synced 2025-04-26 07:12:20 -05:00
Only automatically set collection method for MSP (#5680)
This commit is contained in:
parent
cbb1168da8
commit
eaae4b69c7
@ -1,5 +1,7 @@
|
|||||||
using Bit.Billing.Constants;
|
using Bit.Billing.Constants;
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
|
using Bit.Core.AdminConsole.Enums.Provider;
|
||||||
|
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 Bit.Core.Services;
|
||||||
@ -15,19 +17,22 @@ public class PaymentMethodAttachedHandler : IPaymentMethodAttachedHandler
|
|||||||
private readonly IStripeFacade _stripeFacade;
|
private readonly IStripeFacade _stripeFacade;
|
||||||
private readonly IStripeEventUtilityService _stripeEventUtilityService;
|
private readonly IStripeEventUtilityService _stripeEventUtilityService;
|
||||||
private readonly IFeatureService _featureService;
|
private readonly IFeatureService _featureService;
|
||||||
|
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)
|
IFeatureService featureService,
|
||||||
|
IProviderRepository providerRepository)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_stripeEventService = stripeEventService;
|
_stripeEventService = stripeEventService;
|
||||||
_stripeFacade = stripeFacade;
|
_stripeFacade = stripeFacade;
|
||||||
_stripeEventUtilityService = stripeEventUtilityService;
|
_stripeEventUtilityService = stripeEventUtilityService;
|
||||||
_featureService = featureService;
|
_featureService = featureService;
|
||||||
|
_providerRepository = providerRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleAsync(Event parsedEvent)
|
public async Task HandleAsync(Event parsedEvent)
|
||||||
@ -68,7 +73,13 @@ public class PaymentMethodAttachedHandler : IPaymentMethodAttachedHandler
|
|||||||
* If we have an invoiced provider subscription where the customer hasn't been marked as invoice-approved,
|
* If we have an invoiced provider subscription where the customer hasn't been marked as invoice-approved,
|
||||||
* we need to try and set the default payment method and update the collection method to be "charge_automatically".
|
* we need to try and set the default payment method and update the collection method to be "charge_automatically".
|
||||||
*/
|
*/
|
||||||
if (invoicedProviderSubscription != null && !customer.ApprovedToPayByInvoice())
|
if (invoicedProviderSubscription != null &&
|
||||||
|
!customer.ApprovedToPayByInvoice() &&
|
||||||
|
Guid.TryParse(invoicedProviderSubscription.Metadata[StripeConstants.MetadataKeys.ProviderId], out var providerId))
|
||||||
|
{
|
||||||
|
var provider = await _providerRepository.GetByIdAsync(providerId);
|
||||||
|
|
||||||
|
if (provider is { Type: ProviderType.Msp })
|
||||||
{
|
{
|
||||||
if (customer.InvoiceSettings.DefaultPaymentMethodId != paymentMethod.Id)
|
if (customer.InvoiceSettings.DefaultPaymentMethodId != paymentMethod.Id)
|
||||||
{
|
{
|
||||||
@ -106,6 +117,7 @@ public class PaymentMethodAttachedHandler : IPaymentMethodAttachedHandler
|
|||||||
customer.Id);
|
customer.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var unpaidSubscriptions = subscriptions?.Data.Where(subscription =>
|
var unpaidSubscriptions = subscriptions?.Data.Where(subscription =>
|
||||||
subscription.Status == StripeConstants.SubscriptionStatus.Unpaid).ToList();
|
subscription.Status == StripeConstants.SubscriptionStatus.Unpaid).ToList();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user