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;
|
2019-10-18 17:54:20 +02:00
|
|
|
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
|
|
|
|
{
|
2017-10-27 10:53:04 +02:00
|
|
|
//{"data":[{"pos":"FfZ6WCa8TunAvPCpQZXkdBsoH4Yo18FyPaJ5X5qjrVVY"},{"pos/invoice":"H1pwwh2tMeSCri9rh5VvHWEHokGdf2EGtghfZkUEbeZv"},{"merchant":"89zEBr9orAc6wgybAABp8ioGcjYeFrUaZgMzjxNuqYty"},{"merchant/invoice":"8e7ijDxGfJsWXWgJuKXjjNgxnX1xpsBM8cTZCFnU7ehj"}]}
|
|
|
|
public class GetTokensResponse : IActionResult
|
|
|
|
{
|
2020-06-29 05:07:48 +02:00
|
|
|
readonly BitTokenEntity[] _Tokens;
|
2017-10-27 10:53:04 +02:00
|
|
|
public GetTokensResponse(BitTokenEntity[] tokens)
|
|
|
|
{
|
2021-12-28 09:39:54 +01:00
|
|
|
ArgumentNullException.ThrowIfNull(tokens);
|
2017-10-27 10:53:04 +02:00
|
|
|
this._Tokens = tokens;
|
|
|
|
}
|
2017-09-13 08:47:34 +02:00
|
|
|
|
2017-10-27 10:53:04 +02:00
|
|
|
[JsonProperty(PropertyName = "data")]
|
|
|
|
//{"pos":"FfZ6WCa8TunAvPCpQZXkdBsoH4Yo18FyPaJ5X5qjrVVY"}
|
|
|
|
public JArray Data
|
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
2017-09-13 08:47:34 +02:00
|
|
|
|
2017-10-27 10:53:04 +02:00
|
|
|
public async Task ExecuteResultAsync(ActionContext context)
|
|
|
|
{
|
|
|
|
JObject jobj = new JObject();
|
|
|
|
JArray jarray = new JArray();
|
|
|
|
jobj.Add("data", jarray);
|
2019-04-23 09:05:11 +02:00
|
|
|
var token = _Tokens.FirstOrDefault();
|
|
|
|
if (token != null)
|
2017-10-27 10:53:04 +02:00
|
|
|
{
|
|
|
|
JObject item = new JObject();
|
|
|
|
jarray.Add(item);
|
2019-04-11 16:54:58 +02:00
|
|
|
JProperty jProp = new JProperty("merchant");
|
2017-10-27 10:53:04 +02:00
|
|
|
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-10-27 10:53:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-13 08:47:34 +02:00
|
|
|
}
|