From 019c878c4ec844d695d42227b60ba2962bd1dff0 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sun, 23 Mar 2025 10:53:05 +0900 Subject: [PATCH] Add InvoiceEntity.NetSettled property --- BTCPayServer.Tests/FastTests.cs | 6 +++++- BTCPayServer/Services/Invoices/InvoiceEntity.cs | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/BTCPayServer.Tests/FastTests.cs b/BTCPayServer.Tests/FastTests.cs index 9e1c7ef9f..1bfd68a46 100644 --- a/BTCPayServer.Tests/FastTests.cs +++ b/BTCPayServer.Tests/FastTests.cs @@ -2252,17 +2252,21 @@ bc1qfzu57kgu5jthl934f9xrdzzx8mmemx7gn07tf0grnvz504j6kzusu2v0ku PaymentMethodId = btcId }); invoiceEntity.UpdateTotals(); + var prevNetSettled = invoiceEntity.NetSettled; + Assert.Equal(invoiceEntity.PaidAmount.Net, invoiceEntity.NetSettled); accounting = btc.Calculate(); invoiceEntity.Payments.Add( new PaymentEntity() { - Status = PaymentStatus.Settled, + Status = PaymentStatus.Processing, Currency = "BTC", Value = accounting.Due, PaymentMethodFee = 0.00000100m, PaymentMethodId = btcId }); invoiceEntity.UpdateTotals(); + Assert.NotEqual(invoiceEntity.PaidAmount.Net, invoiceEntity.NetSettled); + Assert.Equal(prevNetSettled, invoiceEntity.NetSettled); accounting = btc.Calculate(); Assert.Equal(0.0m, accounting.Due); Assert.Equal(0.0m, accounting.DueUncapped); diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index f6fae9432..9705e702c 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -416,6 +416,7 @@ namespace BTCPayServer.Services.Invoices { Currency = Currency }; + NetSettled = 0.0m; foreach (var payment in GetPayments(false)) { payment.Rate = GetInvoiceRate(payment.Currency); @@ -425,6 +426,8 @@ namespace BTCPayServer.Services.Invoices { PaidAmount.Gross += payment.InvoicePaidAmount.Gross; PaidAmount.Net += payment.InvoicePaidAmount.Net; + if (payment.Status == PaymentStatus.Settled) + NetSettled += payment.InvoicePaidAmount.Net; } } NetDue = Price - PaidAmount.Net; @@ -772,6 +775,12 @@ namespace BTCPayServer.Services.Invoices } [JsonIgnore] public Amounts PaidAmount { get; set; } + + /// + /// Same as of , but only counting payments in 'Settled' state + /// + [JsonIgnore] + public decimal NetSettled { get; private set; } } public enum InvoiceStatusLegacy