Adding Reference Number to Payment Requests

This commit is contained in:
rockstardev
2025-03-28 22:55:13 -05:00
committed by nicolas.dorier
parent 92e7c7a5f9
commit d2debaa842
5 changed files with 26 additions and 7 deletions

View File

@@ -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))]

View File

@@ -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;

View File

@@ -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<PaymentRequestInvoice>
{
static HashSet<InvoiceState> stateAllowedToDisplay = new HashSet<InvoiceState>
{
new InvoiceState(InvoiceStatus.New, InvoiceExceptionStatus.None),
new InvoiceState(InvoiceStatus.New, InvoiceExceptionStatus.PaidPartial),
};
private static HashSet<InvoiceState> 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<ViewPaymentRequestViewModel.PaymentRequestInvoicePayment>
public static List<PaymentRequestInvoicePayment>
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,

View File

@@ -82,6 +82,11 @@
<label asp-for="AllowCustomPaymentAmounts" class="form-check-label"></label>
<span asp-validation-for="AllowCustomPaymentAmounts" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ReferenceNumber" class="form-label"></label>
<input asp-for="ReferenceNumber" class="form-control" />
<span asp-validation-for="ReferenceNumber" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ExpiryDate" class="form-label"></label>
<div class="input-group ">

View File

@@ -91,6 +91,7 @@
</button>
</div>
</th>
<th text-translate="true">Number</th>
<th text-translate="true">Status</th>
<th class="amount-col" text-translate="true">Amount</th>
<th></th>
@@ -106,6 +107,9 @@
<td class="date-col">
@(item.ExpiryDate?.ToBrowserDate() ?? new HtmlString("<span class=\"text-muted\">No Expiry</span>"))
</td>
<td>
@item.ReferenceNumber
</td>
<td>
<span class="badge badge-@item.Status.ToLower() status-badge">@item.Status</span>
</td>