mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
switch pos to metadata in invoice create view (#5412)
Co-authored-by: d11n <mail@dennisreimann.de>
This commit is contained in:
parent
27c22d5e33
commit
e82281d273
3 changed files with 37 additions and 15 deletions
|
@ -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,
|
||||
|
|
|
@ -44,9 +44,8 @@ namespace BTCPayServer.Models.InvoicingModels
|
|||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[DisplayName("POS Data")]
|
||||
public string PosData
|
||||
[DisplayName("Metadata")]
|
||||
public string Metadata
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
|
|
@ -103,16 +103,16 @@
|
|||
<div class="accordion-item">
|
||||
<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">
|
||||
Point Of Sale Data
|
||||
Metadata
|
||||
<vc:icon symbol="caret-down" />
|
||||
</button>
|
||||
</h2>
|
||||
<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">
|
||||
<label asp-for="PosData" class="form-label"></label>
|
||||
<input asp-for="PosData" class="form-control" />
|
||||
<span asp-validation-for="PosData" class="text-danger"></span>
|
||||
<label asp-for="Metadata" class="form-label"></label>
|
||||
<textarea asp-for="Metadata" class="form-control" rows="10" cols="40"></textarea>
|
||||
<span asp-validation-for="Metadata" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue