From 9a9e31c759175cb34ff6b4e64320a17bc79eb5b7 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 27 Aug 2019 04:31:15 +0200 Subject: [PATCH] Split Bitcoin/LN to partial defined in payment handler and convert checkout to Vue (#996) --- BTCPayServer/BTCPayServer.csproj | 1 - .../Models/InvoicingModels/PaymentModel.cs | 1 + .../Payments/IPaymentMethodHandler.cs | 20 +- .../Views/Invoice/Checkout-Body.cshtml | 337 +++---------- BTCPayServer/Views/Invoice/Checkout.cshtml | 223 ++++++++- .../Views/Invoice/CheckoutNoScript.cshtml | 10 +- ...itcoin_Lightning_LikeMethodCheckout.cshtml | 304 ++++++++++++ ...ightning_LikeMethodCheckoutNoScript.cshtml | 12 + BTCPayServer/wwwroot/checkout/js/core.js | 443 ------------------ BTCPayServer/wwwroot/checkout/js/vexdialog.js | 11 - 10 files changed, 596 insertions(+), 766 deletions(-) create mode 100644 BTCPayServer/Views/Shared/Bitcoin_Lightning_LikeMethodCheckout.cshtml create mode 100644 BTCPayServer/Views/Shared/Bitcoin_Lightning_LikeMethodCheckoutNoScript.cshtml delete mode 100644 BTCPayServer/wwwroot/checkout/js/core.js delete mode 100644 BTCPayServer/wwwroot/checkout/js/vexdialog.js diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index be2f2dd4e..a048d5c0c 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -79,7 +79,6 @@ - diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index 2e55287a9..ebb105fc7 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -9,6 +9,7 @@ namespace BTCPayServer.Models.InvoicingModels { public string ExtensionPartial { get; set; } public string CheckoutBodyVueComponentName { get; set; } + public string CheckoutHeaderVueComponentName { get; set; } public string NoScriptPartialName { get; set; } } public class PaymentModel diff --git a/BTCPayServer/Payments/IPaymentMethodHandler.cs b/BTCPayServer/Payments/IPaymentMethodHandler.cs index 4c41bb4fe..4dba06a0d 100644 --- a/BTCPayServer/Payments/IPaymentMethodHandler.cs +++ b/BTCPayServer/Payments/IPaymentMethodHandler.cs @@ -76,6 +76,21 @@ namespace BTCPayServer.Payments Dictionary> rate, Money amount, PaymentMethodId paymentMethodId); public abstract IEnumerable GetSupportedPaymentMethods(); + public virtual CheckoutUIPaymentMethodSettings GetCheckoutUISettings() + { + return new CheckoutUIPaymentMethodSettings() + { + ExtensionPartial = "Bitcoin_Lightning_LikeMethodCheckout", + CheckoutBodyVueComponentName = "BitcoinLightningLikeMethodCheckout", + CheckoutHeaderVueComponentName = "BitcoinLightningLikeMethodCheckoutHeader", + NoScriptPartialName = "Bitcoin_Lightning_LikeMethodCheckoutNoScript" + }; + } + + public PaymentMethod GetPaymentMethodInInvoice(InvoiceEntity invoice, PaymentMethodId paymentMethodId) + { + return invoice.GetPaymentMethod(paymentMethodId); + } public virtual object PreparePayment(TSupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetworkBase network) @@ -93,11 +108,6 @@ 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 d8a69c3ec..5caa78acc 100644 --- a/BTCPayServer/Views/Invoice/Checkout-Body.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout-Body.cshtml @@ -12,17 +12,17 @@ } -
+
-
-
-
- +
+
+
+
- + {{$t("Invoice expired")}} @@ -32,7 +32,7 @@ {{$t("Awaiting Payment...")}}
-
@Model.TimeLeft
+
{{timerText}}
@@ -45,9 +45,9 @@
@if (Model.AvailableCryptos.Count > 1) { -
- - +
+ + {{srvModel.paymentMethodName}} ({{srvModel.cryptoCodeSrv}}) @@ -58,8 +58,8 @@ @foreach (var crypto in Model.AvailableCryptos) {
  • - - @crypto.PaymentMethodName + + @crypto.PaymentMethodName @crypto.PaymentMethodName @(crypto.IsLightning ? Html.Raw("⚡") : null) @crypto.CryptoCode @@ -72,18 +72,18 @@ else {
    - + {{srvModel.paymentMethodName}} ({{srvModel.cryptoCodeSrv}})
    } -
    - +
    +
  • -
    +
    {{ srvModel.storeName }} @@ -110,7 +110,7 @@
    {{$t("NotPaid_ExtraTransaction")}}
    -
    +
    {{$t("Order Amount")}}
    {{srvModel.orderAmount}} {{ srvModel.cryptoCode }}
    @@ -146,251 +146,50 @@
    -
    -
    - {{$t("Scan")}} -
    -
    - {{$t("Copy")}} -
    - @if (Model.ChangellyEnabled || Model.CoinSwitchEnabled) - { -
    - {{$t("Conversion")}} -
    -
    - } - else - { -
    - } -
    + +
    -
    -
    -
    - {{$t("Contact and Refund Email")}} -
    -
    - - {{$t("Contact_Body")}} - - {{$t("Please enter a valid email address")}} -
    -
    - - - - -
    -
    -
    -
    - - - - -
    - -
    -
    -
    - -
    -
    -
    - {{$t("This invoice has been archived")}} -
    -
    - {{$t("Archived_Body")}} -
    -
    -
    - -
    +
    diff --git a/BTCPayServer/Views/Invoice/Checkout.cshtml b/BTCPayServer/Views/Invoice/Checkout.cshtml index 0ce8f11fc..763e3aa8a 100644 --- a/BTCPayServer/Views/Invoice/Checkout.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout.cshtml @@ -68,7 +68,7 @@