[UI] Do not show unabled payment methods in invoice creation (#6272)

This commit is contained in:
Nicolas Dorier
2024-10-03 21:34:09 +09:00
committed by GitHub
parent 413a9b4269
commit 2f2b4094f6
4 changed files with 15 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ using BTCPayServer.Client;
using BTCPayServer.Data;
using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Invoices;
using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
@@ -24,6 +25,7 @@ namespace BTCPayServer.Controllers
{
public UIAppsController(
UserManager<ApplicationUser> userManager,
PaymentMethodHandlerDictionary handlers,
BTCPayNetworkProvider networkProvider,
StoreRepository storeRepository,
IFileService fileService,
@@ -31,6 +33,7 @@ namespace BTCPayServer.Controllers
IHtmlHelper html)
{
_userManager = userManager;
_handlers = handlers;
_networkProvider = networkProvider;
_storeRepository = storeRepository;
_fileService = fileService;
@@ -39,6 +42,7 @@ namespace BTCPayServer.Controllers
}
private readonly UserManager<ApplicationUser> _userManager;
private readonly PaymentMethodHandlerDictionary _handlers;
private readonly BTCPayNetworkProvider _networkProvider;
private readonly StoreRepository _storeRepository;
private readonly IFileService _fileService;
@@ -140,7 +144,7 @@ namespace BTCPayServer.Controllers
{
return NotFound();
}
if (!store.AnyPaymentMethodAvailable())
if (!store.AnyPaymentMethodAvailable(_handlers))
{
TempData.SetStatusMessageModel(new StatusMessageModel
{

View File

@@ -1177,7 +1177,7 @@ namespace BTCPayServer.Controllers
if (store == null)
return NotFound();
if (!store.AnyPaymentMethodAvailable())
if (!store.AnyPaymentMethodAvailable(_handlers))
{
return NoPaymentMethodResult(store.Id);
}
@@ -1200,7 +1200,7 @@ namespace BTCPayServer.Controllers
public async Task<IActionResult> CreateInvoice(CreateInvoiceModel model, CancellationToken cancellationToken)
{
var store = HttpContext.GetStoreData();
if (!store.AnyPaymentMethodAvailable())
if (!store.AnyPaymentMethodAvailable(_handlers))
{
return NoPaymentMethodResult(store.Id);
}
@@ -1370,9 +1370,7 @@ namespace BTCPayServer.Controllers
private SelectList GetPaymentMethodsSelectList(StoreData store)
{
var excludeFilter = store.GetStoreBlob().GetExcludedPaymentMethods();
return new SelectList(store.GetPaymentMethodConfigs()
.Where(s => !excludeFilter.Match(s.Key))
return new SelectList(store.GetPaymentMethodConfigs(_handlers, true)
.Select(method => new SelectListItem(method.Key.ToString(), method.Key.ToString())),
nameof(SelectListItem.Value),
nameof(SelectListItem.Text));

View File

@@ -33,6 +33,7 @@ namespace BTCPayServer.Controllers
public class UIPaymentRequestController : Controller
{
private readonly UIInvoiceController _InvoiceController;
private readonly PaymentMethodHandlerDictionary _handlers;
private readonly UserManager<ApplicationUser> _UserManager;
private readonly PaymentRequestRepository _PaymentRequestRepository;
private readonly PaymentRequestService _PaymentRequestService;
@@ -49,6 +50,7 @@ namespace BTCPayServer.Controllers
public UIPaymentRequestController(
UIInvoiceController invoiceController,
PaymentMethodHandlerDictionary handlers,
UserManager<ApplicationUser> userManager,
PaymentRequestRepository paymentRequestRepository,
PaymentRequestService paymentRequestService,
@@ -63,6 +65,7 @@ namespace BTCPayServer.Controllers
BTCPayNetworkProvider networkProvider)
{
_InvoiceController = invoiceController;
_handlers = handlers;
_UserManager = userManager;
_PaymentRequestRepository = paymentRequestRepository;
_PaymentRequestService = paymentRequestService;
@@ -124,7 +127,7 @@ namespace BTCPayServer.Controllers
{
return NotFound();
}
if (!store.AnyPaymentMethodAvailable())
if (!store.AnyPaymentMethodAvailable(_handlers))
{
return NoPaymentMethodResult(storeId);
}
@@ -159,7 +162,7 @@ namespace BTCPayServer.Controllers
{
return NotFound();
}
if (!store.AnyPaymentMethodAvailable())
if (!store.AnyPaymentMethodAvailable(_handlers))
{
return NoPaymentMethodResult(store.Id);
}

View File

@@ -59,9 +59,9 @@ namespace BTCPayServer.Data
return result;
}
public static bool AnyPaymentMethodAvailable(this StoreData storeData)
public static bool AnyPaymentMethodAvailable(this StoreData storeData, PaymentMethodHandlerDictionary handlers)
{
return storeData.GetPaymentMethodConfigs(true).Any();
return storeData.GetPaymentMethodConfigs(handlers, true).Any();
}
public static bool SetStoreBlob(this StoreData storeData, StoreBlob storeBlob)