diff --git a/BTCPayServer.Tests/BTCPayServer.Tests.csproj b/BTCPayServer.Tests/BTCPayServer.Tests.csproj index da2677437..3cfebef71 100644 --- a/BTCPayServer.Tests/BTCPayServer.Tests.csproj +++ b/BTCPayServer.Tests/BTCPayServer.Tests.csproj @@ -23,7 +23,7 @@ - + all diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 9b3d5ec93..ff54b3490 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -386,6 +386,10 @@ namespace BTCPayServer.Tests await s.StartAsync(); s.RegisterNewUser(true); s.CreateNewStore(); + s.GoToInvoices(); + s.Driver.FindElement(By.Id("CreateNewInvoice")).Click(); + // Should give us an error message if we try to create an invoice before adding a wallet + Assert.Contains("To create an invoice, you need to", s.Driver.PageSource); s.AddDerivationScheme(); s.GoToInvoices(); s.CreateInvoice(); diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index ab59151c5..925593c00 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -883,13 +883,24 @@ namespace BTCPayServer.Controllers private SelectList GetPaymentMethodsSelectList() { - return new SelectList(_paymentMethodHandlerDictionary.Distinct().SelectMany(handler => - handler.GetSupportedPaymentMethods() - .Select(id => new SelectListItem(id.ToPrettyString(), id.ToString()))), + var store = GetCurrentStore(); + var excludeFilter = store.GetStoreBlob().GetExcludedPaymentMethods(); + + return new SelectList(store.GetSupportedPaymentMethods(_NetworkProvider) + .Where(s => !excludeFilter.Match(s.PaymentId)) + .Select(method => new SelectListItem(method.PaymentId.ToPrettyString(), method.PaymentId.ToString())), nameof(SelectListItem.Value), nameof(SelectListItem.Text)); } + private bool AnyPaymentMethodAvailable(StoreData store) + { + var storeBlob = store.GetStoreBlob(); + var excludeFilter = storeBlob.GetExcludedPaymentMethods(); + + return store.GetSupportedPaymentMethods(_NetworkProvider).Where(s => !excludeFilter.Match(s.PaymentId)).Any(); + } + [HttpGet("/stores/{storeId}/invoices/create")] [HttpGet("invoices/create")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] @@ -913,6 +924,17 @@ namespace BTCPayServer.Controllers var store = await _StoreRepository.FindStore(model.StoreId, GetUserId()); if (store == null) return NotFound(); + + if (!AnyPaymentMethodAvailable(store)) + { + TempData.SetStatusMessageModel(new StatusMessageModel + { + Severity = StatusMessageModel.StatusSeverity.Error, + Html = $"To create an invoice, you need to set up a wallet first", + AllowDismiss = false + }); + } + HttpContext.SetStoreData(store); } @@ -941,12 +963,12 @@ namespace BTCPayServer.Controllers return View(model); } - if (!store.GetSupportedPaymentMethods(_NetworkProvider).Any()) + if (!AnyPaymentMethodAvailable(store)) { TempData.SetStatusMessageModel(new StatusMessageModel { Severity = StatusMessageModel.StatusSeverity.Error, - Html = $"To create an invoice, you need to set up a wallet first", + Html = $"To create an invoice, you need to set up a wallet first", AllowDismiss = false }); return View(model); diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index 282eed2f3..656afc1b6 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -115,6 +115,12 @@ namespace BTCPayServer tempData.Peek(WellKnownTempData.ErrorMessage) ?? tempData.Peek("StatusMessageModel")) != null; } + + public static bool HasErrorMessage(this ITempDataDictionary tempData) + { + return GetStatusMessageModel(tempData)?.Severity == StatusMessageModel.StatusSeverity.Error; + } + public static PaymentMethodId GetpaymentMethodId(this InvoiceCryptoInfo info) { return new PaymentMethodId(info.CryptoCode, PaymentTypes.Parse(info.PaymentType));