mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Fix change state broken in the UI and update invoice's status in payment request to new convention (Fix #3265) (#3286)
This commit is contained in:
parent
cd91e48713
commit
5bbaa48b49
9 changed files with 48 additions and 26 deletions
|
@ -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")]
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<IActionResult> 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);
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||
get; set;
|
||||
} = new List<CryptoPayment>();
|
||||
|
||||
public string State
|
||||
public InvoiceState State
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
|
|
@ -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)})");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,24 +124,20 @@
|
|||
<td>
|
||||
@if (Model.CanMarkStatus)
|
||||
{
|
||||
<div class="dropdown">
|
||||
<div class="dropdown changeInvoiceStateToggle">
|
||||
<button class="btn btn-secondary btn-sm dropdown-toggle py-1 px-2" type="button" id="markStatusDropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@Model.State
|
||||
@if (Model.StatusException != InvoiceExceptionStatus.None)
|
||||
{
|
||||
@String.Format("({0})", Model.StatusException.ToString());
|
||||
}
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="markStatusDropdownMenuButton">
|
||||
@if (Model.CanMarkInvalid)
|
||||
{
|
||||
<a class="dropdown-item" href="#" data-id="@Model.Id" data-status="invalid" data-change-invoice-status-button>
|
||||
<a class="dropdown-item changeInvoiceState" href="#" data-id="@Model.Id" data-status="invalid" data-change-invoice-status-button>
|
||||
Mark as invalid <span class="fa fa-times"></span>
|
||||
</a>
|
||||
}
|
||||
@if (Model.CanMarkSettled)
|
||||
{
|
||||
<a class="dropdown-item" href="#" data-id="@Model.Id" data-status="settled" data-change-invoice-status-button>
|
||||
<a class="dropdown-item changeInvoiceState" href="#" data-id="@Model.Id" data-status="settled" data-change-invoice-status-button>
|
||||
Mark as settled <span class="fa fa-check-circle"></span>
|
||||
</a>
|
||||
}
|
||||
|
|
|
@ -381,13 +381,8 @@
|
|||
@if (invoice.CanMarkStatus)
|
||||
{
|
||||
<div id="pavpill_@invoice.InvoiceId" class="badge badge-@invoice.Status.Status.ToModernStatus().ToString().ToLower()">
|
||||
<span class="dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@invoice.Status.Status.ToModernStatus().ToString() @* @invoice.Status.ToString() *@
|
||||
@if (invoice.Status.ExceptionStatus != InvoiceExceptionStatus.None)
|
||||
{
|
||||
@String.Format("({0})", @invoice.Status.ExceptionStatus.ToString())
|
||||
;
|
||||
}
|
||||
<span class="dropdown-toggle changeInvoiceStateToggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
@invoice.Status.ToString()
|
||||
</span>
|
||||
<div class="dropdown-menu pull-right">
|
||||
@if (invoice.CanMarkInvalid)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@using BTCPayServer.Services.Invoices
|
||||
@using BTCPayServer.Services.Invoices
|
||||
@using BTCPayServer.Client.Models
|
||||
@using BTCPayServer.Abstractions.Contracts
|
||||
@model BTCPayServer.Models.PaymentRequestViewModels.ViewPaymentRequestViewModel
|
||||
|
|
|
@ -97,11 +97,10 @@ document.addEventListener("DOMContentLoaded",function (ev) {
|
|||
statusClass: function (state) {
|
||||
var [, status,, exceptionStatus] = state.match(/(\w*)\s?(\((\w*)\))?/) || [];
|
||||
switch (status) {
|
||||
case "confirmed":
|
||||
case "complete":
|
||||
case "paid":
|
||||
case "Settled":
|
||||
case "Processing":
|
||||
return "success";
|
||||
case "expired":
|
||||
case "Expired":
|
||||
switch (exceptionStatus) {
|
||||
case "paidLate":
|
||||
case "paidPartial":
|
||||
|
@ -110,7 +109,7 @@ document.addEventListener("DOMContentLoaded",function (ev) {
|
|||
default:
|
||||
return "danger";
|
||||
}
|
||||
case "invalid":
|
||||
case "Invalid":
|
||||
return "danger";
|
||||
default:
|
||||
return "warning";
|
||||
|
|
Loading…
Add table
Reference in a new issue