btcpayserver/BTCPayServer/Models/GetTokensResponse.cs

51 lines
1.8 KiB
C#
Raw Normal View History

2020-06-29 04:44:35 +02:00
using System;
2020-06-28 10:55:27 +02:00
using System.IO;
using System.Linq;
2017-09-13 08:47:34 +02:00
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Security.Bitpay;
2020-06-28 10:55:27 +02:00
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
2017-09-13 08:47:34 +02:00
namespace BTCPayServer.Models
{
//{"data":[{"pos":"FfZ6WCa8TunAvPCpQZXkdBsoH4Yo18FyPaJ5X5qjrVVY"},{"pos/invoice":"H1pwwh2tMeSCri9rh5VvHWEHokGdf2EGtghfZkUEbeZv"},{"merchant":"89zEBr9orAc6wgybAABp8ioGcjYeFrUaZgMzjxNuqYty"},{"merchant/invoice":"8e7ijDxGfJsWXWgJuKXjjNgxnX1xpsBM8cTZCFnU7ehj"}]}
public class GetTokensResponse : IActionResult
{
readonly BitTokenEntity[] _Tokens;
public GetTokensResponse(BitTokenEntity[] tokens)
{
ArgumentNullException.ThrowIfNull(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);
2022-01-14 09:50:29 +01:00
await using var writer = new StreamWriter(context.HttpContext.Response.Body, new UTF8Encoding(false), 1024 * 10, true);
await writer.WriteAsync(str);
}
}
2017-09-13 08:47:34 +02:00
}