From 5bbaa48b492556df32aaa8cd81b7e7ac9ea33794 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 11 Jan 2022 21:49:56 +0900 Subject: [PATCH] Fix change state broken in the UI and update invoice's status in payment request to new convention (Fix #3265) (#3286) --- BTCPayServer.Tests/SeleniumTests.cs | 31 +++++++++++++++++++ BTCPayServer.Tests/UnitTest1.cs | 2 +- .../Controllers/InvoiceController.UI.cs | 7 +++-- .../InvoicingModels/InvoiceDetailsModel.cs | 2 +- .../Services/Invoices/InvoiceEntity.cs | 2 +- BTCPayServer/Views/Invoice/Invoice.cshtml | 10 ++---- .../Views/Invoice/ListInvoices.cshtml | 9 ++---- .../PaymentRequest/ViewPaymentRequest.cshtml | 2 +- BTCPayServer/wwwroot/payment-request/app.js | 9 +++--- 9 files changed, 48 insertions(+), 26 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 3feaaf0d1..b7d1998c5 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -350,6 +350,37 @@ namespace BTCPayServer.Tests Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource); } } + [Fact(Timeout = TestTimeout)] + public async Task CanCreateInvoiceInUI() + { + using var s = CreateSeleniumTester(); + await s.StartAsync(); + s.RegisterNewUser(true); + s.CreateNewStore(); + s.AddDerivationScheme(); + s.GoToInvoices(); + s.CreateInvoice(); + s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); + TestUtils.Eventually(() => Assert.Contains("Invalid (marked)", s.Driver.PageSource)); + s.Driver.Navigate().Refresh(); + + s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); + TestUtils.Eventually(() => Assert.Contains("Settled (marked)", s.Driver.PageSource)); + + s.Driver.FindElement(By.ClassName("invoice-details-link")).Click(); + Assert.Contains("Settled (marked)", s.Driver.PageSource); + + s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); + TestUtils.Eventually(() => Assert.Contains("Invalid (marked)", s.Driver.PageSource)); + s.Driver.Navigate().Refresh(); + + s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); + TestUtils.Eventually(() => Assert.Contains("Settled (marked)", s.Driver.PageSource)); + } [Fact(Timeout = TestTimeout)] [Trait("Lightning", "Lightning")] diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 0c09ce224..89086ca3a 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -1985,7 +1985,7 @@ namespace BTCPayServer.Tests Assert.Contains($",orderId,{invoice.Id},", paidresult.Content); Assert.Contains($",On-Chain,BTC,0.0991,0.0001,5000.0", paidresult.Content); Assert.Contains($",USD,5.00", paidresult.Content); // Seems hacky but some plateform does not render this decimal the same - Assert.Contains("0,,\"Some \"\", description\",new (paidPartial),new,paidPartial", + Assert.Contains("0,,\"Some \"\", description\",New (paidPartial),new,paidPartial", paidresult.Content); }); } diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 32560e72d..5340b48d8 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -104,7 +104,7 @@ namespace BTCPayServer.Controllers StoreLink = Url.Action(nameof(StoresController.PaymentMethods), "Stores", new { storeId = store.Id }), PaymentRequestLink = Url.Action(nameof(PaymentRequestController.ViewPaymentRequest), "PaymentRequest", new { payReqId = invoice.Metadata.PaymentRequestId }), Id = invoice.Id, - State = invoiceState.Status.ToModernStatus().ToString(), + State = invoiceState, TransactionSpeed = invoice.SpeedPolicy == SpeedPolicy.HighSpeed ? "high" : invoice.SpeedPolicy == SpeedPolicy.MediumSpeed ? "medium" : invoice.SpeedPolicy == SpeedPolicy.LowMediumSpeed ? "low-medium" : @@ -946,6 +946,7 @@ namespace BTCPayServer.Controllers [HttpPost] [Route("invoices/{invoiceId}/changestate/{newState}")] + [Route("stores/{storeId}/invoices/{invoiceId}/changestate/{newState}")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [BitpayAPIConstraint(false)] public async Task ChangeInvoiceState(string invoiceId, string newState) @@ -964,12 +965,12 @@ namespace BTCPayServer.Controllers if (newState == "invalid") { await _InvoiceRepository.MarkInvoiceStatus(invoiceId, InvoiceStatus.Invalid); - model.StatusString = new InvoiceState("invalid", "marked").ToString(); + model.StatusString = new InvoiceState(InvoiceStatusLegacy.Invalid, InvoiceExceptionStatus.Marked).ToString(); } else if (newState == "settled") { await _InvoiceRepository.MarkInvoiceStatus(invoiceId, InvoiceStatus.Settled); - model.StatusString = new InvoiceState("settled", "marked").ToString(); + model.StatusString = new InvoiceState(InvoiceStatusLegacy.Complete, InvoiceExceptionStatus.Marked).ToString(); } return Json(model); diff --git a/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs b/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs index feee2161e..481ef3440 100644 --- a/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs +++ b/BTCPayServer/Models/InvoicingModels/InvoiceDetailsModel.cs @@ -65,7 +65,7 @@ namespace BTCPayServer.Models.InvoicingModels get; set; } = new List(); - public string State + public InvoiceState State { get; set; } diff --git a/BTCPayServer/Services/Invoices/InvoiceEntity.cs b/BTCPayServer/Services/Invoices/InvoiceEntity.cs index 3d842ec67..483eacfc1 100644 --- a/BTCPayServer/Services/Invoices/InvoiceEntity.cs +++ b/BTCPayServer/Services/Invoices/InvoiceEntity.cs @@ -862,7 +862,7 @@ namespace BTCPayServer.Services.Invoices } public override string ToString() { - return ToString(Status) + (ExceptionStatus == InvoiceExceptionStatus.None ? string.Empty : $" ({ToString(ExceptionStatus)})"); + return Status.ToModernStatus().ToString() + (ExceptionStatus == InvoiceExceptionStatus.None ? string.Empty : $" ({ToString(ExceptionStatus)})"); } } diff --git a/BTCPayServer/Views/Invoice/Invoice.cshtml b/BTCPayServer/Views/Invoice/Invoice.cshtml index 5bd214a9d..8c118b8f2 100644 --- a/BTCPayServer/Views/Invoice/Invoice.cshtml +++ b/BTCPayServer/Views/Invoice/Invoice.cshtml @@ -124,24 +124,20 @@ @if (Model.CanMarkStatus) { -