2017-09-13 08:47:34 +02:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2019-04-23 09:05:11 +02:00
|
|
|
|
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 NBitcoin.DataEncoders;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using System.IO;
|
2019-10-18 17:54:20 +02:00
|
|
|
|
using BTCPayServer.Security.Bitpay;
|
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
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
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);
|
2019-10-09 10:06:00 +02:00
|
|
|
|
await using (var writer = new StreamWriter(context.HttpContext.Response.Body, new UTF8Encoding(false), 1024 * 10, true))
|
2017-10-27 10:53:04 +02:00
|
|
|
|
{
|
|
|
|
|
await writer.WriteAsync(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 08:47:34 +02:00
|
|
|
|
}
|