mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Greenfield: Add payments list endpoint (#4407)
Based on btcpayserver/BTCPayServer.Lightning#109
This commit is contained in:
parent
f46443a5e3
commit
de4ac2c830
9 changed files with 269 additions and 0 deletions
|
@ -113,6 +113,24 @@ namespace BTCPayServer.Client
|
|||
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices", queryPayload), token);
|
||||
return await HandleResponse<LightningInvoiceData[]>(response);
|
||||
}
|
||||
|
||||
public virtual async Task<LightningPaymentData[]> GetLightningPayments(string cryptoCode,
|
||||
bool? includePending = null, long? offsetIndex = null, CancellationToken token = default)
|
||||
{
|
||||
var queryPayload = new Dictionary<string, object>();
|
||||
if (includePending is bool v)
|
||||
{
|
||||
queryPayload.Add("includePending", v.ToString());
|
||||
}
|
||||
if (offsetIndex is > 0)
|
||||
{
|
||||
queryPayload.Add("offsetIndex", offsetIndex);
|
||||
}
|
||||
|
||||
var response = await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/payments", queryPayload), token);
|
||||
return await HandleResponse<LightningPaymentData[]>(response);
|
||||
}
|
||||
|
||||
public virtual async Task<LightningInvoiceData> CreateLightningInvoice(string cryptoCode, CreateLightningInvoiceRequest request,
|
||||
CancellationToken token = default)
|
||||
|
|
|
@ -115,6 +115,24 @@ namespace BTCPayServer.Client
|
|||
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices", queryPayload), token);
|
||||
return await HandleResponse<LightningInvoiceData[]>(response);
|
||||
}
|
||||
|
||||
public virtual async Task<LightningPaymentData[]> GetLightningPayments(string storeId, string cryptoCode,
|
||||
bool? includePending = null, long? offsetIndex = null, CancellationToken token = default)
|
||||
{
|
||||
var queryPayload = new Dictionary<string, object>();
|
||||
if (includePending is bool v)
|
||||
{
|
||||
queryPayload.Add("includePending", v.ToString());
|
||||
}
|
||||
if (offsetIndex is > 0)
|
||||
{
|
||||
queryPayload.Add("offsetIndex", offsetIndex);
|
||||
}
|
||||
|
||||
var response = await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/payments", queryPayload), token);
|
||||
return await HandleResponse<LightningPaymentData[]>(response);
|
||||
}
|
||||
|
||||
public virtual async Task<LightningInvoiceData> CreateLightningInvoice(string storeId, string cryptoCode,
|
||||
CreateLightningInvoiceRequest request, CancellationToken token = default)
|
||||
|
|
|
@ -2259,7 +2259,13 @@ namespace BTCPayServer.Tests
|
|||
|
||||
// Amount received might be bigger because of internal implementation shit from lightning
|
||||
Assert.True(LightMoney.Satoshis(1000) <= invoice.AmountReceived);
|
||||
|
||||
// check payments list for store node
|
||||
var payments = await client.GetLightningPayments(user.StoreId, "BTC");
|
||||
Assert.NotEmpty(payments);
|
||||
Assert.Contains(payments, i => i.BOLT11 == merchantInvoice.BOLT11);
|
||||
|
||||
// Node info
|
||||
info = await client.GetLightningNodeInfo(user.StoreId, "BTC");
|
||||
Assert.Single(info.NodeURIs);
|
||||
Assert.NotEqual(0, info.BlockHeight);
|
||||
|
|
|
@ -125,6 +125,14 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||
return base.CreateInvoice(cryptoCode, request, cancellationToken);
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanUseInternalLightningNode,
|
||||
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/server/lightning/{cryptoCode}/payments")]
|
||||
public override Task<IActionResult> GetPayments(string cryptoCode, [FromQuery] bool? includePending, [FromQuery] long? offsetIndex, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return base.GetPayments(cryptoCode, includePending, offsetIndex, cancellationToken);
|
||||
}
|
||||
|
||||
protected override async Task<ILightningClient> GetLightningClient(string cryptoCode, bool doingAdminThings)
|
||||
{
|
||||
var network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
|
||||
|
|
|
@ -127,6 +127,14 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||
return base.CreateInvoice(cryptoCode, request, cancellationToken);
|
||||
}
|
||||
|
||||
[Authorize(Policy = Policies.CanUseLightningNodeInStore,
|
||||
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/stores/{storeId}/lightning/{cryptoCode}/payments")]
|
||||
public override Task<IActionResult> GetPayments(string cryptoCode, [FromQuery] bool? includePending, [FromQuery] long? offsetIndex, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return base.GetPayments(cryptoCode, includePending, offsetIndex, cancellationToken);
|
||||
}
|
||||
|
||||
protected override Task<ILightningClient> GetLightningClient(string cryptoCode,
|
||||
bool doingAdminThings)
|
||||
{
|
||||
|
|
|
@ -290,6 +290,14 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||
return Ok(invoices.Select(ToModel));
|
||||
}
|
||||
|
||||
public virtual async Task<IActionResult> GetPayments(string cryptoCode, [FromQuery] bool? includePending, [FromQuery] long? offsetIndex, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var lightningClient = await GetLightningClient(cryptoCode, false);
|
||||
var param = new ListPaymentsParams { IncludePending = includePending, OffsetIndex = offsetIndex };
|
||||
var payments = await lightningClient.ListPayments(param, cancellationToken);
|
||||
return Ok(payments.Select(ToModel));
|
||||
}
|
||||
|
||||
public virtual async Task<IActionResult> CreateInvoice(string cryptoCode, CreateLightningInvoiceRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var lightningClient = await GetLightningClient(cryptoCode, false);
|
||||
|
|
|
@ -436,6 +436,13 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||
await GetController<GreenfieldStoreLightningNodeApiController>().GetInvoices(cryptoCode, pendingOnly, offsetIndex, token));
|
||||
}
|
||||
|
||||
public override async Task<LightningPaymentData[]> GetLightningPayments(string storeId, string cryptoCode,
|
||||
bool? includePending = null, long? offsetIndex = null, CancellationToken token = default)
|
||||
{
|
||||
return GetFromActionResult<LightningPaymentData[]>(
|
||||
await GetController<GreenfieldStoreLightningNodeApiController>().GetPayments(cryptoCode, includePending, offsetIndex, token));
|
||||
}
|
||||
|
||||
public override async Task<LightningInvoiceData> CreateLightningInvoice(string storeId, string cryptoCode,
|
||||
CreateLightningInvoiceRequest request, CancellationToken token = default)
|
||||
{
|
||||
|
@ -504,6 +511,13 @@ namespace BTCPayServer.Controllers.Greenfield
|
|||
await GetController<GreenfieldInternalLightningNodeApiController>().GetInvoices(cryptoCode, pendingOnly, offsetIndex, token));
|
||||
}
|
||||
|
||||
public override async Task<LightningPaymentData[]> GetLightningPayments(string cryptoCode,
|
||||
bool? includePending = null, long? offsetIndex = null, CancellationToken token = default)
|
||||
{
|
||||
return GetFromActionResult<LightningPaymentData[]>(
|
||||
await GetController<GreenfieldInternalLightningNodeApiController>().GetPayments(cryptoCode, includePending, offsetIndex, token));
|
||||
}
|
||||
|
||||
public override async Task<LightningInvoiceData> CreateLightningInvoice(string cryptoCode,
|
||||
CreateLightningInvoiceRequest request,
|
||||
CancellationToken token = default)
|
||||
|
|
|
@ -691,6 +691,96 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v1/server/lightning/{cryptoCode}/payments": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Lightning (Internal Node)"
|
||||
],
|
||||
"summary": "Get payments",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "cryptoCode",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"description": "The cryptoCode of the lightning-node to query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "BTC"
|
||||
},
|
||||
{
|
||||
"name": "includePending",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Also include pending payments",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"nullable": true,
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "offsetIndex",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "The index of a payment that will be used as the start of the list",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"nullable": true,
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"description": "View information about the lightning payments",
|
||||
"operationId": "InternalLightningNodeApi_GetPayments",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Lightning payment data",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/LightningPaymentData"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Missing authorization",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ProblemDetails"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"503": {
|
||||
"description": "Unable to access the lightning node"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ProblemDetails"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"API_Key": [
|
||||
"btcpay.server.canuseinternallightningnode"
|
||||
],
|
||||
"Basic": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
|
|
|
@ -791,6 +791,105 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/v1/stores/{storeId}/lightning/{cryptoCode}/payments": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"Lightning (Store)"
|
||||
],
|
||||
"summary": "Get payments",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "cryptoCode",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"description": "The cryptoCode of the lightning-node to query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
},
|
||||
"example": "BTC"
|
||||
},
|
||||
{
|
||||
"name": "storeId",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"description": "The store id with the lightning-node configuration to query",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "includePending",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Also include pending payments",
|
||||
"schema": {
|
||||
"type": "boolean",
|
||||
"nullable": true,
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "offsetIndex",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "The index of an invoice that will be used as the start of the list",
|
||||
"schema": {
|
||||
"type": "number",
|
||||
"nullable": true,
|
||||
"default": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"description": "View information about the lightning payments",
|
||||
"operationId": "StoreLightningNodeApi_GetPayments",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Lightning payment data",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/LightningPaymentData"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"description": "Missing authorization",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ProblemDetails"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"503": {
|
||||
"description": "Unable to access the lightning node"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/ProblemDetails"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"API_Key": [
|
||||
"btcpay.store.cancreatelightninginvoice"
|
||||
],
|
||||
"Basic": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
|
|
Loading…
Add table
Reference in a new issue