From a3ea94c771dcd40e04221e7c9ed067261fdde44f Mon Sep 17 00:00:00 2001 From: NicolasDorier Date: Thu, 14 Sep 2017 01:06:11 +0900 Subject: [PATCH] Improve checkout page --- BTCPayServer/Controllers/InvoiceController.UI.cs | 3 ++- BTCPayServer/Invoicing/InvoiceEntity.cs | 14 ++++++++++++-- BTCPayServer/Invoicing/InvoiceWatcher.cs | 4 ++-- .../Models/InvoicingModels/PaymentModel.cs | 4 ++++ BTCPayServer/Views/Invoice/Checkout.cshtml | 12 +++++++++--- BTCPayServer/Views/Manage/_ManageNav.cshtml | 1 - BTCPayServer/wwwroot/css/normalizer.css | 4 ++-- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index b8753a178..b5e4949d4 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -48,7 +48,8 @@ namespace BTCPayServer.Controllers StoreName = store.StoreName, TxFees = invoice.TxFee.ToString(), InvoiceBitcoinUrl = dto.PaymentUrls.BIP72, - TxCount = invoice.Payments.Count + 1, + TxCount = invoice.GetTxCount(), + BTCPaid = invoice.GetTotalPaid().ToString(), Status = invoice.Status }; diff --git a/BTCPayServer/Invoicing/InvoiceEntity.cs b/BTCPayServer/Invoicing/InvoiceEntity.cs index 4c727bce4..6280b0b68 100644 --- a/BTCPayServer/Invoicing/InvoiceEntity.cs +++ b/BTCPayServer/Invoicing/InvoiceEntity.cs @@ -104,6 +104,12 @@ namespace BTCPayServer.Invoicing { get; set; } + + public int GetTxCount() + { + return Calculate().TxCount; + } + public string OrderId { get; set; @@ -114,10 +120,11 @@ namespace BTCPayServer.Invoicing return Calculate().TotalDue; } - private (Money TotalDue, Money Paid) Calculate() + private (Money TotalDue, Money Paid, int TxCount) Calculate() { var totalDue = Money.Coins((decimal)(ProductInformation.Price / Rate)) + TxFee; var paid = Money.Zero; + int txCount = 1; var payments = Payments .OrderByDescending(p => p.ReceivedTime) @@ -130,11 +137,14 @@ namespace BTCPayServer.Invoicing { var paidEnough = totalDue <= paid; if(!paidEnough) + { + txCount++; totalDue += TxFee; + } return !paidEnough; }) .ToArray(); - return (totalDue, paid); + return (totalDue, paid, txCount); } public Money GetTotalPaid() diff --git a/BTCPayServer/Invoicing/InvoiceWatcher.cs b/BTCPayServer/Invoicing/InvoiceWatcher.cs index 22aa79ae3..ec9c9ea6d 100644 --- a/BTCPayServer/Invoicing/InvoiceWatcher.cs +++ b/BTCPayServer/Invoicing/InvoiceWatcher.cs @@ -71,14 +71,14 @@ namespace BTCPayServer.Invoicing private async Task<(bool NeedSave, UTXOChanges Changes)> UpdateInvoice(UTXOChanges changes, InvoiceEntity invoice) { - if(invoice.Status == "invalid" && (invoice.Status == "new" || invoice.Status == "paidPartial")) + if(invoice.Status == "invalid") { return (false, changes); } bool needSave = false; bool shouldWait = true; - if(invoice.ExpirationTime < DateTimeOffset.UtcNow) + if(invoice.ExpirationTime < DateTimeOffset.UtcNow && (invoice.Status == "new" || invoice.Status == "paidPartial")) { needSave = true; invoice.Status = "invalid"; diff --git a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs index 256189d70..1f19e91c9 100644 --- a/BTCPayServer/Models/InvoicingModels/PaymentModel.cs +++ b/BTCPayServer/Models/InvoicingModels/PaymentModel.cs @@ -90,6 +90,10 @@ namespace BTCPayServer.Models.InvoicingModels { get; set; } + public string BTCPaid + { + get; set; + } public string StoreEmail { get; set; diff --git a/BTCPayServer/Views/Invoice/Checkout.cshtml b/BTCPayServer/Views/Invoice/Checkout.cshtml index 8818fd8a0..bcf440d1e 100644 --- a/BTCPayServer/Views/Invoice/Checkout.cshtml +++ b/BTCPayServer/Views/Invoice/Checkout.cshtml @@ -127,7 +127,7 @@
- @Model.BTCDue + @Model.BTCTotalDue
@@ -152,9 +152,15 @@
@Model.TxCount transaction x @Model.TxFees BTC
+
+
+ Already Paid +
+
-@Model.BTCPaid BTC
+
-
Total
-
@Model.BTCTotalDue BTC
+
Due
+
@Model.BTCDue BTC
diff --git a/BTCPayServer/Views/Manage/_ManageNav.cshtml b/BTCPayServer/Views/Manage/_ManageNav.cshtml index 10a38153c..70fa6131b 100644 --- a/BTCPayServer/Views/Manage/_ManageNav.cshtml +++ b/BTCPayServer/Views/Manage/_ManageNav.cshtml @@ -7,7 +7,6 @@