From 43ee22f965ecf50f0c080c96492ed9846b51fe05 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Sun, 25 Aug 2019 15:50:11 +0200 Subject: [PATCH] Allow overriding UI of checkout in payment handler (#992) --- .../Controllers/InvoiceController.UI.cs | 2 +- .../Models/InvoicingModels/PaymentModel.cs | 7 + .../Payments/IPaymentMethodHandler.cs | 6 + .../Views/Invoice/Checkout-Body.cshtml | 403 +++++++++--------- BTCPayServer/Views/Invoice/Checkout.cshtml | 15 +- .../Views/Invoice/CheckoutNoScript.cshtml | 26 +- BTCPayServer/wwwroot/checkout/js/core.js | 83 ++-- 7 files changed, 296 insertions(+), 246 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 0cf675209..92b75d461 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -167,7 +167,6 @@ namespace BTCPayServer.Controllers return View(model); } - //TODO: abstract private async Task GetInvoiceModel(string invoiceId, PaymentMethodId paymentMethodId) { var invoice = await _InvoiceRepository.GetInvoice(invoiceId); @@ -297,6 +296,7 @@ namespace BTCPayServer.Controllers }; paymentMethodHandler.PreparePaymentModel(model, dto); + model.UISettings = paymentMethodHandler.GetCheckoutUISettings(); model.PaymentMethodId = paymentMethodId.ToString(); var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds); model.TimeLeft = expiration.PrettyPrint(); diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index 67c1783a2..2e55287a9 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -5,8 +5,15 @@ using System.Threading.Tasks; namespace BTCPayServer.Models.InvoicingModels { + public class CheckoutUIPaymentMethodSettings + { + public string ExtensionPartial { get; set; } + public string CheckoutBodyVueComponentName { get; set; } + public string NoScriptPartialName { get; set; } + } public class PaymentModel { + public CheckoutUIPaymentMethodSettings UISettings; public class AvailableCrypto { public string PaymentMethodId { get; set; } diff --git a/BTCPayServer/Payments/IPaymentMethodHandler.cs b/BTCPayServer/Payments/IPaymentMethodHandler.cs index d0a7d099e..4c41bb4fe 100644 --- a/BTCPayServer/Payments/IPaymentMethodHandler.cs +++ b/BTCPayServer/Payments/IPaymentMethodHandler.cs @@ -46,6 +46,7 @@ namespace BTCPayServer.Payments Money amount, PaymentMethodId paymentMethodId); IEnumerable GetSupportedPaymentMethods(); + CheckoutUIPaymentMethodSettings GetCheckoutUISettings(); } public interface IPaymentMethodHandler : IPaymentMethodHandler @@ -92,6 +93,11 @@ namespace BTCPayServer.Payments throw new NotSupportedException("Invalid supportedPaymentMethod"); } + + public virtual CheckoutUIPaymentMethodSettings GetCheckoutUISettings() + { + return null; + } object IPaymentMethodHandler.PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetworkBase network) diff --git a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml index 5a655f745..d8a69c3ec 100644 --- a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml @@ -99,12 +99,10 @@
{{ srvModel.btcDue }} {{ srvModel.cryptoCode }}
- -
+
1 {{ srvModel.cryptoCodeSrv }} = {{ srvModel.rate }}
- @@ -128,7 +126,7 @@ {{$t("Network Cost")}}
- + {{ srvModel.networkFee }} {{ srvModel.cryptoCode }} @@ -148,7 +146,7 @@
-
+
{{$t("Scan")}}
@@ -170,218 +168,227 @@
-
-
-
- {{$t("Contact and Refund Email")}} -
-
- - {{$t("Contact_Body")}} - - {{$t("Please enter a valid email address")}} -
-
- - - + +
+
+
+
+ + + + +