mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 10:40:29 +01:00
43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using BTCPayServer.Data;
|
||
|
using BTCPayServer.Events;
|
||
|
using BTCPayServer.Services.Invoices;
|
||
|
using NBXplorer;
|
||
|
|
||
|
namespace BTCPayServer.HostedServices
|
||
|
{
|
||
|
public class InvoiceEventSaverService : EventHostedServiceBase
|
||
|
{
|
||
|
private readonly InvoiceRepository _invoiceRepository;
|
||
|
public InvoiceEventSaverService(EventAggregator eventAggregator, InvoiceRepository invoiceRepository) : base(
|
||
|
eventAggregator)
|
||
|
{
|
||
|
_invoiceRepository = invoiceRepository;
|
||
|
}
|
||
|
|
||
|
protected override void SubscribeToEvents()
|
||
|
{
|
||
|
Subscribe<InvoiceEvent>();
|
||
|
Subscribe<InvoiceDataChangedEvent>();
|
||
|
Subscribe<InvoiceStopWatchedEvent>();
|
||
|
Subscribe<InvoiceIPNEvent>();
|
||
|
}
|
||
|
|
||
|
protected override async Task ProcessEvent(object evt, CancellationToken cancellationToken)
|
||
|
{
|
||
|
var e = (IHasInvoiceId)evt;
|
||
|
var severity = InvoiceEventData.EventSeverity.Info;
|
||
|
if (evt is InvoiceIPNEvent ipn)
|
||
|
{
|
||
|
severity = string.IsNullOrEmpty(ipn.Error) ? InvoiceEventData.EventSeverity.Success
|
||
|
: InvoiceEventData.EventSeverity.Error;
|
||
|
}
|
||
|
await _invoiceRepository.AddInvoiceEvent(e.InvoiceId, e, severity);
|
||
|
}
|
||
|
}
|
||
|
}
|