btcpayserver/BTCPayServer/Events/InvoiceEvent.cs

79 lines
3.0 KiB
C#
Raw Normal View History

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
{
public enum InvoiceEventCode : int
{
Created = 1001,
ReceivedPayment = 1002,
PaymentSettled = 1014,
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";
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";
public string InvoiceId => Invoice.Id;
public static Dictionary<string, InvoiceEventCode> EventCodes = new Dictionary<string, InvoiceEventCode>()
2020-07-24 09:40:37 +02:00
{
{Created, InvoiceEventCode.Created},
{ReceivedPayment, InvoiceEventCode.ReceivedPayment},
{PaymentSettled, InvoiceEventCode.PaymentSettled},
{PaidInFull, InvoiceEventCode.PaidInFull},
{Expired, InvoiceEventCode.Expired},
2020-11-13 08:28:15 +01:00
{Confirmed, InvoiceEventCode.Confirmed},
{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
{
if (invoice is null)
throw new ArgumentNullException(nameof(invoice));
Invoice = invoice;
2020-07-24 09:40:37 +02:00
EventCode = EventCodes[name];
2018-01-18 12:56:55 +01:00
Name = name;
}
public InvoiceEntity Invoice { get; set; }
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; }
/// <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()
{
return $"Invoice {Invoice.Id} new event: {Name} ({(int)EventCode})";
2018-01-18 12:56:55 +01:00
}
}
}