From d8698181f473e666b0057a090d492e06492195ee Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Mon, 24 Apr 2023 19:26:56 +0900 Subject: [PATCH] Remove LNURLStandardInvoiceEnabled --- .../Models/LNURLPayPaymentMethodBaseData.cs | 1 - .../Models/LNURLPayPaymentMethodData.cs | 3 +- BTCPayServer.Tests/Checkoutv2Tests.cs | 2 - BTCPayServer.Tests/SeleniumTests.cs | 38 +++----- BTCPayServer.Tests/UnitTest1.cs | 1 - ...ldStoreLNURLPayPaymentMethodsController.cs | 7 +- .../Controllers/UIInvoiceController.UI.cs | 96 ++++++++++--------- BTCPayServer/Controllers/UILNURLController.cs | 30 +++++- .../UIStoresController.LightningLike.cs | 8 +- .../Models/InvoicingModels/PaymentModel.cs | 1 + .../LightningSettingsViewModel.cs | 3 - .../LNURLPay/LNURLPayPaymentHandler.cs | 6 -- .../LNURLPaySupportedPaymentMethod.cs | 2 - .../Payments/LNURLPay/PaymentTypes.LNURL.cs | 1 - BTCPayServer/Payments/PaymentMethodId.cs | 3 +- .../Views/UIInvoice/Checkout-Body.cshtml | 8 +- .../Views/UIInvoice/CheckoutNoScript.cshtml | 7 +- .../Views/UIInvoice/CheckoutV2.cshtml | 5 +- .../Views/UIStores/LightningSettings.cshtml | 10 -- ...template.stores-payment-methods.lnurl.json | 4 - 20 files changed, 111 insertions(+), 125 deletions(-) diff --git a/BTCPayServer.Client/Models/LNURLPayPaymentMethodBaseData.cs b/BTCPayServer.Client/Models/LNURLPayPaymentMethodBaseData.cs index 9e37f94d8..4dcc9beaf 100644 --- a/BTCPayServer.Client/Models/LNURLPayPaymentMethodBaseData.cs +++ b/BTCPayServer.Client/Models/LNURLPayPaymentMethodBaseData.cs @@ -3,7 +3,6 @@ namespace BTCPayServer.Client.Models public class LNURLPayPaymentMethodBaseData { public bool UseBech32Scheme { get; set; } - public bool EnableForStandardInvoices { get; set; } public bool LUD12Enabled { get; set; } public LNURLPayPaymentMethodBaseData() diff --git a/BTCPayServer.Client/Models/LNURLPayPaymentMethodData.cs b/BTCPayServer.Client/Models/LNURLPayPaymentMethodData.cs index 23d665952..82d89897a 100644 --- a/BTCPayServer.Client/Models/LNURLPayPaymentMethodData.cs +++ b/BTCPayServer.Client/Models/LNURLPayPaymentMethodData.cs @@ -16,12 +16,11 @@ namespace BTCPayServer.Client.Models { } - public LNURLPayPaymentMethodData(string cryptoCode, bool enabled, bool useBech32Scheme, bool enableForStandardInvoices) + public LNURLPayPaymentMethodData(string cryptoCode, bool enabled, bool useBech32Scheme) { Enabled = enabled; CryptoCode = cryptoCode; UseBech32Scheme = useBech32Scheme; - EnableForStandardInvoices = enableForStandardInvoices; } } } diff --git a/BTCPayServer.Tests/Checkoutv2Tests.cs b/BTCPayServer.Tests/Checkoutv2Tests.cs index ac09e627c..f63b0ded6 100644 --- a/BTCPayServer.Tests/Checkoutv2Tests.cs +++ b/BTCPayServer.Tests/Checkoutv2Tests.cs @@ -49,7 +49,6 @@ namespace BTCPayServer.Tests s.GoToHome(); s.GoToLightningSettings(); s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true); - s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), true); s.Driver.FindElement(By.Id("save")).Click(); Assert.Contains("BTC Lightning settings successfully updated", s.FindAlertMessage().Text); @@ -296,7 +295,6 @@ namespace BTCPayServer.Tests s.GoToHome(); s.GoToLightningSettings(); Assert.True(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected); - Assert.True(s.Driver.FindElement(By.Id("LNURLStandardInvoiceEnabled")).Selected); // BIP21 with top-up invoice invoiceId = s.CreateInvoice(amount: null); diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 3e08ad7b0..5eebde309 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -11,8 +11,10 @@ using System.Threading.Tasks; using BTCPayServer.Abstractions.Models; using BTCPayServer.Client; using BTCPayServer.Client.Models; +using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Lightning; +using BTCPayServer.Models.InvoicingModels; using BTCPayServer.Payments; using BTCPayServer.Services; using BTCPayServer.Services.Invoices; @@ -2088,22 +2090,23 @@ namespace BTCPayServer.Tests }); // Standard invoice test s.GoToStore(storeId); - s.GoToLightningSettings(); - s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), true); - SudoForceSaveLightningSettingsRightNowAndFast(s, cryptoCode); i = s.CreateInvoice(storeId, 0.0000001m, cryptoCode); s.GoToInvoiceCheckout(i); - s.Driver.FindElement(By.ClassName("payment__currencies")).Click(); - // BOLT11 is also available for standard invoices - Assert.Equal(2, s.Driver.FindElements(By.CssSelector(".vex.vex-theme-btcpay .vex-content .vexmenu li.vexmenuitem")).Count); - s.Driver.FindElement(By.CssSelector(".vex.vex-theme-btcpay .vex-content .vexmenu li.vexmenuitem")).Click(); + s.Driver.FindElement(By.ClassName("payment__currencies_noborder")).Click(); + // BOLT11 is also displayed for standard invoice (not LNURL, even if it is available) s.Driver.FindElement(By.Id("copy-tab")).Click(); - lnurl = s.Driver.FindElement(By.CssSelector("input.checkoutTextbox")).GetAttribute("value"); - parsed = LNURL.LNURL.Parse(lnurl, out tag); - fetchedReuqest = Assert.IsType(await LNURL.LNURL.FetchInformation(parsed, new HttpClient())); + var bolt11 = s.Driver.FindElement(By.CssSelector("input.checkoutTextbox")).GetAttribute("value"); + var bolt11Parsed = Lightning.BOLT11PaymentRequest.Parse(bolt11, s.Server.ExplorerNode.Network); + var invoiceId = s.Driver.Url.Split('/').Last(); + using (var resp = await s.Server.PayTester.HttpClient.GetAsync("BTC/lnurl/pay/i/" + invoiceId)) + { + resp.EnsureSuccessStatusCode(); + fetchedReuqest = JsonConvert.DeserializeObject(await resp.Content.ReadAsStringAsync()); + } Assert.Equal(0.0000001m, fetchedReuqest.MaxSendable.ToDecimal(LightMoneyUnit.BTC)); Assert.Equal(0.0000001m, fetchedReuqest.MinSendable.ToDecimal(LightMoneyUnit.BTC)); + await Assert.ThrowsAsync(async () => { await fetchedReuqest.SendRequest(new LightMoney(0.0000002m, LightMoneyUnit.BTC), @@ -2125,13 +2128,6 @@ namespace BTCPayServer.Tests Assert.Equal(new LightMoney(0.0000001m, LightMoneyUnit.BTC), lnurlResponse2.GetPaymentRequest(network).MinimumAmount); s.GoToHome(); - s.GoToLightningSettings(); - // LNURL is enabled and settings are expanded - Assert.True(s.Driver.FindElement(By.Id("LNURLEnabled")).Selected); - Assert.Contains("show", s.Driver.FindElement(By.Id("LNURLSettings")).GetAttribute("class")); - s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), false); - s.Driver.FindElement(By.Id("save")).Click(); - Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text); i = s.CreateInvoice(storeId, 0.000001m, cryptoCode); s.GoToInvoiceCheckout(i); @@ -2145,22 +2141,17 @@ namespace BTCPayServer.Tests s.GoToHome(); s.GoToLightningSettings(); s.Driver.SetCheckbox(By.Id("LNURLBech32Mode"), false); - s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), false); - s.Driver.SetCheckbox(By.Id("DisableBolt11PaymentMethod"), true); s.Driver.FindElement(By.Id("save")).Click(); Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text); // Ensure the toggles are set correctly s.GoToLightningSettings(); - //TODO: DisableBolt11PaymentMethod is actually disabled because LNURLStandardInvoiceEnabled is disabled - // checkboxes is not good choice here, in next release we should have multi choice instead Assert.False(s.Driver.FindElement(By.Id("LNURLBech32Mode")).Selected); - Assert.False(s.Driver.FindElement(By.Id("LNURLStandardInvoiceEnabled")).Selected); //even though we set DisableBolt11PaymentMethod to true, logic when saving it turns it back off as otherwise no lightning option is available at all! Assert.False(s.Driver.FindElement(By.Id("DisableBolt11PaymentMethod")).Selected); - // Invoice creation should fail, because it is a standard invoice with amount, but DisableBolt11PaymentMethod = true and LNURLStandardInvoiceEnabled = false + // Invoice creation should fail, because it is a standard invoice with amount, but DisableBolt11PaymentMethod = true s.CreateInvoice(storeId, 0.0000001m, cryptoCode, "", null, expectedSeverity: StatusMessageModel.StatusSeverity.Success); i = s.CreateInvoice(storeId, null, cryptoCode); @@ -2178,7 +2169,6 @@ namespace BTCPayServer.Tests s.GoToLightningSettings(); s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true); s.Driver.SetCheckbox(By.Id("DisableBolt11PaymentMethod"), true); - s.Driver.SetCheckbox(By.Id("LNURLStandardInvoiceEnabled"), true); s.Driver.FindElement(By.Id("save")).Click(); Assert.Contains($"{cryptoCode} Lightning settings successfully updated", s.FindAlertMessage().Text); var invForPP = s.CreateInvoice(0.0000001m, cryptoCode); diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 661f4166f..38e0da86f 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -1657,7 +1657,6 @@ namespace BTCPayServer.Tests user.RegisterLightningNode(cryptoCode, LightningConnectionType.Charge); var lnSettingsVm = user.GetController().LightningSettings(user.StoreId, cryptoCode).AssertViewModel(); lnSettingsVm.LNURLEnabled = true; - lnSettingsVm.LNURLStandardInvoiceEnabled = true; Assert.IsType(user.GetController().LightningSettings(lnSettingsVm).Result); vm = user.GetController().CheckoutAppearance().AssertViewModel(); criteria = Assert.Single(vm.PaymentMethodCriteria); diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoreLNURLPayPaymentMethodsController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoreLNURLPayPaymentMethodsController.cs index 3f8283ae4..09c7926c9 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoreLNURLPayPaymentMethodsController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoreLNURLPayPaymentMethodsController.cs @@ -54,7 +54,7 @@ namespace BTCPayServer.Controllers.Greenfield new LNURLPayPaymentMethodData( paymentMethod.PaymentId.CryptoCode, !excludedPaymentMethods.Match(paymentMethod.PaymentId), - paymentMethod.UseBech32Scheme, paymentMethod.EnableForStandardInvoices + paymentMethod.UseBech32Scheme ) ) .Where((result) => enabled is null || enabled == result.Enabled) @@ -124,8 +124,7 @@ namespace BTCPayServer.Controllers.Greenfield LNURLPaySupportedPaymentMethod? paymentMethod = new LNURLPaySupportedPaymentMethod() { CryptoCode = cryptoCode, - UseBech32Scheme = paymentMethodData.UseBech32Scheme, - EnableForStandardInvoices = paymentMethodData.EnableForStandardInvoices + UseBech32Scheme = paymentMethodData.UseBech32Scheme }; var store = Store; @@ -154,7 +153,7 @@ namespace BTCPayServer.Controllers.Greenfield : new LNURLPayPaymentMethodData( paymentMethod.PaymentId.CryptoCode, !excluded, - paymentMethod.UseBech32Scheme, paymentMethod.EnableForStandardInvoices + paymentMethod.UseBech32Scheme ); } private void AssertCryptoCodeWallet(string cryptoCode, out BTCPayNetwork network) diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index bb5b7f119..c338b12cb 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -666,48 +666,55 @@ namespace BTCPayServer.Controllers var btcId = PaymentMethodId.Parse("BTC"); var lnId = PaymentMethodId.Parse("BTC_LightningLike"); var lnurlId = PaymentMethodId.Parse("BTC_LNURLPAY"); + + + var displayedPaymentMethods = invoice.GetPaymentMethods().Select(p => p.GetId()).ToList(); + + // Exclude Lightning if OnChainWithLnInvoiceFallback is active and we have both payment methods + if (storeBlob is { CheckoutType: CheckoutType.V2, OnChainWithLnInvoiceFallback: true } && + displayedPaymentMethods.Contains(btcId)) + { + displayedPaymentMethods.Remove(lnId); + displayedPaymentMethods.Remove(lnurlId); + } + + // BOLT11 doesn't really support payment without amount + if (invoice.IsUnsetTopUp()) + displayedPaymentMethods.Remove(lnId); + + // Exclude lnurl if bolt11 is available + if (displayedPaymentMethods.Contains(lnId) && displayedPaymentMethods.Contains(lnurlId)) + displayedPaymentMethods.Remove(lnurlId); + + if (paymentMethodId is not null && displayedPaymentMethods.Contains(paymentMethodId)) + paymentMethodId = null; if (paymentMethodId is null) { - var enabledPaymentIds = store.GetEnabledPaymentIds(_NetworkProvider).ToArray(); - - // Exclude Lightning if OnChainWithLnInvoiceFallback is active and we have both payment methods - if (storeBlob is { CheckoutType: CheckoutType.V2, OnChainWithLnInvoiceFallback: true }) - { - if (enabledPaymentIds.Contains(btcId) && enabledPaymentIds.Contains(lnId)) - { - enabledPaymentIds = enabledPaymentIds.Where(pmId => pmId != lnId).ToArray(); - } - if (enabledPaymentIds.Contains(btcId) && enabledPaymentIds.Contains(lnurlId)) - { - enabledPaymentIds = enabledPaymentIds.Where(pmId => pmId != lnurlId).ToArray(); - } - } - PaymentMethodId? invoicePaymentId = invoice.GetDefaultPaymentMethod(); PaymentMethodId? storePaymentId = store.GetDefaultPaymentId(); if (invoicePaymentId is not null) { - if (enabledPaymentIds.Contains(invoicePaymentId)) + if (displayedPaymentMethods.Contains(invoicePaymentId)) paymentMethodId = invoicePaymentId; } if (paymentMethodId is null && storePaymentId is not null) { - if (enabledPaymentIds.Contains(storePaymentId)) + if (displayedPaymentMethods.Contains(storePaymentId)) paymentMethodId = storePaymentId; } if (paymentMethodId is null && invoicePaymentId is not null) { - paymentMethodId = invoicePaymentId.FindNearest(enabledPaymentIds); + paymentMethodId = invoicePaymentId.FindNearest(displayedPaymentMethods); } if (paymentMethodId is null && storePaymentId is not null) { - paymentMethodId = storePaymentId.FindNearest(enabledPaymentIds); + paymentMethodId = storePaymentId.FindNearest(displayedPaymentMethods); } if (paymentMethodId is null) { - paymentMethodId = enabledPaymentIds.FirstOrDefault(e => e.CryptoCode == _NetworkProvider.DefaultNetwork.CryptoCode && e.PaymentType == PaymentTypes.BTCLike) ?? - enabledPaymentIds.FirstOrDefault(e => e.CryptoCode == _NetworkProvider.DefaultNetwork.CryptoCode && e.PaymentType != PaymentTypes.LNURLPay) ?? - enabledPaymentIds.FirstOrDefault(); + paymentMethodId = displayedPaymentMethods.FirstOrDefault(e => e.CryptoCode == _NetworkProvider.DefaultNetwork.CryptoCode && e.PaymentType == PaymentTypes.BTCLike) ?? + displayedPaymentMethods.FirstOrDefault(e => e.CryptoCode == _NetworkProvider.DefaultNetwork.CryptoCode && e.PaymentType != PaymentTypes.LNURLPay) ?? + displayedPaymentMethods.FirstOrDefault(); } isDefaultPaymentId = true; } @@ -721,30 +728,37 @@ namespace BTCPayServer.Controllers return null; var paymentMethodTemp = invoice .GetPaymentMethods() - .FirstOrDefault(pm => - { - var pmId = pm.GetId(); - return paymentMethodId.CryptoCode == pmId.CryptoCode && - ((invoice.IsUnsetTopUp() && !storeBlob.OnChainWithLnInvoiceFallback) || pmId != lnurlId); - }); - if (paymentMethodTemp == null) - paymentMethodTemp = invoice.GetPaymentMethods().FirstOrDefault(); + .Where(p => displayedPaymentMethods.Contains(p.GetId())) + .FirstOrDefault(); if (paymentMethodTemp is null) return null; network = paymentMethodTemp.Network; paymentMethodId = paymentMethodTemp.GetId(); } - var paymentMethod = invoice.GetPaymentMethod(paymentMethodId); - var paymentMethodDetails = paymentMethod.GetPaymentMethodDetails(); - if (!paymentMethodDetails.Activated) + + // We activate the default payment method, and also those which aren't displayed (as they can't be set as default) + bool activated = false; + foreach (var pm in invoice.GetPaymentMethods()) { - if (await _invoiceActivator.ActivateInvoicePaymentMethod(paymentMethod.GetId(), invoice, store)) + var pmi = pm.GetId(); + if (pmi != paymentMethodId || !displayedPaymentMethods.Contains(pmi)) + continue; + var pmd = pm.GetPaymentMethodDetails(); + if (!pmd.Activated) { - return await GetInvoiceModel(invoiceId, paymentMethodId, lang); + if (await _invoiceActivator.ActivateInvoicePaymentMethod(pmi, invoice, store)) + { + activated = true; + } } } + if (activated) + return await GetInvoiceModel(invoiceId, paymentMethodId, lang); + + var paymentMethod = invoice.GetPaymentMethod(paymentMethodId); + var paymentMethodDetails = paymentMethod.GetPaymentMethodDetails(); var dto = invoice.EntityToDTO(); var accounting = paymentMethod.Calculate(); var paymentMethodHandler = _paymentMethodHandlerDictionary[paymentMethodId]; @@ -844,6 +858,7 @@ namespace BTCPayServer.Controllers var availableCryptoHandler = _paymentMethodHandlerDictionary[availableCryptoPaymentMethodId]; return new PaymentModel.AvailableCrypto { + Displayed = displayedPaymentMethods.Contains(kv.GetId()), PaymentMethodId = kv.GetId().ToString(), CryptoCode = kv.Network?.CryptoCode ?? kv.GetId().CryptoCode, PaymentMethodName = availableCryptoHandler.GetPaymentMethodName(availableCryptoPaymentMethodId), @@ -862,17 +877,6 @@ namespace BTCPayServer.Controllers .ToList() }; - // Exclude Lightning if OnChainWithLnInvoiceFallback is active and we have both payment methods - if (storeBlob is { CheckoutType: CheckoutType.V2, OnChainWithLnInvoiceFallback: true }) - { - var onchainPM = model.AvailableCryptos.Find(c => c.PaymentMethodId == btcId.ToString()); - var lightningPM = model.AvailableCryptos.Find(c => c.PaymentMethodId == lnId.ToString()); - if (onchainPM != null && lightningPM != null) - { - model.AvailableCryptos.Remove(lightningPM); - } - } - paymentMethodHandler.PreparePaymentModel(model, dto, storeBlob, paymentMethod); model.UISettings = paymentMethodHandler.GetCheckoutUISettings(); model.PaymentMethodId = paymentMethodId.ToString(); diff --git a/BTCPayServer/Controllers/UILNURLController.cs b/BTCPayServer/Controllers/UILNURLController.cs index 13051a9d3..148a7db0b 100644 --- a/BTCPayServer/Controllers/UILNURLController.cs +++ b/BTCPayServer/Controllers/UILNURLController.cs @@ -59,6 +59,7 @@ namespace BTCPayServer private readonly PullPaymentHostedService _pullPaymentHostedService; private readonly BTCPayNetworkJsonSerializerSettings _btcPayNetworkJsonSerializerSettings; private readonly IPluginHookService _pluginHookService; + private readonly InvoiceActivator _invoiceActivator; public UILNURLController(InvoiceRepository invoiceRepository, EventAggregator eventAggregator, @@ -72,7 +73,8 @@ namespace BTCPayServer LightningLikePayoutHandler lightningLikePayoutHandler, PullPaymentHostedService pullPaymentHostedService, BTCPayNetworkJsonSerializerSettings btcPayNetworkJsonSerializerSettings, - IPluginHookService pluginHookService) + IPluginHookService pluginHookService, + InvoiceActivator invoiceActivator) { _invoiceRepository = invoiceRepository; _eventAggregator = eventAggregator; @@ -87,6 +89,7 @@ namespace BTCPayServer _pullPaymentHostedService = pullPaymentHostedService; _btcPayNetworkJsonSerializerSettings = btcPayNetworkJsonSerializerSettings; _pluginHookService = pluginHookService; + _invoiceActivator = invoiceActivator; } [HttpGet("withdraw/pp/{pullPaymentId}")] @@ -436,13 +439,27 @@ namespace BTCPayServer List additionalTags = null, bool allowOverpay = true) { - if (GetLNUrlPaymentMethodId(cryptoCode, store, out _) is null) + var pmi = GetLNUrlPaymentMethodId(cryptoCode, store, out _); + if (pmi is null) return NotFound("LNUrl or LN is disabled"); InvoiceEntity i; try { + createInvoice.Checkout ??= new InvoiceDataBase.CheckoutOptions(); + createInvoice.Checkout.PaymentMethods = new[] { pmi.ToStringNormalized() }; i = await _invoiceController.CreateInvoiceCoreRaw(createInvoice, store, Request.GetAbsoluteRoot(), additionalTags); + var pm = i.GetPaymentMethod(pmi); + if (pm is null) + return NotFound("LNUrl is enabled, but the invoice couldn't use it. Check the invoice's events for more information."); + // If LNUrl isn't activated, make sure it is + var pmd = pm.GetPaymentMethodDetails(); + if (!pmd.Activated) + { + if (!await _invoiceActivator.ActivateInvoicePaymentMethod(pmi, i, store)) + return NotFound("Unable to activate LNURL. Check the invoice's events for more information."); + i = await _invoiceRepository.GetInvoice(i.Id); + } } catch (Exception e) { @@ -572,6 +589,15 @@ namespace BTCPayServer var lightningPaymentMethod = i.GetPaymentMethod(pmi); var paymentMethodDetails = lightningPaymentMethod?.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails; + if (paymentMethodDetails is not null && !paymentMethodDetails.Activated) + { + if (!await _invoiceActivator.ActivateInvoicePaymentMethod(pmi, i, store)) + return NotFound(); + i = await _invoiceRepository.GetInvoice(invoiceId, true); + lightningPaymentMethod = i.GetPaymentMethod(pmi); + paymentMethodDetails = lightningPaymentMethod.GetPaymentMethodDetails() as LNURLPayPaymentMethodDetails; + } + if (paymentMethodDetails?.LightningSupportedPaymentMethod is null) return NotFound(); diff --git a/BTCPayServer/Controllers/UIStoresController.LightningLike.cs b/BTCPayServer/Controllers/UIStoresController.LightningLike.cs index 587e85ec3..4b1cd8432 100644 --- a/BTCPayServer/Controllers/UIStoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/UIStoresController.LightningLike.cs @@ -181,7 +181,6 @@ namespace BTCPayServer.Controllers { CryptoCode = vm.CryptoCode, UseBech32Scheme = true, - EnableForStandardInvoices = false, LUD12Enabled = false }); @@ -255,10 +254,9 @@ namespace BTCPayServer.Controllers { vm.LNURLEnabled = !store.GetStoreBlob().GetExcludedPaymentMethods().Match(lnurl.PaymentId); vm.LNURLBech32Mode = lnurl.UseBech32Scheme; - vm.LNURLStandardInvoiceEnabled = lnurl.EnableForStandardInvoices; vm.LUD12Enabled = lnurl.LUD12Enabled; vm.DisableBolt11PaymentMethod = - vm.LNURLEnabled && vm.LNURLStandardInvoiceEnabled && vm.DisableBolt11PaymentMethod; + vm.LNURLEnabled && vm.DisableBolt11PaymentMethod; } else { @@ -291,7 +289,7 @@ namespace BTCPayServer.Controllers blob.LightningPrivateRouteHints = vm.LightningPrivateRouteHints; blob.OnChainWithLnInvoiceFallback = vm.OnChainWithLnInvoiceFallback; var disableBolt11PaymentMethod = - vm.LNURLEnabled && vm.LNURLStandardInvoiceEnabled && vm.DisableBolt11PaymentMethod; + vm.LNURLEnabled && vm.DisableBolt11PaymentMethod; var lnurlId = new PaymentMethodId(vm.CryptoCode, PaymentTypes.LNURLPay); blob.SetExcluded(lnurlId, !vm.LNURLEnabled); var lightning = GetExistingLightningSupportedPaymentMethod(vm.CryptoCode, store); @@ -305,7 +303,6 @@ namespace BTCPayServer.Controllers var lnurl = GetExistingLNURLSupportedPaymentMethod(vm.CryptoCode, store); if (lnurl is null || ( - lnurl.EnableForStandardInvoices != vm.LNURLStandardInvoiceEnabled || lnurl.UseBech32Scheme != vm.LNURLBech32Mode || lnurl.LUD12Enabled != vm.LUD12Enabled)) { @@ -315,7 +312,6 @@ namespace BTCPayServer.Controllers store.SetSupportedPaymentMethod(new LNURLPaySupportedPaymentMethod { CryptoCode = vm.CryptoCode, - EnableForStandardInvoices = vm.LNURLStandardInvoiceEnabled, UseBech32Scheme = vm.LNURLBech32Mode, LUD12Enabled = vm.LUD12Enabled }); diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index b91558390..3d1a62188 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -21,6 +21,7 @@ namespace BTCPayServer.Models.InvoicingModels public string PaymentMethodName { get; set; } public bool IsLightning { get; set; } public string CryptoCode { get; set; } + public bool Displayed { get; set; } } public string CustomCSSLink { get; set; } public string CustomLogoLink { get; set; } diff --git a/BTCPayServer/Models/StoreViewModels/LightningSettingsViewModel.cs b/BTCPayServer/Models/StoreViewModels/LightningSettingsViewModel.cs index 914310ab8..fee946bec 100644 --- a/BTCPayServer/Models/StoreViewModels/LightningSettingsViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/LightningSettingsViewModel.cs @@ -24,9 +24,6 @@ namespace BTCPayServer.Models.StoreViewModels [Display(Name = "LNURL Classic Mode")] public bool LNURLBech32Mode { get; set; } = true; - [Display(Name = "LNURL enabled for standard invoices")] - public bool LNURLStandardInvoiceEnabled { get; set; } = true; - [Display(Name = "Allow payee to pass a comment")] public bool LUD12Enabled { get; set; } diff --git a/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentHandler.cs b/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentHandler.cs index f5237432e..9059fa066 100644 --- a/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentHandler.cs +++ b/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentHandler.cs @@ -50,12 +50,6 @@ namespace BTCPayServer.Payments.Lightning BTCPayNetwork network, object preparePaymentObject, IEnumerable invoicePaymentMethods) { var lnPmi = new PaymentMethodId(supportedPaymentMethod.CryptoCode, PaymentTypes.LightningLike); - if (!supportedPaymentMethod.EnableForStandardInvoices && - paymentMethod.ParentEntity.Type == InvoiceType.Standard && - invoicePaymentMethods.Contains(lnPmi)) - { - throw new PaymentMethodUnavailableException("LNURL is not enabled for standard invoices"); - } if (string.IsNullOrEmpty(paymentMethod.ParentEntity.Id)) { var lnSupported = store.GetSupportedPaymentMethods(_networkProvider) diff --git a/BTCPayServer/Payments/LNURLPay/LNURLPaySupportedPaymentMethod.cs b/BTCPayServer/Payments/LNURLPay/LNURLPaySupportedPaymentMethod.cs index e7e5230fe..8696246e0 100644 --- a/BTCPayServer/Payments/LNURLPay/LNURLPaySupportedPaymentMethod.cs +++ b/BTCPayServer/Payments/LNURLPay/LNURLPaySupportedPaymentMethod.cs @@ -14,8 +14,6 @@ namespace BTCPayServer.Payments.Lightning public bool UseBech32Scheme { get; set; } - public bool EnableForStandardInvoices { get; set; } = false; - public bool LUD12Enabled { get; set; } = true; } diff --git a/BTCPayServer/Payments/LNURLPay/PaymentTypes.LNURL.cs b/BTCPayServer/Payments/LNURLPay/PaymentTypes.LNURL.cs index e91d07559..820d414a5 100644 --- a/BTCPayServer/Payments/LNURLPay/PaymentTypes.LNURL.cs +++ b/BTCPayServer/Payments/LNURLPay/PaymentTypes.LNURL.cs @@ -47,7 +47,6 @@ namespace BTCPayServer.Payments return new LNURLPayPaymentMethodBaseData() { UseBech32Scheme = lightningSupportedPaymentMethod.UseBech32Scheme, - EnableForStandardInvoices = lightningSupportedPaymentMethod.EnableForStandardInvoices, LUD12Enabled = lightningSupportedPaymentMethod.LUD12Enabled }; return null; diff --git a/BTCPayServer/Payments/PaymentMethodId.cs b/BTCPayServer/Payments/PaymentMethodId.cs index af30c4ed0..e7833f3cc 100644 --- a/BTCPayServer/Payments/PaymentMethodId.cs +++ b/BTCPayServer/Payments/PaymentMethodId.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -11,7 +12,7 @@ namespace BTCPayServer.Payments /// public class PaymentMethodId { - public PaymentMethodId? FindNearest(PaymentMethodId[] others) + public PaymentMethodId? FindNearest(IEnumerable others) { ArgumentNullException.ThrowIfNull(others); return others.FirstOrDefault(f => f == this) ?? diff --git a/BTCPayServer/Views/UIInvoice/Checkout-Body.cshtml b/BTCPayServer/Views/UIInvoice/Checkout-Body.cshtml index 06e1ff10f..bb0f7b842 100644 --- a/BTCPayServer/Views/UIInvoice/Checkout-Body.cshtml +++ b/BTCPayServer/Views/UIInvoice/Checkout-Body.cshtml @@ -1,5 +1,7 @@ @model PaymentModel - +@{ + var displayedPaymentMethods = Model.AvailableCryptos.Where(a => a.Displayed).ToList(); +}
@if (!string.IsNullOrEmpty(Model.CustomLogoLink)) @@ -45,7 +47,7 @@
- @if (Model.AvailableCryptos.Count > 1) + @if (displayedPaymentMethods.Count > 1) {
@@ -57,7 +59,7 @@