diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index b9f57bd52..b973be1f0 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -1258,6 +1258,19 @@ namespace BTCPayServer.Controllers model.CheckoutType = storeBlob.CheckoutType; model.AvailablePaymentMethods = GetPaymentMethodsSelectList(); + JObject? metadataObj = null; + if (!string.IsNullOrEmpty(model.Metadata)) + { + try + { + metadataObj = JObject.Parse(model.Metadata); + } + catch (Exception e) + { + ModelState.AddModelError(nameof(model.Metadata), "Metadata was not valid JSON"); + } + } + if (!ModelState.IsValid) { return View(model); @@ -1276,17 +1289,27 @@ namespace BTCPayServer.Controllers try { + var metadata = metadataObj is null ? new InvoiceMetadata() : InvoiceMetadata.FromJObject(metadataObj); + if (!string.IsNullOrEmpty(model.OrderId)) + { + metadata.OrderId = model.OrderId; + } + + if (!string.IsNullOrEmpty(model.ItemDesc)) + { + metadata.ItemDesc = model.ItemDesc; + } + + if (!string.IsNullOrEmpty(model.BuyerEmail)) + { + metadata.BuyerEmail = model.BuyerEmail; + } + var result = await CreateInvoiceCoreRaw(new CreateInvoiceRequest() { Amount = model.Amount, Currency = model.Currency, - Metadata = new InvoiceMetadata() - { - PosDataLegacy = model.PosData, - OrderId = model.OrderId, - ItemDesc = model.ItemDesc, - BuyerEmail = model.BuyerEmail, - }.ToJObject(), + Metadata = metadata.ToJObject(), Checkout = new () { RedirectURL = store.StoreWebsite, diff --git a/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs b/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs index 105e0b663..510c23141 100644 --- a/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs +++ b/BTCPayServer/Models/InvoicingModels/CreateInvoiceModel.cs @@ -44,9 +44,8 @@ namespace BTCPayServer.Models.InvoicingModels { get; set; } - - [DisplayName("POS Data")] - public string PosData + [DisplayName("Metadata")] + public string Metadata { get; set; } diff --git a/BTCPayServer/Views/UIInvoice/CreateInvoice.cshtml b/BTCPayServer/Views/UIInvoice/CreateInvoice.cshtml index bc79960d2..ae5141762 100644 --- a/BTCPayServer/Views/UIInvoice/CreateInvoice.cshtml +++ b/BTCPayServer/Views/UIInvoice/CreateInvoice.cshtml @@ -103,16 +103,16 @@
Custom data to correlate the invoice with an order. This data can be a simple text, number or JSON object, e.g. { "orderId": 615, "product": "Pizza" }
Custom data to expand the invoice. This data is a JSON object, e.g. { "orderId": 615, "product": "Pizza" }