diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 4335336ea..831045d58 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() { @@ -891,7 +891,11 @@ namespace BTCPayServer.Controllers ButtonSize = 2, UrlRoot = appUrl, PayButtonImageUrl = appUrl + "img/paybutton/pay.png", - StoreId = store.Id + StoreId = store.Id, + ButtonType = 0, + Min = 1, + Max = 20, + Step = 1 }; return View(model); } diff --git a/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs b/BTCPayServer/Models/StoreViewModels/PayButtonViewModel.cs index 2c6687e93..dc5c1ea23 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,13 @@ namespace BTCPayServer.Models.StoreViewModels public string CheckoutDesc { get; set; } 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 215685018..87c4a9b50 100644 --- a/BTCPayServer/Views/Stores/PayButton.cshtml +++ b/BTCPayServer/Views/Stores/PayButton.cshtml @@ -18,7 +18,7 @@
-
@@ -57,6 +57,44 @@ +
+ +
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + {{ errors.first('min') }} +
+
+ + + {{ errors.first('max') }} +
+
+ + + {{ errors.first('step') }} +
+

@@ -121,7 +159,7 @@ Please fix errors shown in order for code generation to successfully execute.
- + @section HeadScripts { @@ -152,3 +190,20 @@ }); } + + + + + + + + diff --git a/BTCPayServer/wwwroot/paybutton/paybutton.js b/BTCPayServer/wwwroot/paybutton/paybutton.js index a901a14fc..eda819f62 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,42 @@ 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 (srvModel.buttonType = 0) + if (srvModel.buttonType == 0) { + html += addinput("price", srvModel.price); + } + 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
'; + html += addInputPrice(srvModel.price, width, 'onchange="document.querySelector(\'#btcpay-input-range\').value = document.querySelector(\'#btcpay-input-price\').value"'); + html += addSelectCurrency(); + html += addSlider(srvModel.price, srvModel.min, srvModel.max, srvModel.step, width); + html += '
'; + } + if (srvModel.currency) { html += addinput("currency", srvModel.currency); } @@ -65,14 +98,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 +118,37 @@ function addinput(name, value) { return html; } +function addPlusMinusButton(type) { + var button = document.getElementById('template-button-plus-minus').innerHTML.trim(); + if (type === "+") { + return button.replace(/TYPE/g, '+'); + } else { + return button.replace(/TYPE/g, '-'); + } +} + +function addInputPrice(price, widthInput, customFn) { + 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); + } + return input.replace("CUSTOM", ""); +} + +function addSelectCurrency() { + 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; +}