From 184c797b0e40020dbd5438f3f28f7c32dfb34d85 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Wed, 3 Apr 2019 21:43:53 +0200 Subject: [PATCH 1/6] Add a new Pay Button Type : Custom amount --- BTCPayServer/Controllers/StoresController.cs | 3 +- .../StoreViewModels/PayButtonViewModel.cs | 6 +-- BTCPayServer/Views/Stores/PayButton.cshtml | 35 +++++++++----- BTCPayServer/wwwroot/paybutton/paybutton.js | 46 +++++++++++++++---- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 4335336ea..8f267b8d2 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -891,7 +891,8 @@ namespace BTCPayServer.Controllers ButtonSize = 2, UrlRoot = appUrl, PayButtonImageUrl = appUrl + "img/paybutton/pay.png", - StoreId = store.Id + StoreId = store.Id, + ButtonType = 0 }; return View(model); } diff --git a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs index 2c6687e93..27a649594 100644 --- a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; using BTCPayServer.ModelBinders; using Microsoft.AspNetCore.Mvc; @@ -18,6 +15,7 @@ namespace BTCPayServer.Models.StoreViewModels public string CheckoutDesc { get; set; } public string OrderId { get; set; } public int ButtonSize { get; set; } + public int ButtonType { get; set; } [Url] public string ServerIpn { get; set; } [Url] diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index 215685018..eb0223a77 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -57,6 +57,17 @@ +
+ +
+ + +
+
+ + +
+

