Files
btcpayserver/BTCPayServer/Models/InvoicingModels/ExportInvoicesModel.cs
Rockstar Developer c2bbc04c4c Various bugfixes (#308)
* NotifyEmail field on Invoice, sending email when triggered

* Styling invoices page

* Exporting Invoices in JSON

* Recoding based on feedback

* Fixing image breaking responsive layout on mobile

* Reducing amount of data sent in email notification

* Turning bundling on by default
2018-10-12 10:09:13 +09:00

43 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Services.Invoices;
using Newtonsoft.Json;
namespace BTCPayServer.Models.InvoicingModels
{
public class ExportInvoicesModel
{
public InvoiceEntity[] Invoices { get; set; }
public string Format { get; set; }
public string Process()
{
if (String.Equals(Format, "json", StringComparison.OrdinalIgnoreCase))
return processJson();
else
throw new Exception("Export format not supported");
}
private string processJson()
{
foreach (var i in Invoices)
{
// removing error causing complex circular dependencies
i.Payments?.ForEach(a =>
{
a.Output = null;
a.Outpoint = null;
});
}
var serializerSett = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
var json = JsonConvert.SerializeObject(new { Invoices }, Formatting.Indented, serializerSett);
return json;
}
}
}