diff --git a/BTCPayServer/Events/InvoiceDataChangedEvent.cs b/BTCPayServer/Events/InvoiceDataChangedEvent.cs index e8339dbce..ea0fe971f 100644 --- a/BTCPayServer/Events/InvoiceDataChangedEvent.cs +++ b/BTCPayServer/Events/InvoiceDataChangedEvent.cs @@ -1,4 +1,4 @@ -using BTCPayServer.Services.Invoices; +using BTCPayServer.Services.Invoices; namespace BTCPayServer.Events { diff --git a/BTCPayServer/Events/InvoicePaymentMethodActivated.cs b/BTCPayServer/Events/InvoicePaymentMethodActivated.cs new file mode 100644 index 000000000..4ad82254f --- /dev/null +++ b/BTCPayServer/Events/InvoicePaymentMethodActivated.cs @@ -0,0 +1,24 @@ +using BTCPayServer.Payments; +using BTCPayServer.Services.Invoices; + +namespace BTCPayServer.Events +{ + public class InvoicePaymentMethodActivated : IHasInvoiceId + { + public PaymentMethodId PaymentMethodId { get; } + public InvoiceEntity InvoiceEntity { get; } + + public InvoicePaymentMethodActivated(PaymentMethodId paymentMethodId, InvoiceEntity invoiceEntity) + { + PaymentMethodId = paymentMethodId; + InvoiceEntity = invoiceEntity; + } + + public string InvoiceId => InvoiceEntity.Id; + + public override string ToString() + { + return $"Invoice {InvoiceId} activated payment method {PaymentMethodId}"; + } + } +} diff --git a/BTCPayServer/Payments/Lightning/LightningListener.cs b/BTCPayServer/Payments/Lightning/LightningListener.cs index b1c0626e4..496a142ad 100644 --- a/BTCPayServer/Payments/Lightning/LightningListener.cs +++ b/BTCPayServer/Payments/Lightning/LightningListener.cs @@ -168,6 +168,13 @@ namespace BTCPayServer.Payments.Lightning } })); + leases.Add(_Aggregator.Subscribe(async inv => + { + if (inv.PaymentMethodId.PaymentType == LightningPaymentType.Instance) + { + _CheckInvoices.Writer.TryWrite(inv.InvoiceId); + } + })); _CheckingInvoice = CheckingInvoice(_Cts.Token); _ListenPoller = new Timer(async s => { diff --git a/BTCPayServer/Services/Invoices/InvoiceExtensions.cs b/BTCPayServer/Services/Invoices/InvoiceExtensions.cs index 118540a66..e0cdf95c2 100644 --- a/BTCPayServer/Services/Invoices/InvoiceExtensions.cs +++ b/BTCPayServer/Services/Invoices/InvoiceExtensions.cs @@ -33,6 +33,7 @@ namespace BTCPayServer.Services.Invoices prepare); eligibleMethodToActivate.SetPaymentMethodDetails(newDetails); await invoiceRepository.UpdateInvoicePaymentMethod(invoice.Id, eligibleMethodToActivate); + eventAggregator.Publish(new InvoicePaymentMethodActivated(paymentMethodId, invoice)); } catch (PaymentMethodUnavailableException ex) {