diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 5a258493b..4c1dbd2f9 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -93,6 +93,7 @@ namespace BTCPayServer.Controllers IncludeAddresses = true, IncludeEvents = true, IncludeArchived = true, + IncludeRefunds = true, })).FirstOrDefault(); if (invoice == null) return NotFound(); @@ -116,7 +117,9 @@ namespace BTCPayServer.Controllers ExpirationDate = invoice.ExpirationTime, MonitoringDate = invoice.MonitoringExpiration, Fiat = _CurrencyNameTable.DisplayFormatCurrency(invoice.Price, invoice.Currency), - TaxIncluded = _CurrencyNameTable.DisplayFormatCurrency(invoice.Metadata.TaxIncluded ?? 0.0m, invoice.Currency), + TaxIncluded = invoice.Metadata.TaxIncluded is null + ? null + : _CurrencyNameTable.DisplayFormatCurrency(invoice.Metadata.TaxIncluded ?? 0.0m, invoice.Currency), NotificationUrl = invoice.NotificationURL?.AbsoluteUri, RedirectUrl = invoice.RedirectURL?.AbsoluteUri, TypedMetadata = invoice.Metadata, @@ -125,6 +128,7 @@ namespace BTCPayServer.Controllers PosData = PosDataParser.ParsePosData(invoice.Metadata.PosData), Archived = invoice.Archived, CanRefund = CanRefund(invoiceState), + Refunds = invoice.Refunds, ShowCheckout = invoice.Status == InvoiceStatusLegacy.New, Deliveries = (await _InvoiceRepository.GetWebhookDeliveries(invoiceId)) .Select(c => new Models.StoreViewModels.DeliveryViewModel(c)) @@ -412,8 +416,8 @@ namespace BTCPayServer.Controllers { InvoiceId = new[] { invoiceId }, UserId = GetUserId(), - IncludeAddresses = true, - IncludeEvents = true, + IncludeAddresses = false, + IncludeEvents = false, IncludeArchived = true, })).FirstOrDefault(); if (invoice == null) diff --git a/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs b/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs index c980cfc30..a4337f55c 100644 --- a/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs +++ b/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using BTCPayServer.Client.Models; +using BTCPayServer.Data; using BTCPayServer.Payments; using BTCPayServer.Payments.Bitcoin; using BTCPayServer.Services.Invoices; @@ -131,5 +132,6 @@ namespace BTCPayServer.Models.InvoicingModels public bool CanMarkSettled { get; set; } public bool CanMarkInvalid { get; set; } public bool CanMarkStatus => CanMarkSettled || CanMarkInvalid; + public List Refunds { get; set; } } } diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index f393afd89..b1c8680cd 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -441,6 +441,8 @@ namespace BTCPayServer.Services.Invoices [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public InvoiceType Type { get; set; } + public List Refunds { get; set; } + public bool IsExpired() { return DateTimeOffset.UtcNow > ExpirationTime; diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index 179e4c7d7..c0ec2f0f5 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -579,6 +579,10 @@ namespace BTCPayServer.Services.Invoices { entity.Events = invoice.Events.OrderBy(c => c.Timestamp).ToList(); } + if (invoice.Refunds != null) + { + entity.Refunds = invoice.Refunds.OrderBy(c => c.PullPaymentData.StartDate).ToList(); + } if (!string.IsNullOrEmpty(entity.RefundMail) && string.IsNullOrEmpty(entity.Metadata.BuyerEmail)) { entity.Metadata.BuyerEmail = entity.RefundMail; @@ -715,6 +719,8 @@ namespace BTCPayServer.Services.Invoices query = query.Include(o => o.AddressInvoices); if (queryObject.IncludeEvents) query = query.Include(o => o.Events); + if (queryObject.IncludeRefunds) + query = query.Include(o => o.Refunds).ThenInclude(refundData => refundData.PullPaymentData); var data = await query.ToArrayAsync().ConfigureAwait(false); return data.Select(ToEntity).ToArray(); } @@ -825,5 +831,6 @@ namespace BTCPayServer.Services.Invoices public bool IncludeEvents { get; set; } public bool IncludeArchived { get; set; } = true; + public bool IncludeRefunds { get; set; } } } diff --git a/BTCPayServer/Views/UIInvoice/Invoice.cshtml b/BTCPayServer/Views/UIInvoice/Invoice.cshtml index 41199bd21..e309c0c78 100644 --- a/BTCPayServer/Views/UIInvoice/Invoice.cshtml +++ b/BTCPayServer/Views/UIInvoice/Invoice.cshtml @@ -75,7 +75,7 @@