mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
switch pos to metadata in invoice create view (#5412)
Co-authored-by: d11n <mail@dennisreimann.de>
This commit is contained in:
@@ -1258,6 +1258,19 @@ namespace BTCPayServer.Controllers
|
|||||||
model.CheckoutType = storeBlob.CheckoutType;
|
model.CheckoutType = storeBlob.CheckoutType;
|
||||||
model.AvailablePaymentMethods = GetPaymentMethodsSelectList();
|
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)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
return View(model);
|
return View(model);
|
||||||
@@ -1276,17 +1289,27 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
try
|
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()
|
var result = await CreateInvoiceCoreRaw(new CreateInvoiceRequest()
|
||||||
{
|
{
|
||||||
Amount = model.Amount,
|
Amount = model.Amount,
|
||||||
Currency = model.Currency,
|
Currency = model.Currency,
|
||||||
Metadata = new InvoiceMetadata()
|
Metadata = metadata.ToJObject(),
|
||||||
{
|
|
||||||
PosDataLegacy = model.PosData,
|
|
||||||
OrderId = model.OrderId,
|
|
||||||
ItemDesc = model.ItemDesc,
|
|
||||||
BuyerEmail = model.BuyerEmail,
|
|
||||||
}.ToJObject(),
|
|
||||||
Checkout = new ()
|
Checkout = new ()
|
||||||
{
|
{
|
||||||
RedirectURL = store.StoreWebsite,
|
RedirectURL = store.StoreWebsite,
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
[DisplayName("Metadata")]
|
||||||
[DisplayName("POS Data")]
|
public string Metadata
|
||||||
public string PosData
|
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,16 +103,16 @@
|
|||||||
<div class="accordion-item">
|
<div class="accordion-item">
|
||||||
<h2 class="accordion-header" id="additional-pos-data-header">
|
<h2 class="accordion-header" id="additional-pos-data-header">
|
||||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#additional-pos-data" aria-expanded="false" aria-controls="additional-pos-data">
|
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#additional-pos-data" aria-expanded="false" aria-controls="additional-pos-data">
|
||||||
Point Of Sale Data
|
Metadata
|
||||||
<vc:icon symbol="caret-down" />
|
<vc:icon symbol="caret-down" />
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</h2>
|
||||||
<div id="additional-pos-data" class="accordion-collapse collapse" aria-labelledby="additional-pos-data-header">
|
<div id="additional-pos-data" class="accordion-collapse collapse" aria-labelledby="additional-pos-data-header">
|
||||||
<p>Custom data to correlate the invoice with an order. This data can be a simple text, number or JSON object, e.g. <code>{ "orderId": 615, "product": "Pizza" }</code></p>
|
<p>Custom data to expand the invoice. This data is a JSON object, e.g. <code>{ "orderId": 615, "product": "Pizza" }</code></p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label asp-for="PosData" class="form-label"></label>
|
<label asp-for="Metadata" class="form-label"></label>
|
||||||
<input asp-for="PosData" class="form-control" />
|
<textarea asp-for="Metadata" class="form-control" rows="10" cols="40"></textarea>
|
||||||
<span asp-validation-for="PosData" class="text-danger"></span>
|
<span asp-validation-for="Metadata" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user