diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 34c57f70e..a9275891d 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -133,28 +133,30 @@ namespace BTCPayServer.Controllers var model = new PaymentModel() { - ServerUrl = HttpContext.Request.GetAbsoluteRoot(), + serverUrl = HttpContext.Request.GetAbsoluteRoot(), OrderId = invoice.OrderId, - InvoiceId = invoice.Id, - BTCAddress = invoice.DepositAddress.ToString(), + invoiceId = invoice.Id, + btcAddress = invoice.DepositAddress.ToString(), BTCAmount = (invoice.GetTotalCryptoDue() - invoice.TxFee).ToString(), BTCTotalDue = invoice.GetTotalCryptoDue().ToString(), - BTCDue = invoice.GetCryptoDue().ToString(), - CustomerEmail = invoice.RefundMail, - ExpirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds), - MaxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds, + btcDue = invoice.GetCryptoDue().ToString(), + customerEmail = invoice.RefundMail, + expirationSeconds = Math.Max(0, (int)(invoice.ExpirationTime - DateTimeOffset.UtcNow).TotalSeconds), + maxTimeSeconds = (int)(invoice.ExpirationTime - invoice.InvoiceTime).TotalSeconds, ItemDesc = invoice.ProductInformation.ItemDesc, Rate = invoice.Rate.ToString("C", GetCurrencyProvider(invoice.ProductInformation.Currency)), - RedirectUrl = invoice.RedirectURL, + merchantRefLink = invoice.RedirectURL, StoreName = store.StoreName, TxFees = invoice.TxFee.ToString(), InvoiceBitcoinUrl = dto.PaymentUrls.BIP72, TxCount = invoice.GetTxCount(), BTCPaid = invoice.GetTotalPaid().ToString(), - Status = invoice.Status + status = invoice.Status }; - var expiration = TimeSpan.FromSeconds((double)model.ExpirationSeconds); + + + var expiration = TimeSpan.FromSeconds((double)model.expirationSeconds); model.TimeLeft = PrettyPrint(expiration); return View(nameof(Checkout), model); } diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index f10f39e12..0e5bb2eb3 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -5,106 +5,38 @@ using System.Threading.Tasks; namespace BTCPayServer.Models.InvoicingModels { - public class PaymentModel - { - public string InvoiceId - { - get; set; - } - public string ServerUrl - { - get; set; - } + // going with lowercase for property names to enable easy ToJson conversion + // down the road I can look into mapper who transforms capital into lower case + // because of different conventions between server and client side + public class PaymentModel + { + public string serverUrl { get; set; } + public string invoiceId { get; set; } + public string btcAddress { get; set; } + public string btcDue { get; set; } + public string customerEmail { get; set; } + public int expirationSeconds { get; set; } + public string status { get; set; } + public string merchantRefLink { get; set; } + public int maxTimeSeconds { get; set; } + + // These properties are still not used in client side code + // so will stick with C# notation for now + public string StoreName { get; set; } + public string ItemDesc { get; set; } + public string TimeLeft { get; set; } + public string Rate { get; set; } + public string BTCAmount { get; set; } + public string TxFees { get; set; } + public string InvoiceBitcoinUrl { get; set; } + public string BTCTotalDue { get; set; } + public int TxCount { get; set; } + public string BTCPaid { get; set; } + public string StoreEmail { get; set; } + public string OrderId { get; set; } - public string BTCAddress - { - get; set; - } - - public string BTCDue - { - get; set; - } - - public string CustomerEmail - { - get; set; - } - - public int ExpirationSeconds - { - get; set; - } - - public int MaxTimeSeconds - { - get; set; - } - - public string TimeLeft - { - get; set; - } - - public string RedirectUrl - { - get; set; - } - - - public string StoreName - { - get; set; - } - - public string ItemDesc - { - get; set; - } - - public string Rate - { - get; set; - } - - public string BTCAmount - { - get; set; - } - - public string TxFees - { - get; set; - } - public string InvoiceBitcoinUrl - { - get; - internal set; - } - public string BTCTotalDue - { - get; - set; - } - public int TxCount - { - get; set; - } - public string BTCPaid - { - get; set; - } - public string StoreEmail - { - get; set; - } - public string Status - { - get; - set; - } } } diff --git a/BTCPayServer/Views/Invoice/Checkout.cshtml b/BTCPayServer/Views/Invoice/Checkout.cshtml index 66a16f201..c543123eb 100644 --- a/BTCPayServer/Views/Invoice/Checkout.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout.cshtml @@ -27,23 +27,7 @@ crossorigin="anonymous"> @@ -160,7 +144,7 @@
Due
-
@Model.BTCDue BTC
+
@Model.btcDue BTC
@@ -379,7 +363,7 @@
Amount
- @Model.BTCDue BTC + @Model.btcDue BTC
Copied
@@ -398,7 +382,7 @@ -
@Model.BTCAddress
+
@Model.btcAddress
Copied @@ -536,7 +520,7 @@ hours.
- Invoice ID: @Model.InvoiceId
+ Invoice ID: @Model.invoiceId
Order ID: @Model.OrderId diff --git a/BTCPayServer/Views/_ViewImports.cshtml b/BTCPayServer/Views/_ViewImports.cshtml index a10adaa90..1531eefdd 100644 --- a/BTCPayServer/Views/_ViewImports.cshtml +++ b/BTCPayServer/Views/_ViewImports.cshtml @@ -5,4 +5,5 @@ @using BTCPayServer.Models.InvoicingModels @using BTCPayServer.Models.ManageViewModels @using BTCPayServer.Models.StoreViewModels +@using Newtonsoft.Json; @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/BTCPayServer/wwwroot/js/core.js b/BTCPayServer/wwwroot/js/core.js index 08a17b117..20afbac90 100644 --- a/BTCPayServer/wwwroot/js/core.js +++ b/BTCPayServer/wwwroot/js/core.js @@ -33,12 +33,12 @@ var display = $(".timer-row__time-left"); // Timer container // check if the Document expired -if (expirationTime > 0) { +if (srvModel.expirationSeconds > 0) { - progressStart(maxTime); // Progress bar - startTimer(expirationTime, display); // Timer + progressStart(srvModel.maxTimeSeconds); // Progress bar + startTimer(srvModel.expirationSeconds, display); // Timer - if (!validateEmail(customerEmail)) + if (!validateEmail(srvModel.customerEmail)) emailForm(); // Email form Display else hideEmailForm(); @@ -48,9 +48,9 @@ if (expirationTime > 0) { function hideEmailForm() { $("[role=document]").removeClass("enter-purchaser-email"); $("#emailAddressView").removeClass("active"); - $("placeholder-refundEmail").html(customerEmail); + $("placeholder-refundEmail").html(srvModel.customerEmail); // to generate a QR-Code : $().qrcode("1Dut19quHiJrXEwfmig4hB8RyLss5aTRTC"); - $('.qr-codes').qrcode(btcAddress); + $('.qr-codes').qrcode(srvModel.btcAddress); // Remove Email mode $(".modal-dialog").removeClass("enter-purchaser-email"); @@ -67,14 +67,14 @@ function emailForm() { if (validateEmail(emailAddress)) { $("#emailAddressForm .input-wrapper bp-loading-button .action-button").addClass("loading"); // Push the email to a server, once the reception is confirmed move on - customerEmail = emailAddress; + srvModel.customerEmail = emailAddress; - var path = serverUrl + "/i/" + invoiceId + "/UpdateCustomer"; + var path = srvModel.serverUrl + "/i/" + srvModel.invoiceId + "/UpdateCustomer"; $.ajax({ url: path, type: "POST", - data: JSON.stringify({ Email: customerEmail }), + data: JSON.stringify({ Email: srvModel.customerEmail }), contentType: "application/json; charset=utf-8" }).done(function () { hideEmailForm(); @@ -94,7 +94,7 @@ function emailForm() { } // Copy Tab Info -$("#copy .manual__step-two__instructions span").html("To complete your payment, please send " + btcDue + " BTC to the address below."); +$("#copy .manual__step-two__instructions span").html("To complete your payment, please send " + srvModel.btcDue + " BTC to the address below."); /* =============== Even listeners =============== */ @@ -155,30 +155,28 @@ $("#copy-tab").click(function () { // Should connect using webhook ? // If notification received -var oldStatus = status; -updateState(status); +var oldStat = srvModel.status; +onDataCallback(srvModel.status); -function updateState(status) { - if (oldStatus != status) - { - oldStatus = status; - window.parent.postMessage({ "invoiceId": invoiceId, "status": status }, "*"); +function onDataCallback(newStatus) { + if (oldStat != newStatus) { + oldStat = newStatus; + window.parent.postMessage({ "invoiceId": srvModel.invoiceId, "status": newStatus }, "*"); } - if (status == "complete" || - status == "paidOver" || - status == "confirmed" || - status =="paid") { + if (newStatus == "complete" || + newStatus == "paidOver" || + newStatus == "confirmed" || + newStatus == "paid") { if ($(".modal-dialog").hasClass("expired")) { $(".modal-dialog").removeClass("expired"); } - if (merchantRefLink != "") { + if (srvModel.merchantRefLink != "") { $(".action-button").click(function () { - window.location.href = merchantRefLink; + window.location.href = srvModel.merchantRefLink; }); } - else - { + else { $(".action-button").hide(); } @@ -192,7 +190,7 @@ function updateState(status) { $("#paid").addClass("active"); } - if (status == "invalid") { + if (newStatus == "invalid") { $(".timer-row").removeClass("expiring-soon"); $(".timer-row__message span").html("Invoice expired."); $(".timer-row__spinner").html(""); @@ -203,17 +201,16 @@ function updateState(status) { } var watcher = setInterval(function () { - var path = serverUrl + "/i/" + invoiceId + "/status"; + var path = srvModel.serverUrl + "/i/" + srvModel.invoiceId + "/status"; $.ajax({ url: path, type: "GET" }).done(function (data) { status = data; - updateState(status); - }) - .fail(function (jqXHR, textStatus, errorThrown) { + onDataCallback(status); + }).fail(function (jqXHR, textStatus, errorThrown) { - }); + }); }, 2000); $(".menu__item").click(function () { @@ -255,11 +252,11 @@ function startTimer(duration, display) { } // Progress bar -function progressStart(maxTime) { +function progressStart(timerMax) { var end = new Date(); // Setup Time Variable, should come from server - end.setSeconds(end.getSeconds() + expirationTime); - maxTime *= 1000; // Usually 15 minutes = 9000 second= 900000 ms - var timeoutVal = Math.floor(maxTime / 100); // Timeout calc + end.setSeconds(end.getSeconds() + srvModel.expirationSeconds); + timerMax *= 1000; // Usually 15 minutes = 9000 second= 900000 ms + var timeoutVal = Math.floor(timerMax / 100); // Timeout calc animateUpdate(); //Launch it function updateProgress(percentage) { @@ -270,7 +267,7 @@ function progressStart(maxTime) { var now = new Date(); var timeDiff = end.getTime() - now.getTime(); - var perc = 100 - Math.round((timeDiff / maxTime) * 100); + var perc = 100 - Math.round((timeDiff / timerMax) * 100); if (perc === 75 && (status == "paidPartial" || status == "new")) { $(".timer-row").addClass("expiring-soon"); @@ -282,7 +279,7 @@ function progressStart(maxTime) { setTimeout(animateUpdate, timeoutVal); } if (perc >= 100 && status == "expired") { - updateState(status); + onDataCallback(status); } } } @@ -313,4 +310,5 @@ $(document).keypress( if (event.which === '13') { event.preventDefault(); } - }); + } +);