From 184c797b0e40020dbd5438f3f28f7c32dfb34d85 Mon Sep 17 00:00:00 2001 From: Ludovic Date: Wed, 3 Apr 2019 21:43:53 +0200 Subject: [PATCH] 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, '-'); + } +}