From d2debaa84292282eea4cfbff2fe7b7aec0053e3d Mon Sep 17 00:00:00 2001 From: rockstardev <5191402+rockstardev@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:55:13 -0500 Subject: [PATCH 1/8] Adding Reference Number to Payment Requests --- .../Models/PaymentRequestBaseData.cs | 2 ++ .../Controllers/UIPaymentRequestController.cs | 1 + .../ListPaymentRequestsViewModel.cs | 21 ++++++++++++------- .../EditPaymentRequest.cshtml | 5 +++++ .../GetPaymentRequests.cshtml | 4 ++++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/BTCPayServer.Client/Models/PaymentRequestBaseData.cs b/BTCPayServer.Client/Models/PaymentRequestBaseData.cs index d425f61d0..8856e57b5 100644 --- a/BTCPayServer.Client/Models/PaymentRequestBaseData.cs +++ b/BTCPayServer.Client/Models/PaymentRequestBaseData.cs @@ -37,6 +37,8 @@ namespace BTCPayServer.Client.Models public string Title { get; set; } public string Description { get; set; } public string Email { get; set; } + // Allow payment requests to be linked to invoices outside BTCPay Server using Reference Number + public string ReferenceNumber { get; set; } public bool AllowCustomPaymentAmounts { get; set; } [JsonConverter(typeof(StringEnumConverter))] diff --git a/BTCPayServer/Controllers/UIPaymentRequestController.cs b/BTCPayServer/Controllers/UIPaymentRequestController.cs index 192347685..1ac3663cd 100644 --- a/BTCPayServer/Controllers/UIPaymentRequestController.cs +++ b/BTCPayServer/Controllers/UIPaymentRequestController.cs @@ -206,6 +206,7 @@ namespace BTCPayServer.Controllers data.Amount = viewModel.Amount; data.Currency = viewModel.Currency ?? store.GetStoreBlob().DefaultCurrency; data.Expiry = viewModel.ExpiryDate?.ToUniversalTime(); + blob.ReferenceNumber = viewModel.ReferenceNumber; blob.AllowCustomPaymentAmounts = viewModel.AllowCustomPaymentAmounts; blob.FormId = viewModel.FormId; diff --git a/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs b/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs index c1c000c44..7600af000 100644 --- a/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs +++ b/BTCPayServer/Models/PaymentRequestViewModels/ListPaymentRequestsViewModel.cs @@ -48,6 +48,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels Description = blob.Description; ExpiryDate = data.Expiry?.UtcDateTime; Email = blob.Email; + ReferenceNumber = blob.ReferenceNumber; AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts; FormResponse = blob.FormResponse is null ? null @@ -84,6 +85,10 @@ namespace BTCPayServer.Models.PaymentRequestViewModels [MailboxAddress] public string Email { get; set; } + [Display(Name = "Reference Number")] + [MaxLength(50)] + public string ReferenceNumber { get; set; } + [Display(Name = "Allow payee to create invoices with custom amounts")] public bool AllowCustomPaymentAmounts { get; set; } @@ -106,6 +111,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels Description = blob.Description; ExpiryDate = data.Expiry?.UtcDateTime; Email = blob.Email; + ReferenceNumber = blob.ReferenceNumber; AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts; switch (data.Status) { @@ -127,6 +133,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels } } public StoreBrandingViewModel StoreBranding { get; set; } + public string ReferenceNumber { get; set; } public bool AllowCustomPaymentAmounts { get; set; } public string Email { get; set; } public string Status { get; set; } @@ -147,11 +154,11 @@ namespace BTCPayServer.Models.PaymentRequestViewModels #nullable enable public class InvoiceList : List { - static HashSet stateAllowedToDisplay = new HashSet - { - new InvoiceState(InvoiceStatus.New, InvoiceExceptionStatus.None), - new InvoiceState(InvoiceStatus.New, InvoiceExceptionStatus.PaidPartial), - }; + private static HashSet stateAllowedToDisplay = + [ + new(InvoiceStatus.New, InvoiceExceptionStatus.None), + new(InvoiceStatus.New, InvoiceExceptionStatus.PaidPartial) + ]; public InvoiceList() { @@ -195,7 +202,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels public class PaymentRequestInvoicePayment { - public static List + public static List GetViewModels( InvoiceEntity invoice, DisplayFormatter displayFormatter, @@ -215,7 +222,7 @@ namespace BTCPayServer.Models.PaymentRequestViewModels string link = paymentMethodId is null ? null : txLinkProvider.GetTransactionLink(paymentMethodId, txId); - return new ViewPaymentRequestViewModel.PaymentRequestInvoicePayment + return new PaymentRequestInvoicePayment { Amount = paymentEntity.PaidAmount.Gross, Paid = paymentEntity.InvoicePaidAmount.Net, diff --git a/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml b/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml index 0c56a10a7..1cf5fbc20 100644 --- a/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml +++ b/BTCPayServer/Views/UIPaymentRequest/EditPaymentRequest.cshtml @@ -82,6 +82,11 @@ +
+ + + +
diff --git a/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml b/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml index afdfc41ce..2ca3f637d 100644 --- a/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml +++ b/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml @@ -91,6 +91,7 @@
+ Number Status Amount @@ -106,6 +107,9 @@ @(item.ExpiryDate?.ToBrowserDate() ?? new HtmlString("No Expiry")) + + @item.ReferenceNumber + @item.Status From fdde3096d0e48a8d932963702cafb5f0e8022e0e Mon Sep 17 00:00:00 2001 From: rockstardev <5191402+rockstardev@users.noreply.github.com> Date: Fri, 28 Mar 2025 23:10:29 -0500 Subject: [PATCH 2/8] Allowing copying of Payment Request URL --- BTCPayServer/Services/CallbackGenerator.cs | 12 ++++++++++++ .../Views/UIPaymentRequest/GetPaymentRequests.cshtml | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/BTCPayServer/Services/CallbackGenerator.cs b/BTCPayServer/Services/CallbackGenerator.cs index 015af6280..42ccbbb38 100644 --- a/BTCPayServer/Services/CallbackGenerator.cs +++ b/BTCPayServer/Services/CallbackGenerator.cs @@ -92,5 +92,17 @@ namespace BTCPayServer.Services pathBase: request.PathBase ) ?? throw Bug(); } + + public string PaymentRequestLink(string payReqId, HttpRequest request) + { + return LinkGenerator.GetUriByAction( + action: nameof(UIPaymentRequestController.ViewPaymentRequest), + controller: "UIPaymentRequest", + values: new { payReqId }, + scheme: request.Scheme, + host: request.Host, + pathBase: request.PathBase + ) ?? throw Bug(); + } } } diff --git a/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml b/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml index 2ca3f637d..b1e59a755 100644 --- a/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml +++ b/BTCPayServer/Views/UIPaymentRequest/GetPaymentRequests.cshtml @@ -3,6 +3,9 @@ @using Microsoft.AspNetCore.Mvc.TagHelpers @using BTCPayServer.Components @using BTCPayServer.Client +@using BTCPayServer.Services +@using BTCPayServer.TagHelpers +@inject CallbackGenerator CallbackGenerator @model BTCPayServer.Models.PaymentRequestViewModels.ListPaymentRequestsViewModel @{ Layout = "_Layout"; @@ -119,6 +122,11 @@
View +