Do not fire InvoiceExpired twice if invoice partially paid (Fix #3004)

This commit is contained in:
nicolas.dorier 2021-10-27 19:27:19 +09:00
parent 8a0660cbd6
commit 0b5d0349d4
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
3 changed files with 8 additions and 4 deletions

View File

@ -62,6 +62,10 @@ namespace BTCPayServer.Events
public string Name { get; set; }
public PaymentEntity Payment { get; set; }
/// <summary>
/// Only set for Expired event
/// </summary>
public bool PaidPartial { get; internal set; }
public override string ToString()
{

View File

@ -83,9 +83,10 @@ namespace BTCPayServer.HostedServices
context.MarkDirty();
context.UnaffectAddresses();
invoice.Status = InvoiceStatusLegacy.Expired;
context.Events.Add(new InvoiceEvent(invoice, InvoiceEvent.Expired));
var paidPartial = invoice.ExceptionStatus == InvoiceExceptionStatus.PaidPartial;
context.Events.Add(new InvoiceEvent(invoice, InvoiceEvent.Expired) { PaidPartial = paidPartial });
if (invoice.ExceptionStatus == InvoiceExceptionStatus.PaidPartial)
context.Events.Add(new InvoiceEvent(invoice, InvoiceEvent.ExpiredPaidPartial));
context.Events.Add(new InvoiceEvent(invoice, InvoiceEvent.ExpiredPaidPartial) { PaidPartial = paidPartial });
}
var allPaymentMethods = invoice.GetPaymentMethods();
var paymentMethod = GetNearestClearedPayment(allPaymentMethods, out var accounting);

View File

@ -216,10 +216,9 @@ namespace BTCPayServer.HostedServices
case InvoiceEventCode.Created:
return new WebhookInvoiceEvent(WebhookEventType.InvoiceCreated);
case InvoiceEventCode.Expired:
case InvoiceEventCode.ExpiredPaidPartial:
return new WebhookInvoiceExpiredEvent(WebhookEventType.InvoiceExpired)
{
PartiallyPaid = eventCode == InvoiceEventCode.ExpiredPaidPartial
PartiallyPaid = invoiceEvent.PaidPartial
};
case InvoiceEventCode.FailedToConfirm:
case InvoiceEventCode.MarkedInvalid: