mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Pass the whole Entity object to internal InvoiceEvent
This commit is contained in:
@@ -660,13 +660,13 @@ namespace BTCPayServer.Controllers
|
|||||||
if (newState == "invalid")
|
if (newState == "invalid")
|
||||||
{
|
{
|
||||||
await _InvoiceRepository.UpdatePaidInvoiceToInvalid(invoiceId);
|
await _InvoiceRepository.UpdatePaidInvoiceToInvalid(invoiceId);
|
||||||
_EventAggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1008, InvoiceEvent.MarkedInvalid));
|
_EventAggregator.Publish(new InvoiceEvent(invoice, 1008, InvoiceEvent.MarkedInvalid));
|
||||||
StatusMessage = "Invoice marked invalid";
|
StatusMessage = "Invoice marked invalid";
|
||||||
}
|
}
|
||||||
else if(newState == "complete")
|
else if(newState == "complete")
|
||||||
{
|
{
|
||||||
await _InvoiceRepository.UpdatePaidInvoiceToComplete(invoiceId);
|
await _InvoiceRepository.UpdatePaidInvoiceToComplete(invoiceId);
|
||||||
_EventAggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 2008, InvoiceEvent.MarkedCompleted));
|
_EventAggregator.Publish(new InvoiceEvent(invoice, 2008, InvoiceEvent.MarkedCompleted));
|
||||||
StatusMessage = "Invoice marked complete";
|
StatusMessage = "Invoice marked complete";
|
||||||
}
|
}
|
||||||
return RedirectToAction(nameof(ListInvoices));
|
return RedirectToAction(nameof(ListInvoices));
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace BTCPayServer.Controllers
|
|||||||
entity.PosData = invoice.PosData;
|
entity.PosData = invoice.PosData;
|
||||||
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity, logs, _NetworkProvider);
|
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity, logs, _NetworkProvider);
|
||||||
await fetchingAll;
|
await fetchingAll;
|
||||||
_EventAggregator.Publish(new Events.InvoiceEvent(entity.EntityToDTO(_NetworkProvider), 1001, InvoiceEvent.Created));
|
_EventAggregator.Publish(new Events.InvoiceEvent(entity, 1001, InvoiceEvent.Created));
|
||||||
var resp = entity.EntityToDTO(_NetworkProvider);
|
var resp = entity.EntityToDTO(_NetworkProvider);
|
||||||
return new DataWrapper<InvoiceResponse>(resp) { Facade = "pos/invoice" };
|
return new DataWrapper<InvoiceResponse>(resp) { Facade = "pos/invoice" };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ namespace BTCPayServer.Events
|
|||||||
public const string Confirmed= "invoice_confirmed";
|
public const string Confirmed= "invoice_confirmed";
|
||||||
public const string Completed= "invoice_completed";
|
public const string Completed= "invoice_completed";
|
||||||
|
|
||||||
public InvoiceEvent(Models.InvoiceResponse invoice, int code, string name)
|
public InvoiceEvent(InvoiceEntity invoice, int code, string name)
|
||||||
{
|
{
|
||||||
Invoice = invoice;
|
Invoice = invoice;
|
||||||
EventCode = code;
|
EventCode = code;
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Models.InvoiceResponse Invoice { get; set; }
|
public InvoiceEntity Invoice { get; set; }
|
||||||
public int EventCode { get; set; }
|
public int EventCode { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ namespace BTCPayServer.HostedServices
|
|||||||
context.MarkDirty();
|
context.MarkDirty();
|
||||||
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
||||||
|
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1004, InvoiceEvent.Expired));
|
|
||||||
invoice.Status = InvoiceStatus.Expired;
|
invoice.Status = InvoiceStatus.Expired;
|
||||||
|
context.Events.Add(new InvoiceEvent(invoice, 1004, InvoiceEvent.Expired));
|
||||||
if (invoice.ExceptionStatus == InvoiceExceptionStatus.PaidPartial)
|
if (invoice.ExceptionStatus == InvoiceExceptionStatus.PaidPartial)
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 2000, InvoiceEvent.ExpiredPaidPartial));
|
context.Events.Add(new InvoiceEvent(invoice, 2000, InvoiceEvent.ExpiredPaidPartial));
|
||||||
}
|
}
|
||||||
|
|
||||||
var payments = invoice.GetPayments().Where(p => p.Accounted).ToArray();
|
var payments = invoice.GetPayments().Where(p => p.Accounted).ToArray();
|
||||||
@@ -83,7 +83,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
if (invoice.Status == InvoiceStatus.New)
|
if (invoice.Status == InvoiceStatus.New)
|
||||||
{
|
{
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1003, InvoiceEvent.PaidInFull));
|
context.Events.Add(new InvoiceEvent(invoice, 1003, InvoiceEvent.PaidInFull));
|
||||||
invoice.Status = InvoiceStatus.Paid;
|
invoice.Status = InvoiceStatus.Paid;
|
||||||
invoice.ExceptionStatus = accounting.Paid > accounting.TotalDue ? InvoiceExceptionStatus.PaidOver : InvoiceExceptionStatus.None;
|
invoice.ExceptionStatus = accounting.Paid > accounting.TotalDue ? InvoiceExceptionStatus.PaidOver : InvoiceExceptionStatus.None;
|
||||||
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
||||||
@@ -92,7 +92,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
else if (invoice.Status == InvoiceStatus.Expired && invoice.ExceptionStatus != InvoiceExceptionStatus.PaidLate)
|
else if (invoice.Status == InvoiceStatus.Expired && invoice.ExceptionStatus != InvoiceExceptionStatus.PaidLate)
|
||||||
{
|
{
|
||||||
invoice.ExceptionStatus = InvoiceExceptionStatus.PaidLate;
|
invoice.ExceptionStatus = InvoiceExceptionStatus.PaidLate;
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1009, InvoiceEvent.PaidAfterExpiration));
|
context.Events.Add(new InvoiceEvent(invoice, 1009, InvoiceEvent.PaidAfterExpiration));
|
||||||
context.MarkDirty();
|
context.MarkDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,15 +138,15 @@ namespace BTCPayServer.HostedServices
|
|||||||
(confirmedAccounting.Paid < accounting.MinimumTotalDue))
|
(confirmedAccounting.Paid < accounting.MinimumTotalDue))
|
||||||
{
|
{
|
||||||
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1013, InvoiceEvent.FailedToConfirm));
|
context.Events.Add(new InvoiceEvent(invoice, 1013, InvoiceEvent.FailedToConfirm));
|
||||||
invoice.Status = InvoiceStatus.Invalid;
|
invoice.Status = InvoiceStatus.Invalid;
|
||||||
context.MarkDirty();
|
context.MarkDirty();
|
||||||
}
|
}
|
||||||
else if (confirmedAccounting.Paid >= accounting.MinimumTotalDue)
|
else if (confirmedAccounting.Paid >= accounting.MinimumTotalDue)
|
||||||
{
|
{
|
||||||
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
await _InvoiceRepository.UnaffectAddress(invoice.Id);
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1005, InvoiceEvent.Confirmed));
|
|
||||||
invoice.Status = InvoiceStatus.Confirmed;
|
invoice.Status = InvoiceStatus.Confirmed;
|
||||||
|
context.Events.Add(new InvoiceEvent(invoice, 1005, InvoiceEvent.Confirmed));
|
||||||
context.MarkDirty();
|
context.MarkDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
var completedAccounting = paymentMethod.Calculate(p => p.GetCryptoPaymentData().PaymentCompleted(p, network));
|
var completedAccounting = paymentMethod.Calculate(p => p.GetCryptoPaymentData().PaymentCompleted(p, network));
|
||||||
if (completedAccounting.Paid >= accounting.MinimumTotalDue)
|
if (completedAccounting.Paid >= accounting.MinimumTotalDue)
|
||||||
{
|
{
|
||||||
context.Events.Add(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1006, InvoiceEvent.Completed));
|
context.Events.Add(new InvoiceEvent(invoice, 1006, InvoiceEvent.Completed));
|
||||||
invoice.Status = InvoiceStatus.Complete;
|
invoice.Status = InvoiceStatus.Complete;
|
||||||
context.MarkDirty();
|
context.MarkDirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,10 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
private TaskCompletionSource<bool> _RunningTask;
|
private TaskCompletionSource<bool> _RunningTask;
|
||||||
private CancellationTokenSource _Cts;
|
private CancellationTokenSource _Cts;
|
||||||
BTCPayWalletProvider _Wallets;
|
BTCPayWalletProvider _Wallets;
|
||||||
BTCPayNetworkProvider _NetworkProvider;
|
|
||||||
|
|
||||||
public NBXplorerListener(ExplorerClientProvider explorerClients,
|
public NBXplorerListener(ExplorerClientProvider explorerClients,
|
||||||
BTCPayWalletProvider wallets,
|
BTCPayWalletProvider wallets,
|
||||||
InvoiceRepository invoiceRepository,
|
InvoiceRepository invoiceRepository,
|
||||||
BTCPayNetworkProvider networkProvider,
|
|
||||||
EventAggregator aggregator, Microsoft.Extensions.Hosting.IApplicationLifetime lifetime)
|
EventAggregator aggregator, Microsoft.Extensions.Hosting.IApplicationLifetime lifetime)
|
||||||
{
|
{
|
||||||
PollInterval = TimeSpan.FromMinutes(1.0);
|
PollInterval = TimeSpan.FromMinutes(1.0);
|
||||||
@@ -47,7 +45,6 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
_ExplorerClients = explorerClients;
|
_ExplorerClients = explorerClients;
|
||||||
_Aggregator = aggregator;
|
_Aggregator = aggregator;
|
||||||
_Lifetime = lifetime;
|
_Lifetime = lifetime;
|
||||||
_NetworkProvider = networkProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositeDisposable leases = new CompositeDisposable();
|
CompositeDisposable leases = new CompositeDisposable();
|
||||||
@@ -373,7 +370,7 @@ namespace BTCPayServer.Payments.Bitcoin
|
|||||||
invoice.SetPaymentMethod(paymentMethod);
|
invoice.SetPaymentMethod(paymentMethod);
|
||||||
}
|
}
|
||||||
wallet.InvalidateCache(strategy);
|
wallet.InvalidateCache(strategy);
|
||||||
_Aggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1002, InvoiceEvent.ReceivedPayment){Payment = payment});
|
_Aggregator.Publish(new InvoiceEvent(invoice, 1002, InvoiceEvent.ReceivedPayment){Payment = payment});
|
||||||
return invoice;
|
return invoice;
|
||||||
}
|
}
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ namespace BTCPayServer.Payments.Lightning
|
|||||||
{
|
{
|
||||||
var invoice = await _InvoiceRepository.GetInvoice(listenedInvoice.InvoiceId);
|
var invoice = await _InvoiceRepository.GetInvoice(listenedInvoice.InvoiceId);
|
||||||
if (invoice != null)
|
if (invoice != null)
|
||||||
_Aggregator.Publish(new InvoiceEvent(invoice.EntityToDTO(_NetworkProvider), 1002, InvoiceEvent.ReceivedPayment){Payment = payment});
|
_Aggregator.Publish(new InvoiceEvent(invoice, 1002, InvoiceEvent.ReceivedPayment){Payment = payment});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user