diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 4e095a01f..1f6a8f198 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -941,19 +941,9 @@ namespace BTCPayServer.Controllers extension.ModifyPaymentModel(new PaymentModelContext(model, store, storeBlob, invoice, Url, kv, h, paymentMethodId == kv.PaymentMethodId)); } } - model.UISettings = _viewProvider.TryGetViewViewModel(prompt, "CheckoutUI")?.View as CheckoutUIPaymentMethodSettings; model.PaymentMethodId = paymentMethodId.ToString(); model.OrderAmountFiat = OrderAmountFromInvoice(model.CryptoCode, invoice, DisplayFormatter.CurrencyFormat.Symbol); - foreach (var paymentPrompt in invoice.GetPaymentPrompts()) - { - var vvm = _viewProvider.TryGetViewViewModel(paymentPrompt, "CheckoutUI"); - if (vvm?.View is CheckoutUIPaymentMethodSettings { ExtensionPartial: { } partial }) - { - model.ExtensionPartials.Add(partial); - } - } - if (storeBlob.PlaySoundOnPayment) { model.PaymentSoundUrl = storeBlob.PaymentSoundUrl is null diff --git a/BTCPayServer/Extensions.cs b/BTCPayServer/Extensions.cs index 3e8721b80..b270fe7ab 100644 --- a/BTCPayServer/Extensions.cs +++ b/BTCPayServer/Extensions.cs @@ -14,6 +14,8 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; +using BTCPayServer.Abstractions.Services; using BTCPayServer.BIP78.Sender; using BTCPayServer.Configuration; using BTCPayServer.Data; @@ -289,6 +291,13 @@ namespace BTCPayServer } } + + public static IServiceCollection AddUIExtension(this IServiceCollection services, string key, string partialView) + { + services.AddSingleton(new UIExtension(partialView, + key)); + return services; + } public static IServiceCollection AddReportProvider(this IServiceCollection services) where T : ReportProvider { diff --git a/BTCPayServer/Hosting/BTCPayServerServices.cs b/BTCPayServer/Hosting/BTCPayServerServices.cs index 80c045533..3fb78f7f6 100644 --- a/BTCPayServer/Hosting/BTCPayServerServices.cs +++ b/BTCPayServer/Hosting/BTCPayServerServices.cs @@ -365,6 +365,9 @@ namespace BTCPayServer.Hosting o.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(DerivationStrategyBase))); }); + services.AddUIExtension("checkout-end", "Bitcoin/BitcoinLikeMethodCheckout"); + services.AddUIExtension("checkout-end", "Lightning/LightningLikeMethodCheckout"); + services.AddSingleton(); services.AddSingleton(o => o.GetRequiredService()); services.AddSingleton(); @@ -631,8 +634,6 @@ o.GetRequiredService>().ToDictionary(o => o.P (BitcoinPaymentModelExtension)ActivatorUtilities.CreateInstance(provider, typeof(BitcoinPaymentModelExtension), new object[] { network, pmi })); services.AddSingleton(provider => (IPaymentMethodBitpayAPIExtension)ActivatorUtilities.CreateInstance(provider, typeof(BitcoinPaymentMethodBitpayAPIExtension), new object[] { pmi })); - services.AddSingleton(provider => -(IPaymentMethodViewExtension)ActivatorUtilities.CreateInstance(provider, typeof(BitcoinPaymentMethodViewExtension), new object[] { pmi })); if (!network.ReadonlyWallet && network.WalletSupported) { @@ -652,8 +653,6 @@ o.GetRequiredService>().ToDictionary(o => o.P (IPaymentLinkExtension)ActivatorUtilities.CreateInstance(provider, typeof(LightningPaymentLinkExtension), new object[] { network, pmi })); services.AddSingleton(provider => (IPaymentModelExtension)ActivatorUtilities.CreateInstance(provider, typeof(LightningPaymentModelExtension), new object[] { network, pmi })); - services.AddSingleton(provider => -(IPaymentMethodViewExtension)ActivatorUtilities.CreateInstance(provider, typeof(LightningPaymentMethodViewExtension), new object[] { pmi })); services.AddSingleton(provider => (IPaymentMethodBitpayAPIExtension)ActivatorUtilities.CreateInstance(provider, typeof(LightningPaymentMethodBitpayAPIExtension), new object[] { pmi })); var payoutMethodId = PayoutTypes.LN.GetPayoutMethodId(network.CryptoCode); diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index 15898ae72..586dd74ad 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -9,7 +9,7 @@ namespace BTCPayServer.Models.InvoicingModels { public class PaymentModel { - public CheckoutUIPaymentMethodSettings UISettings; + public string CheckoutBodyComponentName { get; set; } public class AvailableCrypto { [JsonConverter(typeof(PaymentMethodIdJsonConverter))] @@ -80,9 +80,6 @@ namespace BTCPayServer.Models.InvoicingModels public string ReceiptLink { get; set; } public int? RequiredConfirmations { get; set; } public long? ReceivedConfirmations { get; set; } - - [JsonIgnore] - public HashSet ExtensionPartials { get; } = new HashSet(); [JsonExtensionData] public Dictionary AdditionalData { get; set; } = new(); } diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinPaymentMethodViewExtension.cs b/BTCPayServer/Payments/Bitcoin/BitcoinPaymentMethodViewExtension.cs deleted file mode 100644 index 0850a48d5..000000000 --- a/BTCPayServer/Payments/Bitcoin/BitcoinPaymentMethodViewExtension.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace BTCPayServer.Payments.Bitcoin -{ - public class BitcoinPaymentMethodViewExtension : IPaymentMethodViewExtension - { - public BitcoinPaymentMethodViewExtension(PaymentMethodId paymentMethodId) - { - PaymentMethodId = paymentMethodId; - } - public PaymentMethodId PaymentMethodId { get; } - - public void RegisterViews(PaymentMethodViewContext context) - { - context.RegisterCheckoutUI(new CheckoutUIPaymentMethodSettings - { - ExtensionPartial = "Bitcoin/BitcoinLikeMethodCheckout", - }); - } - } -} diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinPaymentModelExtension.cs b/BTCPayServer/Payments/Bitcoin/BitcoinPaymentModelExtension.cs index 273cccd01..25e1fb59c 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinPaymentModelExtension.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinPaymentModelExtension.cs @@ -14,6 +14,7 @@ namespace BTCPayServer.Payments.Bitcoin { public class BitcoinPaymentModelExtension : IPaymentModelExtension { + public const string CheckoutBodyComponentName = "BitcoinCheckoutBody"; private readonly PaymentMethodHandlerDictionary _handlers; private readonly BTCPayNetwork _Network; private readonly DisplayFormatter _displayFormatter; @@ -50,6 +51,7 @@ namespace BTCPayServer.Payments.Bitcoin return; var prompt = context.Prompt; var details = handler.ParsePaymentPromptDetails(prompt.Details); + context.Model.CheckoutBodyComponentName = CheckoutBodyComponentName; context.Model.ShowRecommendedFee = context.StoreBlob.ShowRecommendedFee; context.Model.FeeRate = details.RecommendedFeeRate.SatoshiPerByte; diff --git a/BTCPayServer/Payments/IPaymentMethodViewExtension.cs b/BTCPayServer/Payments/IPaymentMethodViewExtension.cs index 1266b5ac7..72ad805b5 100644 --- a/BTCPayServer/Payments/IPaymentMethodViewExtension.cs +++ b/BTCPayServer/Payments/IPaymentMethodViewExtension.cs @@ -51,17 +51,9 @@ namespace BTCPayServer.Payments { _Views.Add("AdditionalPaymentMethodDetails", partialName); } - public void RegisterCheckoutUI(CheckoutUIPaymentMethodSettings settings) - { - _Views.Add("CheckoutUI", settings); - } public void Register(string key, object value) { _Views.Add(key, value); } } - public class CheckoutUIPaymentMethodSettings - { - public string? ExtensionPartial { get; set; } - } } diff --git a/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentModelExtension.cs b/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentModelExtension.cs index 14b19dfd2..d7c2c01f3 100644 --- a/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentModelExtension.cs +++ b/BTCPayServer/Payments/LNURLPay/LNURLPayPaymentModelExtension.cs @@ -48,6 +48,7 @@ namespace BTCPayServer.Payments.LNURLPay context.Model.InvoiceBitcoinUrl = lnurl; context.Model.InvoiceBitcoinUrlQR = lnurl.ToUpperInvariant().Replace(UriScheme.ToUpperInvariant(), UriScheme); } + context.Model.CheckoutBodyComponentName = LightningPaymentModelExtension.CheckoutBodyComponentName; context.Model.PeerInfo = handler.ParsePaymentPromptDetails(context.Prompt.Details).NodeInfo; if (context.StoreBlob.LightningAmountInSatoshi && context.Model.CryptoCode == "BTC") { diff --git a/BTCPayServer/Payments/LNURLPay/LNURLPaymentMethodViewExtension.cs b/BTCPayServer/Payments/LNURLPay/LNURLPaymentMethodViewExtension.cs index 6777c6433..d1677ec22 100644 --- a/BTCPayServer/Payments/LNURLPay/LNURLPaymentMethodViewExtension.cs +++ b/BTCPayServer/Payments/LNURLPay/LNURLPaymentMethodViewExtension.cs @@ -14,10 +14,6 @@ namespace BTCPayServer.Payments.LNURLPay if (details is not LNURLPayPaymentMethodDetails d) return; context.RegisterPaymentMethodDetails("LNURL/AdditionalPaymentMethodDetails"); - context.RegisterCheckoutUI(new CheckoutUIPaymentMethodSettings() - { - ExtensionPartial = "Lightning/LightningLikeMethodCheckout" - }); } } } diff --git a/BTCPayServer/Payments/Lightning/LightningPaymentMethodViewExtension.cs b/BTCPayServer/Payments/Lightning/LightningPaymentMethodViewExtension.cs deleted file mode 100644 index 2ef202aef..000000000 --- a/BTCPayServer/Payments/Lightning/LightningPaymentMethodViewExtension.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace BTCPayServer.Payments.Lightning -{ - public class LightningPaymentMethodViewExtension : IPaymentMethodViewExtension - { - public LightningPaymentMethodViewExtension(PaymentMethodId paymentMethodId) - { - PaymentMethodId = paymentMethodId; - } - public PaymentMethodId PaymentMethodId { get; } - - public void RegisterViews(PaymentMethodViewContext context) - { - context.RegisterCheckoutUI(new CheckoutUIPaymentMethodSettings() - { - ExtensionPartial = "Lightning/LightningLikeMethodCheckout" - }); - } - } -} diff --git a/BTCPayServer/Payments/Lightning/LightningPaymentModelExtension.cs b/BTCPayServer/Payments/Lightning/LightningPaymentModelExtension.cs index 7f1573625..ab113585b 100644 --- a/BTCPayServer/Payments/Lightning/LightningPaymentModelExtension.cs +++ b/BTCPayServer/Payments/Lightning/LightningPaymentModelExtension.cs @@ -11,6 +11,7 @@ namespace BTCPayServer.Payments.Lightning { public class LightningPaymentModelExtension : IPaymentModelExtension { + public const string CheckoutBodyComponentName = "LightningCheckoutBody"; private readonly DisplayFormatter _displayFormatter; IPaymentLinkExtension _PaymentLinkExtension; public LightningPaymentModelExtension( @@ -44,6 +45,7 @@ namespace BTCPayServer.Payments.Lightning var paymentPrompt = context.InvoiceEntity.GetPaymentPrompt(PaymentMethodId); if (paymentPrompt is null) return; + context.Model.CheckoutBodyComponentName = CheckoutBodyComponentName; context.Model.InvoiceBitcoinUrl = _PaymentLinkExtension.GetPaymentLink(context.Prompt, context.UrlHelper); if (context.Model.InvoiceBitcoinUrl is not null) context.Model.InvoiceBitcoinUrlQR = $"lightning:{context.Model.InvoiceBitcoinUrl.ToUpperInvariant()?.Substring("LIGHTNING:".Length)}"; diff --git a/BTCPayServer/Plugins/Altcoins/Monero/AltcoinsPlugin.Monero.cs b/BTCPayServer/Plugins/Altcoins/Monero/AltcoinsPlugin.Monero.cs index e51e16dcd..fe829c86a 100644 --- a/BTCPayServer/Plugins/Altcoins/Monero/AltcoinsPlugin.Monero.cs +++ b/BTCPayServer/Plugins/Altcoins/Monero/AltcoinsPlugin.Monero.cs @@ -42,8 +42,6 @@ public partial class AltcoinsPlugin var pmi = PaymentTypes.CHAIN.GetPaymentMethodId("XMR"); services.AddBTCPayNetwork(network) .AddTransactionLinkProvider(pmi, new SimpleTransactionLinkProvider(blockExplorerLink)); - services.AddSingleton(provider => -(IPaymentMethodViewExtension)ActivatorUtilities.CreateInstance(provider, typeof(BitcoinPaymentMethodViewExtension), new object[] { pmi })); services.AddSingleton(provider => diff --git a/BTCPayServer/Plugins/Altcoins/Zcash/AltcoinsPlugin.Zcash.cs b/BTCPayServer/Plugins/Altcoins/Zcash/AltcoinsPlugin.Zcash.cs index a6ffd2610..8cec5a8bf 100644 --- a/BTCPayServer/Plugins/Altcoins/Zcash/AltcoinsPlugin.Zcash.cs +++ b/BTCPayServer/Plugins/Altcoins/Zcash/AltcoinsPlugin.Zcash.cs @@ -43,8 +43,6 @@ public partial class AltcoinsPlugin var pmi = PaymentTypes.CHAIN.GetPaymentMethodId("ZEC"); services.AddBTCPayNetwork(network) .AddTransactionLinkProvider(pmi, new SimpleTransactionLinkProvider(blockExplorerLink)); - services.AddSingleton(provider => -(IPaymentMethodViewExtension)ActivatorUtilities.CreateInstance(provider, typeof(BitcoinPaymentMethodViewExtension), new object[] { pmi })); services.AddSingleton(provider => diff --git a/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroLikePaymentMethodHandler.cs b/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroLikePaymentMethodHandler.cs index b8e8001a6..04f01016b 100644 --- a/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroLikePaymentMethodHandler.cs +++ b/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroLikePaymentMethodHandler.cs @@ -108,14 +108,6 @@ namespace BTCPayServer.Services.Altcoins.Monero.Payments return details.ToObject(Serializer); } - public CheckoutUIPaymentMethodSettings GetCheckoutUISettings() - { - return new CheckoutUIPaymentMethodSettings - { - ExtensionPartial = "Bitcoin/BitcoinLikeMethodCheckout" - }; - } - public MoneroLikePaymentData ParsePaymentDetails(JToken details) { return details.ToObject(Serializer) ?? throw new FormatException($"Invalid {nameof(MoneroLikePaymentMethodHandler)}"); diff --git a/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroPaymentModelExtension.cs b/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroPaymentModelExtension.cs index 092cdb105..cb1c52a9f 100644 --- a/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroPaymentModelExtension.cs +++ b/BTCPayServer/Services/Altcoins/Monero/Payments/MoneroPaymentModelExtension.cs @@ -36,6 +36,7 @@ namespace BTCPayServer.Services.Altcoins.Monero.Payments { if (context is not { IsSelected: true, Handler: MoneroLikePaymentMethodHandler handler }) return; + context.Model.CheckoutBodyComponentName = BitcoinPaymentModelExtension.CheckoutBodyComponentName; if (context.Model.Activated) { var details = context.InvoiceEntity.GetPayments(true) diff --git a/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashLikePaymentMethodHandler.cs b/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashLikePaymentMethodHandler.cs index 8984459f7..7db54a244 100644 --- a/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashLikePaymentMethodHandler.cs +++ b/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashLikePaymentMethodHandler.cs @@ -102,14 +102,6 @@ namespace BTCPayServer.Services.Altcoins.Zcash.Payments public long AccountIndex { get; internal set; } } - public CheckoutUIPaymentMethodSettings GetCheckoutUISettings() - { - return new CheckoutUIPaymentMethodSettings - { - ExtensionPartial = "Bitcoin/BitcoinLikeMethodCheckout" - }; - } - public ZcashLikePaymentData ParsePaymentDetails(JToken details) { return details.ToObject(Serializer) ?? throw new FormatException($"Invalid {nameof(ZcashLikePaymentData)}"); diff --git a/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashPaymentModelExtension.cs b/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashPaymentModelExtension.cs index 47a0527cd..6e824274a 100644 --- a/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashPaymentModelExtension.cs +++ b/BTCPayServer/Services/Altcoins/Zcash/Payments/ZcashPaymentModelExtension.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using BTCPayServer.Payments; +using BTCPayServer.Payments.Bitcoin; using BTCPayServer.Services.Altcoins.Monero.Payments; using BTCPayServer.Services.Altcoins.Zcash.Services; using BTCPayServer.Services.Invoices; @@ -35,7 +36,8 @@ namespace BTCPayServer.Services.Altcoins.Zcash.Payments { if (context is not { IsSelected: true, Handler: ZcashLikePaymentMethodHandler handler }) return; - if (context.Model.Activated) + context.Model.CheckoutBodyComponentName = BitcoinPaymentModelExtension.CheckoutBodyComponentName; + if (context.Model.Activated) { var details = context.InvoiceEntity.GetPayments(true) .Select(p => p.GetDetails(handler)) diff --git a/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout.cshtml b/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout.cshtml index ccb8dd4b6..4dc23a5e5 100644 --- a/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout.cshtml +++ b/BTCPayServer/Views/Shared/Bitcoin/BitcoinLikeMethodCheckout.cshtml @@ -1,9 +1,10 @@ @using BTCPayServer.BIP78.Sender @using BTCPayServer.Components.TruncateCenter @using BTCPayServer.Abstractions.TagHelpers +@using BTCPayServer.Payments.Bitcoin @model BTCPayServer.Models.InvoicingModels.PaymentModel -