From 5190c25be06ac3ddf93ebfc4d7d59de5debe5131 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Fri, 4 Oct 2024 16:58:24 +0900 Subject: [PATCH] OnlyIfSupportAttribute should use PaymentMethodId (#6274) --- BTCPayServer/Filters/OnlyIfSupportAttribute.cs | 13 +++++++------ .../Monero/RPC/MoneroDaemonCallbackController.cs | 2 +- .../Altcoins/Monero/UI/MoneroLikeStoreController.cs | 2 +- .../Zcash/RPC/ZcashDaemonCallbackController.cs | 2 +- .../Altcoins/Zcash/UI/ZcashLikeStoreController.cs | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/BTCPayServer/Filters/OnlyIfSupportAttribute.cs b/BTCPayServer/Filters/OnlyIfSupportAttribute.cs index dba26b7b8..7ca67f4f9 100644 --- a/BTCPayServer/Filters/OnlyIfSupportAttribute.cs +++ b/BTCPayServer/Filters/OnlyIfSupportAttribute.cs @@ -1,5 +1,7 @@ using System; using System.Threading.Tasks; +using BTCPayServer.Payments; +using BTCPayServer.Services.Invoices; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; @@ -8,22 +10,21 @@ namespace BTCPayServer.Filters { public class OnlyIfSupportAttribute : Attribute, IAsyncActionFilter { - private readonly string _cryptoCode; + private readonly string _paymentMethodId; - public OnlyIfSupportAttribute(string cryptoCode) + public OnlyIfSupportAttribute(string paymentMethodId) { - _cryptoCode = cryptoCode; + _paymentMethodId = paymentMethodId; } public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { - var options = context.HttpContext.RequestServices.GetService(); - if (options.GetNetwork(_cryptoCode) == null) + var handlers = context.HttpContext.RequestServices.GetService(); + if (!handlers.Support(PaymentMethodId.Parse(_paymentMethodId))) { context.Result = new NotFoundResult(); return; } - await next(); } } diff --git a/BTCPayServer/Services/Altcoins/Monero/RPC/MoneroDaemonCallbackController.cs b/BTCPayServer/Services/Altcoins/Monero/RPC/MoneroDaemonCallbackController.cs index 9db2d24e3..3b2634d94 100644 --- a/BTCPayServer/Services/Altcoins/Monero/RPC/MoneroDaemonCallbackController.cs +++ b/BTCPayServer/Services/Altcoins/Monero/RPC/MoneroDaemonCallbackController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; namespace BTCPayServer.Services.Altcoins.Monero.RPC { [Route("[controller]")] - [OnlyIfSupportAttribute("XMR")] + [OnlyIfSupportAttribute("XMR-CHAIN")] public class MoneroLikeDaemonCallbackController : Controller { private readonly EventAggregator _eventAggregator; diff --git a/BTCPayServer/Services/Altcoins/Monero/UI/MoneroLikeStoreController.cs b/BTCPayServer/Services/Altcoins/Monero/UI/MoneroLikeStoreController.cs index 1d66d4fa3..ac21adce6 100644 --- a/BTCPayServer/Services/Altcoins/Monero/UI/MoneroLikeStoreController.cs +++ b/BTCPayServer/Services/Altcoins/Monero/UI/MoneroLikeStoreController.cs @@ -29,7 +29,7 @@ using Microsoft.AspNetCore.Mvc.Rendering; namespace BTCPayServer.Services.Altcoins.Monero.UI { [Route("stores/{storeId}/monerolike")] - [OnlyIfSupportAttribute("XMR")] + [OnlyIfSupportAttribute("XMR-CHAIN")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] diff --git a/BTCPayServer/Services/Altcoins/Zcash/RPC/ZcashDaemonCallbackController.cs b/BTCPayServer/Services/Altcoins/Zcash/RPC/ZcashDaemonCallbackController.cs index d191b9f3c..327952c54 100644 --- a/BTCPayServer/Services/Altcoins/Zcash/RPC/ZcashDaemonCallbackController.cs +++ b/BTCPayServer/Services/Altcoins/Zcash/RPC/ZcashDaemonCallbackController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; namespace BTCPayServer.Services.Altcoins.Zcash.RPC { [Route("[controller]")] - [OnlyIfSupportAttribute("ZEC")] + [OnlyIfSupportAttribute("ZEC-CHAIN")] public class ZcashLikeDaemonCallbackController : Controller { private readonly EventAggregator _eventAggregator; diff --git a/BTCPayServer/Services/Altcoins/Zcash/UI/ZcashLikeStoreController.cs b/BTCPayServer/Services/Altcoins/Zcash/UI/ZcashLikeStoreController.cs index eb628630e..2618edb67 100644 --- a/BTCPayServer/Services/Altcoins/Zcash/UI/ZcashLikeStoreController.cs +++ b/BTCPayServer/Services/Altcoins/Zcash/UI/ZcashLikeStoreController.cs @@ -30,7 +30,7 @@ using Microsoft.AspNetCore.Mvc.Rendering; namespace BTCPayServer.Services.Altcoins.Zcash.UI { [Route("stores/{storeId}/Zcashlike")] - [OnlyIfSupportAttribute("ZEC")] + [OnlyIfSupportAttribute("ZEC-CHAIN")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)] [Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]