btcpayserver/BTCPayServer/Models/GetTokensResponse.cs

61 lines
2.1 KiB
C#
Raw Normal View History

2017-09-13 08:47:34 +02:00
using Microsoft.AspNetCore.Mvc;
using System.Linq;
2017-09-13 08:47:34 +02:00
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Authentication;
using NBitcoin.DataEncoders;
using Microsoft.AspNetCore.Http;
using System.IO;
namespace BTCPayServer.Models
{
//{"data":[{"pos":"FfZ6WCa8TunAvPCpQZXkdBsoH4Yo18FyPaJ5X5qjrVVY"},{"pos/invoice":"H1pwwh2tMeSCri9rh5VvHWEHokGdf2EGtghfZkUEbeZv"},{"merchant":"89zEBr9orAc6wgybAABp8ioGcjYeFrUaZgMzjxNuqYty"},{"merchant/invoice":"8e7ijDxGfJsWXWgJuKXjjNgxnX1xpsBM8cTZCFnU7ehj"}]}
public class GetTokensResponse : IActionResult
{
BitTokenEntity[] _Tokens;
public GetTokensResponse(BitTokenEntity[] tokens)
{
if (tokens == null)
throw new ArgumentNullException(nameof(tokens));
this._Tokens = tokens;
}
2017-09-13 08:47:34 +02:00
[JsonProperty(PropertyName = "data")]
//{"pos":"FfZ6WCa8TunAvPCpQZXkdBsoH4Yo18FyPaJ5X5qjrVVY"}
public JArray Data
{
get; set;
}
2017-09-13 08:47:34 +02:00
public async Task ExecuteResultAsync(ActionContext context)
{
JObject jobj = new JObject();
JArray jarray = new JArray();
jobj.Add("data", jarray);
var token = _Tokens.FirstOrDefault();
if (token != null)
{
JObject item = new JObject();
jarray.Add(item);
2019-04-11 16:54:58 +02:00
JProperty jProp = new JProperty("merchant");
item.Add(jProp);
jProp.Value = token.Value;
}
context.HttpContext.Response.Headers.Add("Content-Type", new Microsoft.Extensions.Primitives.StringValues("application/json"));
var str = JsonConvert.SerializeObject(jobj);
2019-10-09 10:06:00 +02:00
#if NETCOREAPP21
using (var writer = new StreamWriter(context.HttpContext.Response.Body, new UTF8Encoding(false), 1024 * 10, true))
2019-10-09 10:06:00 +02:00
#else
await using (var writer = new StreamWriter(context.HttpContext.Response.Body, new UTF8Encoding(false), 1024 * 10, true))
#endif
{
await writer.WriteAsync(str);
}
}
}
2017-09-13 08:47:34 +02:00
}