@@ -123,20 +134,20 @@
-@section HeadScripts { - - + @section HeadScripts { + + - - + + - + - -} + + } -@section Scripts { - -} + + } diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index a901a14fc..1248218ec 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -22,7 +22,7 @@ function esc(input) { (but it's not necessary). Or for XML, only if the named entities are defined in its DTD. */ - ; + ; } Vue.use(VeeValidate); @@ -42,9 +42,35 @@ function inputChanges(event, buttonSize) { srvModel.buttonSize = buttonSize; } + var width = "209px"; + var widthInput = "3em"; + if (srvModel.buttonSize === 0) { + width = "146px"; + widthInput = "2em"; + } else if (srvModel.buttonSize === 1) { + width = "168px"; + } else if (srvModel.buttonSize === 2) { + width = "209px"; + } + var html = '
'; html += addinput("storeId", srvModel.storeId); - html += addinput("price", srvModel.price); + + // Add price as hidden only if it's a fixed amount + if (srvModel.buttonType == 0) { + html += addinput("price", srvModel.price); + } + else if (srvModel.buttonType == 1) { + html += '\n
'; + html += addPlusMinusButton("-"); + html += ''; // Method to try if it's a number + html += addPlusMinusButton("+"); + html += '
'; + } + if (srvModel.currency) { html += addinput("currency", srvModel.currency); } @@ -65,14 +91,6 @@ function inputChanges(event, buttonSize) { html += addinput("notifyEmail", srvModel.notifyEmail); } - var width = "209px"; - if (srvModel.buttonSize === 0) { - width = "146px"; - } else if (srvModel.buttonSize === 1) { - width = "168px"; - } else if (srvModel.buttonSize === 2) { - width = "209px"; - } html += '\n '; @@ -93,3 +111,11 @@ function addinput(name, value) { return html; } +function addPlusMinusButton(type) { + var button = ''; + if (type === "+") { + return button.replace(/TYPE/g, '+'); + } else { + return button.replace(/TYPE/g, '-'); + } +} From 449066449b1d8d976dd55a7855782e8a9ab70193 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Thu, 4 Apr 2019 20:56:12 +0200 Subject: [PATCH 2/6] Add a new Pay Button Type : Slider --- BTCPayServer/Controllers/StoresController.cs | 7 ++-- .../StoreViewModels/PayButtonViewModel.cs | 6 ++++ BTCPayServer/Views/Stores/PayButton.cshtml | 27 ++++++++++++++++ BTCPayServer/wwwroot/paybutton/paybutton.js | 32 ++++++++++++++++--- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 8f267b8d2..a42c51102 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -507,7 +507,7 @@ namespace BTCPayServer.Controllers Action = nameof(UpdateChangellySettings), Provider = "Changelly" }); - + var coinSwitchEnabled = storeBlob.CoinSwitchSettings != null && storeBlob.CoinSwitchSettings.Enabled; vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.ThirdPartyPaymentMethod() { @@ -892,7 +892,10 @@ namespace BTCPayServer.Controllers UrlRoot = appUrl, PayButtonImageUrl = appUrl + "img/paybutton/pay.png", StoreId = store.Id, - ButtonType = 0 + ButtonType = 2, + Min = 1, + Max = 20, + Step = 1 }; return View(model); } diff --git a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs index 27a649594..dc5c1ea23 100644 --- a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs @@ -16,6 +16,12 @@ namespace BTCPayServer.Models.StoreViewModels public string OrderId { get; set; } public int ButtonSize { get; set; } public int ButtonType { get; set; } + + // Slider properties (ButtonType = 2) + public decimal Min { get; set; } + public decimal Max { get; set; } + public decimal Step { get; set; } + [Url] public string ServerIpn { get; set; } [Url] diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index eb0223a77..992df92d4 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -23,6 +23,29 @@ :class="{'is-invalid': errors.has('currency') }"> +
+
+ + + {{ errors.first('min') }} +
+
+ + + {{ errors.first('max') }} +
+
+ + + {{ errors.first('step') }} +
+
+
+ + +
diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index 1248218ec..91e39d3af 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -56,20 +56,31 @@ function inputChanges(event, buttonSize) { var html = ''; html += addinput("storeId", srvModel.storeId); - // Add price as hidden only if it's a fixed amount + // Add price as hidden only if it's a fixed amount (srvModel.buttonType = 0) if (srvModel.buttonType == 0) { html += addinput("price", srvModel.price); } else if (srvModel.buttonType == 1) { html += '\n
'; html += addPlusMinusButton("-"); - html += ''; // Method to try if it's a number + html += addInputPrice(srvModel.price, widthInput, ""); html += addPlusMinusButton("+"); html += '
'; } + else if (srvModel.buttonType == 2) { + html += '\n
'; + + // Input price + html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"'); + + // Slider + html += ''; + + // Slider style + html += ''; + html += '
'; + } if (srvModel.currency) { html += addinput("currency", srvModel.currency); @@ -119,3 +130,14 @@ function addPlusMinusButton(type) { return button.replace(/TYPE/g, '-'); } } + +function addInputPrice(price, widthInput, customFn) { + var input = ''; + if (customFn) { + return input.replace("CUSTOM", customFn); + } + return input.replace("CUSTOM", ""); +} From bc97c076707e5982fe8dc7ec1f37c5d4d29d1bb0 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Thu, 4 Apr 2019 21:32:16 +0200 Subject: [PATCH 3/6] Add currency select in Pay Button --- BTCPayServer/Controllers/StoresController.cs | 2 +- BTCPayServer/Views/Stores/PayButton.cshtml | 2 +- BTCPayServer/wwwroot/paybutton/paybutton.js | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index a42c51102..831045d58 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -892,7 +892,7 @@ namespace BTCPayServer.Controllers UrlRoot = appUrl, PayButtonImageUrl = appUrl + "img/paybutton/pay.png", StoreId = store.Id, - ButtonType = 2, + ButtonType = 0, Min = 1, Max = 20, Step = 1 diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index 992df92d4..946fb016c 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -18,7 +18,7 @@
-
diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index 91e39d3af..047aaae90 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -62,17 +62,20 @@ function inputChanges(event, buttonSize) { } else if (srvModel.buttonType == 1) { html += '\n
'; + html += '
'; html += addPlusMinusButton("-"); html += addInputPrice(srvModel.price, widthInput, ""); html += addPlusMinusButton("+"); html += '
'; + html += addSelectCurrency(); + html += '
'; } else if (srvModel.buttonType == 2) { html += '\n
'; // Input price html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"'); - + html += addSelectCurrency(); // Slider html += ''; @@ -134,10 +137,19 @@ function addPlusMinusButton(type) { function addInputPrice(price, widthInput, customFn) { var input = ''; if (customFn) { return input.replace("CUSTOM", customFn); } return input.replace("CUSTOM", ""); } + +function addSelectCurrency() { + return ''; +} From a8a857a7ce1b0fe59a91fe5252181bc72a5485fd Mon Sep 17 00:00:00 2001 From: Ludovic Date: Sat, 6 Apr 2019 13:47:22 +0200 Subject: [PATCH 4/6] Move Slider settings below radio buttons --- BTCPayServer/Views/Stores/PayButton.cshtml | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index 946fb016c..244760271 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -23,29 +23,6 @@ :class="{'is-invalid': errors.has('currency') }">
-
-
- - - {{ errors.first('min') }} -
-
- - - {{ errors.first('max') }} -
-
- - - {{ errors.first('step') }} -
-
Slider
+
+
+ + + {{ errors.first('min') }} +
+
+ + + {{ errors.first('max') }} +
+
+ + + {{ errors.first('step') }} +
+

From 7e0211924d4ad441b2d267f7f5bf6932b38236c8 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Sat, 6 Apr 2019 15:02:02 +0200 Subject: [PATCH 5/6] Replace inline js by templates in pay button --- BTCPayServer/Views/Stores/PayButton.cshtml | 44 +++++++++++++++------ BTCPayServer/wwwroot/paybutton/paybutton.js | 37 +++++++++-------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index 244760271..f5cc179e8 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -159,22 +159,22 @@ Please fix errors shown in order for code generation to successfully execute.
+ +@section HeadScripts { + + - @section HeadScripts { - - + + - - + - + +} - - } - - @section Scripts { - - } + +} + + + + + + + + + diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index 047aaae90..eda819f62 100644 --- a/BTCPayServer/wwwroot/paybutton/paybutton.js +++ b/BTCPayServer/wwwroot/paybutton/paybutton.js @@ -72,16 +72,9 @@ function inputChanges(event, buttonSize) { } else if (srvModel.buttonType == 2) { html += '\n
'; - - // Input price html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"'); html += addSelectCurrency(); - // Slider - html += ''; - - // Slider style - html += ''; + html += addSlider(srvModel.price, srvModel.min, srvModel.max, srvModel.step, width); html += '
'; } @@ -126,7 +119,7 @@ function addinput(name, value) { } function addPlusMinusButton(type) { - var button = ''; + var button = document.getElementById('template-button-plus-minus').innerHTML.trim(); if (type === "+") { return button.replace(/TYPE/g, '+'); } else { @@ -135,10 +128,11 @@ function addPlusMinusButton(type) { } function addInputPrice(price, widthInput, customFn) { - var input = ''; + var input = document.getElementById('template-input-price').innerHTML.trim(); + + input = input.replace(/PRICEVALUE/g, price); + input = input.replace("WIDTHINPUT", widthInput); + if (customFn) { return input.replace("CUSTOM", customFn); } @@ -146,10 +140,15 @@ function addInputPrice(price, widthInput, customFn) { } function addSelectCurrency() { - return ''; + return document.getElementById('template-select-currency').innerHTML.trim(); +} + +function addSlider(price, min, max, step, width) { + var input = document.getElementById('template-input-slider').innerHTML.trim(); + input = input.replace("PRICE", price); + input = input.replace("MIN", min); + input = input.replace("MAX", max); + input = input.replace("STEP", step); + input = input.replace("WIDTH", width); + return input; } From 0bf73abb395823db91ffc2125e3cd8f16f0e7ba5 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Sat, 6 Apr 2019 15:22:09 +0200 Subject: [PATCH 6/6] Fix Custom amount under 0 in Pay button --- BTCPayServer/Views/Stores/PayButton.cshtml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/BTCPayServer/Views/Stores/PayButton.cshtml b/BTCPayServer/Views/Stores/PayButton.cshtml index f5cc179e8..87c4a9b50 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -195,13 +195,12 @@ -