From 0bb260bec937b868906675d7d654bbffc1959762 Mon Sep 17 00:00:00 2001 From: lepipele Date: Sun, 5 Nov 2017 21:15:52 -0600 Subject: [PATCH 1/2] Allowing user to invalidate paid invoice --- .../Controllers/InvoiceController.UI.cs | 10 +++ .../Services/Invoices/InvoiceRepository.cs | 12 ++++ .../Views/Invoice/ListInvoices.cshtml | 67 +++++++++++++++---- 3 files changed, 76 insertions(+), 13 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index a78f989a7..44f2f35ca 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -281,6 +281,16 @@ namespace BTCPayServer.Controllers }); } + [HttpPost] + [Route("invoices/invalidatepaid")] + [Authorize(AuthenticationSchemes = "Identity.Application")] + [BitpayAPIConstraint(false)] + public async Task InvalidatePaidInvoice(string invoiceId) + { + await _InvoiceRepository.UpdatePaidInvoiceToInvalid(invoiceId); + return RedirectToAction(nameof(ListInvoices)); + } + [TempData] public string StatusMessage { diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index e0f8dfa2f..57ee42e4f 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -251,6 +251,18 @@ namespace BTCPayServer.Services.Invoices } } + public async Task UpdatePaidInvoiceToInvalid(string invoiceId) + { + using (var context = _ContextFactory.CreateContext()) + { + var invoiceData = await context.FindAsync(invoiceId).ConfigureAwait(false); + if (invoiceData == null || invoiceData.Status != "paid") + return; + invoiceData.Status = "invalid"; + await context.SaveChangesAsync().ConfigureAwait(false); + } + } + public async Task GetInvoice(string storeId, string id, bool includeHistoricalAddresses = false) { using (var context = _ContextFactory.CreateContext()) diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 64111fba1..b1e2026e6 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -43,12 +43,28 @@ - @foreach(var invoice in Model.Invoices) + @foreach (var invoice in Model.Invoices) { @invoice.Date @invoice.InvoiceId - @invoice.Status + @if (invoice.Status == "paid") + { + + + + } + else + { + @invoice.Status + } @invoice.AmountCurrency Checkout - Details @@ -56,23 +72,48 @@ - @if(Model.Skip != 0) + @if (Model.Skip != 0) { << - + { + searchTerm = Model.SearchTerm, + skip = Math.Max(0, Model.Skip - Model.Count), + count = Model.Count, + })"><< - } >> + { + searchTerm = Model.SearchTerm, + skip = Model.Skip + Model.Count, + count = Model.Count, + })">>> + + + From f58fdafdcd29a394299bab8d8c950fdcc4b31080 Mon Sep 17 00:00:00 2001 From: lepipele Date: Mon, 6 Nov 2017 07:43:24 -0600 Subject: [PATCH 2/2] Simplifying check for invoiceData null and status --- BTCPayServer/Services/Invoices/InvoiceRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index 2aa4c343c..aa695e954 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -256,7 +256,7 @@ namespace BTCPayServer.Services.Invoices using (var context = _ContextFactory.CreateContext()) { var invoiceData = await context.FindAsync(invoiceId).ConfigureAwait(false); - if (invoiceData == null || invoiceData.Status != "paid") + if (invoiceData?.Status != "paid") return; invoiceData.Status = "invalid"; await context.SaveChangesAsync().ConfigureAwait(false);