Fix infinite loop happening if payment method unavailable with on invoices with lazy activation (#2914)

This commit is contained in:
Nicolas Dorier
2021-09-24 00:00:55 +09:00
committed by GitHub
parent 047222b3ee
commit 83b54b7be1
2 changed files with 10 additions and 5 deletions

View File

@@ -517,9 +517,11 @@ namespace BTCPayServer.Controllers
var paymentMethodDetails = paymentMethod.GetPaymentMethodDetails(); var paymentMethodDetails = paymentMethod.GetPaymentMethodDetails();
if (!paymentMethodDetails.Activated) if (!paymentMethodDetails.Activated)
{ {
await _InvoiceRepository.ActivateInvoicePaymentMethod(_EventAggregator, _NetworkProvider, if (await _InvoiceRepository.ActivateInvoicePaymentMethod(_EventAggregator, _NetworkProvider,
_paymentMethodHandlerDictionary, store, invoice, paymentMethod.GetId()); _paymentMethodHandlerDictionary, store, invoice, paymentMethod.GetId()))
return await GetInvoiceModel(invoiceId, paymentMethodId, lang); {
return await GetInvoiceModel(invoiceId, paymentMethodId, lang);
}
} }
var dto = invoice.EntityToDTO(); var dto = invoice.EntityToDTO();
var storeBlob = store.GetStoreBlob(); var storeBlob = store.GetStoreBlob();

View File

@@ -11,10 +11,11 @@ namespace BTCPayServer.Services.Invoices
public static class InvoiceExtensions public static class InvoiceExtensions
{ {
public static async Task ActivateInvoicePaymentMethod(this InvoiceRepository invoiceRepository, public static async Task<bool> ActivateInvoicePaymentMethod(this InvoiceRepository invoiceRepository,
EventAggregator eventAggregator, BTCPayNetworkProvider btcPayNetworkProvider, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary, EventAggregator eventAggregator, BTCPayNetworkProvider btcPayNetworkProvider, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
StoreData store,InvoiceEntity invoice, PaymentMethodId paymentMethodId) StoreData store,InvoiceEntity invoice, PaymentMethodId paymentMethodId)
{ {
bool success = false;
var eligibleMethodToActivate = invoice.GetPaymentMethod(paymentMethodId); var eligibleMethodToActivate = invoice.GetPaymentMethod(paymentMethodId);
if (!eligibleMethodToActivate.GetPaymentMethodDetails().Activated) if (!eligibleMethodToActivate.GetPaymentMethodDetails().Activated)
{ {
@@ -34,6 +35,8 @@ namespace BTCPayServer.Services.Invoices
eligibleMethodToActivate.SetPaymentMethodDetails(newDetails); eligibleMethodToActivate.SetPaymentMethodDetails(newDetails);
await invoiceRepository.UpdateInvoicePaymentMethod(invoice.Id, eligibleMethodToActivate); await invoiceRepository.UpdateInvoicePaymentMethod(invoice.Id, eligibleMethodToActivate);
eventAggregator.Publish(new InvoicePaymentMethodActivated(paymentMethodId, invoice)); eventAggregator.Publish(new InvoicePaymentMethodActivated(paymentMethodId, invoice));
eventAggregator.Publish(new InvoiceNeedUpdateEvent(invoice.Id));
success = true;
} }
catch (PaymentMethodUnavailableException ex) catch (PaymentMethodUnavailableException ex)
{ {
@@ -45,8 +48,8 @@ namespace BTCPayServer.Services.Invoices
} }
await invoiceRepository.AddInvoiceLogs(invoice.Id, logs); await invoiceRepository.AddInvoiceLogs(invoice.Id, logs);
eventAggregator.Publish(new InvoiceNeedUpdateEvent(invoice.Id));
} }
return success;
} }
} }
} }