2024-04-04 09:31:04 +02:00
|
|
|
using System;
|
2020-07-24 09:40:37 +02:00
|
|
|
using System.Collections.Generic;
|
2018-01-18 12:56:55 +01:00
|
|
|
using BTCPayServer.Services.Invoices;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Events
|
|
|
|
{
|
2020-11-06 14:23:10 +01:00
|
|
|
public enum InvoiceEventCode : int
|
|
|
|
{
|
|
|
|
Created = 1001,
|
|
|
|
ReceivedPayment = 1002,
|
2021-10-05 11:10:41 +02:00
|
|
|
PaymentSettled = 1014,
|
2020-11-06 14:23:10 +01:00
|
|
|
PaidInFull = 1003,
|
|
|
|
Expired = 1004,
|
|
|
|
Confirmed = 1005,
|
|
|
|
Completed = 1006,
|
|
|
|
MarkedInvalid = 1008,
|
|
|
|
FailedToConfirm = 1013,
|
|
|
|
PaidAfterExpiration = 1009,
|
|
|
|
ExpiredPaidPartial = 2000,
|
|
|
|
MarkedCompleted = 2008,
|
|
|
|
}
|
|
|
|
public class InvoiceEvent : IHasInvoiceId
|
2018-01-18 12:56:55 +01:00
|
|
|
{
|
2019-01-06 10:12:45 +01:00
|
|
|
public const string Created = "invoice_created";
|
|
|
|
public const string ReceivedPayment = "invoice_receivedPayment";
|
2021-10-05 11:10:41 +02:00
|
|
|
public const string PaymentSettled = "invoice_paymentSettled";
|
2019-01-06 10:12:45 +01:00
|
|
|
public const string MarkedCompleted = "invoice_markedComplete";
|
2020-06-28 10:55:27 +02:00
|
|
|
public const string MarkedInvalid = "invoice_markedInvalid";
|
|
|
|
public const string Expired = "invoice_expired";
|
|
|
|
public const string ExpiredPaidPartial = "invoice_expiredPaidPartial";
|
|
|
|
public const string PaidInFull = "invoice_paidInFull";
|
|
|
|
public const string PaidAfterExpiration = "invoice_paidAfterExpiration";
|
|
|
|
public const string FailedToConfirm = "invoice_failedToConfirm";
|
|
|
|
public const string Confirmed = "invoice_confirmed";
|
|
|
|
public const string Completed = "invoice_completed";
|
2020-11-06 14:23:10 +01:00
|
|
|
|
|
|
|
public string InvoiceId => Invoice.Id;
|
|
|
|
public static Dictionary<string, InvoiceEventCode> EventCodes = new Dictionary<string, InvoiceEventCode>()
|
2020-07-24 09:40:37 +02:00
|
|
|
{
|
2020-11-06 14:23:10 +01:00
|
|
|
{Created, InvoiceEventCode.Created},
|
|
|
|
{ReceivedPayment, InvoiceEventCode.ReceivedPayment},
|
2021-10-05 11:10:41 +02:00
|
|
|
{PaymentSettled, InvoiceEventCode.PaymentSettled},
|
2020-11-06 14:23:10 +01:00
|
|
|
{PaidInFull, InvoiceEventCode.PaidInFull},
|
|
|
|
{Expired, InvoiceEventCode.Expired},
|
2020-11-13 08:28:15 +01:00
|
|
|
{Confirmed, InvoiceEventCode.Confirmed},
|
2020-11-06 14:23:10 +01:00
|
|
|
{Completed, InvoiceEventCode.Completed},
|
|
|
|
{MarkedInvalid, InvoiceEventCode.MarkedInvalid},
|
|
|
|
{FailedToConfirm, InvoiceEventCode.FailedToConfirm},
|
|
|
|
{PaidAfterExpiration, InvoiceEventCode.PaidAfterExpiration},
|
|
|
|
{ExpiredPaidPartial, InvoiceEventCode.ExpiredPaidPartial},
|
|
|
|
{MarkedCompleted, InvoiceEventCode.MarkedCompleted},
|
2020-07-24 09:40:37 +02:00
|
|
|
};
|
2020-06-28 10:55:27 +02:00
|
|
|
|
2020-07-24 09:40:37 +02:00
|
|
|
public InvoiceEvent(InvoiceEntity invoice, string name)
|
2018-01-18 12:56:55 +01:00
|
|
|
{
|
2024-04-04 09:31:04 +02:00
|
|
|
if (invoice is null)
|
|
|
|
throw new ArgumentNullException(nameof(invoice));
|
2018-06-21 07:15:36 +02:00
|
|
|
Invoice = invoice;
|
2020-07-24 09:40:37 +02:00
|
|
|
EventCode = EventCodes[name];
|
2018-01-18 12:56:55 +01:00
|
|
|
Name = name;
|
|
|
|
}
|
|
|
|
|
2019-02-19 04:06:13 +01:00
|
|
|
public InvoiceEntity Invoice { get; set; }
|
2020-11-06 14:23:10 +01:00
|
|
|
public InvoiceEventCode EventCode { get; set; }
|
2018-01-18 12:56:55 +01:00
|
|
|
public string Name { get; set; }
|
|
|
|
|
2019-01-06 10:12:45 +01:00
|
|
|
public PaymentEntity Payment { get; set; }
|
2021-10-27 12:27:19 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Only set for Expired event
|
|
|
|
/// </summary>
|
|
|
|
public bool PaidPartial { get; internal set; }
|
2019-01-06 10:12:45 +01:00
|
|
|
|
2018-01-18 12:56:55 +01:00
|
|
|
public override string ToString()
|
|
|
|
{
|
2020-11-06 14:23:10 +01:00
|
|
|
return $"Invoice {Invoice.Id} new event: {Name} ({(int)EventCode})";
|
2018-01-18 12:56:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|