BTCPayServerClient refactoring (#6024)

* Allow overrides on all methods

* Add non-returning SendHttpRequest methods

* Use SendHttpRequest consistently

* Use file-scoped namespace

* Rates: Set default null value for currencyPair

* Ensure it works with instances which have BTCPAY_ROOTPATH set
This commit is contained in:
d11n
2024-06-19 15:25:33 +02:00
committed by GitHub
parent 0f8da123b8
commit f8f98ab7f0
31 changed files with 1115 additions and 1532 deletions

View File

@@ -1,58 +1,44 @@
using System; using System;
using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<ApiKeyData> GetCurrentAPIKeyInfo(CancellationToken token = default) public virtual async Task<ApiKeyData> GetCurrentAPIKeyInfo(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/api-keys/current"), token); return await SendHttpRequest<ApiKeyData>("api/v1/api-keys/current", null, HttpMethod.Get, token);
return await HandleResponse<ApiKeyData>(response);
} }
public virtual async Task<ApiKeyData> CreateAPIKey(CreateApiKeyRequest request, CancellationToken token = default) public virtual async Task<ApiKeyData> CreateAPIKey(CreateApiKeyRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<ApiKeyData>("api/v1/api-keys", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/api-keys", bodyPayload: request, method: HttpMethod.Post), token);
return await HandleResponse<ApiKeyData>(response);
} }
public virtual async Task<ApiKeyData> CreateAPIKey(string userId, CreateApiKeyRequest request, CancellationToken token = default) public virtual async Task<ApiKeyData> CreateAPIKey(string userId, CreateApiKeyRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<ApiKeyData>($"api/v1/users/{userId}/api-keys", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{userId}/api-keys",
bodyPayload: request, method: HttpMethod.Post), token);
return await HandleResponse<ApiKeyData>(response);
} }
public virtual async Task RevokeCurrentAPIKeyInfo(CancellationToken token = default) public virtual async Task RevokeCurrentAPIKeyInfo(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/api-keys/current", null, HttpMethod.Delete), token); await SendHttpRequest("api/v1/api-keys/current", null, HttpMethod.Delete, token);
await HandleResponse(response);
} }
public virtual async Task RevokeAPIKey(string apikey, CancellationToken token = default) public virtual async Task RevokeAPIKey(string apikey, CancellationToken token = default)
{ {
if (apikey == null) if (apikey == null) throw new ArgumentNullException(nameof(apikey));
throw new ArgumentNullException(nameof(apikey)); await SendHttpRequest($"api/v1/api-keys/{apikey}", null, HttpMethod.Delete, token);
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/api-keys/{apikey}", null, HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task RevokeAPIKey(string userId, string apikey, CancellationToken token = default) public virtual async Task RevokeAPIKey(string userId, string apikey, CancellationToken token = default)
{ {
if (apikey == null) if (apikey == null) throw new ArgumentNullException(nameof(apikey));
throw new ArgumentNullException(nameof(apikey)); if (userId is null) throw new ArgumentNullException(nameof(userId));
if (userId is null) await SendHttpRequest($"api/v1/users/{userId}/api-keys/{apikey}", null, HttpMethod.Delete, token);
throw new ArgumentNullException(nameof(userId));
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{userId}/api-keys/{apikey}", null, HttpMethod.Delete), token);
await HandleResponse(response);
}
} }
} }

View File

@@ -4,100 +4,63 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
{
public partial class BTCPayServerClient
{
public partial class BTCPayServerClient
{
public virtual async Task<PointOfSaleAppData> CreatePointOfSaleApp(string storeId, public virtual async Task<PointOfSaleAppData> CreatePointOfSaleApp(string storeId,
CreatePointOfSaleAppRequest request, CancellationToken token = default) CreatePointOfSaleAppRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<PointOfSaleAppData>($"api/v1/stores/{storeId}/apps/pos", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/apps/pos", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<PointOfSaleAppData>(response);
} }
public virtual async Task<CrowdfundAppData> CreateCrowdfundApp(string storeId, public virtual async Task<CrowdfundAppData> CreateCrowdfundApp(string storeId,
CreateCrowdfundAppRequest request, CancellationToken token = default) CreateCrowdfundAppRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<CrowdfundAppData>($"api/v1/stores/{storeId}/apps/crowdfund", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/apps/crowdfund", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<CrowdfundAppData>(response);
} }
public virtual async Task<PointOfSaleAppData> UpdatePointOfSaleApp(string appId, public virtual async Task<PointOfSaleAppData> UpdatePointOfSaleApp(string appId,
CreatePointOfSaleAppRequest request, CancellationToken token = default) CreatePointOfSaleAppRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<PointOfSaleAppData>($"api/v1/apps/pos/{appId}", request, HttpMethod.Put, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/apps/pos/{appId}", bodyPayload: request,
method: HttpMethod.Put), token);
return await HandleResponse<PointOfSaleAppData>(response);
} }
public virtual async Task<AppDataBase> GetApp(string appId, CancellationToken token = default) public virtual async Task<AppDataBase> GetApp(string appId, CancellationToken token = default)
{ {
if (appId == null) if (appId == null) throw new ArgumentNullException(nameof(appId));
throw new ArgumentNullException(nameof(appId)); return await SendHttpRequest<AppDataBase>($"api/v1/apps/{appId}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/apps/{appId}",
method: HttpMethod.Get), token);
return await HandleResponse<AppDataBase>(response);
} }
public virtual async Task<AppDataBase[]> GetAllApps(string storeId, CancellationToken token = default) public virtual async Task<AppDataBase[]> GetAllApps(string storeId, CancellationToken token = default)
{ {
if (storeId == null) if (storeId == null) throw new ArgumentNullException(nameof(storeId));
throw new ArgumentNullException(nameof(storeId)); return await SendHttpRequest<AppDataBase[]>($"api/v1/stores/{storeId}/apps", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/apps",
method: HttpMethod.Get), token);
return await HandleResponse<AppDataBase[]>(response);
} }
public virtual async Task<AppDataBase[]> GetAllApps(CancellationToken token = default) public virtual async Task<AppDataBase[]> GetAllApps(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<AppDataBase[]>("api/v1/apps", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/apps",
method: HttpMethod.Get), token);
return await HandleResponse<AppDataBase[]>(response);
} }
public virtual async Task<PointOfSaleAppData> GetPosApp(string appId, CancellationToken token = default) public virtual async Task<PointOfSaleAppData> GetPosApp(string appId, CancellationToken token = default)
{ {
if (appId == null) if (appId == null) throw new ArgumentNullException(nameof(appId));
throw new ArgumentNullException(nameof(appId)); return await SendHttpRequest<PointOfSaleAppData>($"api/v1/apps/pos/{appId}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/apps/pos/{appId}",
method: HttpMethod.Get), token);
return await HandleResponse<PointOfSaleAppData>(response);
} }
public virtual async Task<CrowdfundAppData> GetCrowdfundApp(string appId, CancellationToken token = default) public virtual async Task<CrowdfundAppData> GetCrowdfundApp(string appId, CancellationToken token = default)
{ {
if (appId == null) if (appId == null) throw new ArgumentNullException(nameof(appId));
throw new ArgumentNullException(nameof(appId)); return await SendHttpRequest<CrowdfundAppData>($"api/v1/apps/crowdfund/{appId}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/apps/crowdfund/{appId}",
method: HttpMethod.Get), token);
return await HandleResponse<CrowdfundAppData>(response);
} }
public virtual async Task DeleteApp(string appId, CancellationToken token = default) public virtual async Task DeleteApp(string appId, CancellationToken token = default)
{ {
if (appId == null) if (appId == null) throw new ArgumentNullException(nameof(appId));
throw new ArgumentNullException(nameof(appId)); await SendHttpRequest($"api/v1/apps/{appId}", null, HttpMethod.Delete, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/apps/{appId}",
method: HttpMethod.Delete), token);
await HandleResponse(response);
}
} }
} }

View File

@@ -1,20 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public static Uri GenerateAuthorizeUri(Uri btcpayHost, string[] permissions, bool strict = true, public static Uri GenerateAuthorizeUri(Uri btcpayHost, string[] permissions, bool strict = true,
bool selectiveStores = false, (string ApplicationIdentifier, Uri Redirect) applicationDetails = default) bool selectiveStores = false, (string ApplicationIdentifier, Uri Redirect) applicationDetails = default)
{ {
var result = new UriBuilder(btcpayHost); var result = new UriBuilder(btcpayHost) { Path = "api-keys/authorize" };
result.Path = "api-keys/authorize";
AppendPayloadToQuery(result, AppendPayloadToQuery(result,
new Dictionary<string, object>() new Dictionary<string, object>
{ {
{"strict", strict}, {"selectiveStores", selectiveStores}, {"permissions", permissions} {"strict", strict}, {"selectiveStores", selectiveStores}, {"permissions", permissions}
}); });
@@ -30,5 +26,4 @@ namespace BTCPayServer.Client
return result.Uri; return result.Uri;
} }
}
} }

View File

@@ -1,15 +1,14 @@
using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<ApiHealthData> GetHealth(CancellationToken token = default) public virtual async Task<ApiHealthData> GetHealth(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/health"), token); return await SendHttpRequest<ApiHealthData>("api/v1/health", null, HttpMethod.Get, token);
return await HandleResponse<ApiHealthData>(response);
}
} }
} }

View File

@@ -7,10 +7,10 @@ using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using NBitcoin; using NBitcoin;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<IEnumerable<InvoiceData>> GetInvoices(string storeId, string[] orderId = null, public virtual async Task<IEnumerable<InvoiceData>> GetInvoices(string storeId, string[] orderId = null,
InvoiceStatus[] status = null, InvoiceStatus[] status = null,
DateTimeOffset? startDate = null, DateTimeOffset? startDate = null,
@@ -21,112 +21,72 @@ namespace BTCPayServer.Client
int? take = null, int? take = null,
CancellationToken token = default) CancellationToken token = default)
{ {
Dictionary<string, object> queryPayload = new Dictionary<string, object>(); var queryPayload = new Dictionary<string, object> { { nameof(includeArchived), includeArchived } };
queryPayload.Add(nameof(includeArchived), includeArchived); if (startDate is { } s)
if (startDate is DateTimeOffset s)
queryPayload.Add(nameof(startDate), Utils.DateTimeToUnixTime(s)); queryPayload.Add(nameof(startDate), Utils.DateTimeToUnixTime(s));
if (endDate is { } e)
if (endDate is DateTimeOffset e)
queryPayload.Add(nameof(endDate), Utils.DateTimeToUnixTime(e)); queryPayload.Add(nameof(endDate), Utils.DateTimeToUnixTime(e));
if (orderId != null) if (orderId != null)
queryPayload.Add(nameof(orderId), orderId); queryPayload.Add(nameof(orderId), orderId);
if (textSearch != null) if (textSearch != null)
queryPayload.Add(nameof(textSearch), textSearch); queryPayload.Add(nameof(textSearch), textSearch);
if (status != null) if (status != null)
queryPayload.Add(nameof(status), status.Select(s => s.ToString().ToLower()).ToArray()); queryPayload.Add(nameof(status), status.Select(s => s.ToString().ToLower()).ToArray());
if (skip != null) if (skip != null)
{
queryPayload.Add(nameof(skip), skip); queryPayload.Add(nameof(skip), skip);
}
if (take != null) if (take != null)
{
queryPayload.Add(nameof(take), take); queryPayload.Add(nameof(take), take);
}
var response = return await SendHttpRequest<IEnumerable<InvoiceData>>($"api/v1/stores/{storeId}/invoices", queryPayload, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/invoices",
queryPayload), token);
return await HandleResponse<IEnumerable<InvoiceData>>(response);
} }
public virtual async Task<InvoiceData> GetInvoice(string storeId, string invoiceId, public virtual async Task<InvoiceData> GetInvoice(string storeId, string invoiceId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<InvoiceData>($"api/v1/stores/{storeId}/invoices/{invoiceId}", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}"), token);
return await HandleResponse<InvoiceData>(response);
} }
public virtual async Task<InvoicePaymentMethodDataModel[]> GetInvoicePaymentMethods(string storeId, string invoiceId, public virtual async Task<InvoicePaymentMethodDataModel[]> GetInvoicePaymentMethods(string storeId, string invoiceId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<InvoicePaymentMethodDataModel[]>($"api/v1/stores/{storeId}/invoices/{invoiceId}/payment-methods", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}/payment-methods"), token);
return await HandleResponse<InvoicePaymentMethodDataModel[]>(response);
} }
public virtual async Task ArchiveInvoice(string storeId, string invoiceId, public virtual async Task ArchiveInvoice(string storeId, string invoiceId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}", null, HttpMethod.Delete, token);
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}",
method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task<InvoiceData> CreateInvoice(string storeId, public virtual async Task<InvoiceData> CreateInvoice(string storeId,
CreateInvoiceRequest request, CancellationToken token = default) CreateInvoiceRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<InvoiceData>($"api/v1/stores/{storeId}/invoices", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/invoices", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<InvoiceData>(response);
} }
public virtual async Task<InvoiceData> UpdateInvoice(string storeId, string invoiceId, public virtual async Task<InvoiceData> UpdateInvoice(string storeId, string invoiceId,
UpdateInvoiceRequest request, CancellationToken token = default) UpdateInvoiceRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<InvoiceData>($"api/v1/stores/{storeId}/invoices/{invoiceId}", request, HttpMethod.Put, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}", bodyPayload: request,
method: HttpMethod.Put), token);
return await HandleResponse<InvoiceData>(response);
} }
public virtual async Task<InvoiceData> MarkInvoiceStatus(string storeId, string invoiceId, public virtual async Task<InvoiceData> MarkInvoiceStatus(string storeId, string invoiceId,
MarkInvoiceStatusRequest request, CancellationToken token = default) MarkInvoiceStatusRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); if (request.Status != InvoiceStatus.Settled && request.Status != InvoiceStatus.Invalid) throw new ArgumentOutOfRangeException(nameof(request.Status), "Status can only be Invalid or Complete");
if (request.Status != InvoiceStatus.Settled && request.Status != InvoiceStatus.Invalid) return await SendHttpRequest<InvoiceData>($"api/v1/stores/{storeId}/invoices/{invoiceId}/status", request, HttpMethod.Post, token);
throw new ArgumentOutOfRangeException(nameof(request.Status), "Status can only be Invalid or Complete");
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}/status", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<InvoiceData>(response);
} }
public virtual async Task<InvoiceData> UnarchiveInvoice(string storeId, string invoiceId, CancellationToken token = default) public virtual async Task<InvoiceData> UnarchiveInvoice(string storeId, string invoiceId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<InvoiceData>($"api/v1/stores/{storeId}/invoices/{invoiceId}/unarchive", null, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}/unarchive",
method: HttpMethod.Post), token);
return await HandleResponse<InvoiceData>(response);
} }
public virtual async Task ActivateInvoicePaymentMethod(string storeId, string invoiceId, string paymentMethod, CancellationToken token = default) public virtual async Task ActivateInvoicePaymentMethod(string storeId, string invoiceId, string paymentMethod, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}/payment-methods/{paymentMethod}/activate", null, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}/payment-methods/{paymentMethod}/activate",
method: HttpMethod.Post), token);
await HandleResponse(response);
} }
public virtual async Task<PullPaymentData> RefundInvoice( public virtual async Task<PullPaymentData> RefundInvoice(
@@ -136,10 +96,6 @@ namespace BTCPayServer.Client
CancellationToken token = default CancellationToken token = default
) )
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<PullPaymentData>($"api/v1/stores/{storeId}/invoices/{invoiceId}/refund", request, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/invoices/{invoiceId}/refund", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<PullPaymentData>(response);
}
} }
} }

View File

@@ -5,95 +5,65 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<LightningNodeInformationData> GetLightningNodeInfo(string cryptoCode, public virtual async Task<LightningNodeInformationData> GetLightningNodeInfo(string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningNodeInformationData>($"api/v1/server/lightning/{cryptoCode}/info", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/info",
method: HttpMethod.Get), token);
return await HandleResponse<LightningNodeInformationData>(response);
} }
public virtual async Task<LightningNodeBalanceData> GetLightningNodeBalance(string cryptoCode, public virtual async Task<LightningNodeBalanceData> GetLightningNodeBalance(string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningNodeBalanceData>($"api/v1/server/lightning/{cryptoCode}/balance", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/balance",
method: HttpMethod.Get), token);
return await HandleResponse<LightningNodeBalanceData>(response);
} }
public virtual async Task ConnectToLightningNode(string cryptoCode, ConnectToNodeRequest request, public virtual async Task ConnectToLightningNode(string cryptoCode, ConnectToNodeRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); await SendHttpRequest($"api/v1/server/lightning/{cryptoCode}/connect", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/connect", bodyPayload: request,
method: HttpMethod.Post), token);
await HandleResponse(response);
} }
public virtual async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string cryptoCode, public virtual async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<IEnumerable<LightningChannelData>>($"api/v1/server/lightning/{cryptoCode}/channels", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/channels",
method: HttpMethod.Get), token);
return await HandleResponse<IEnumerable<LightningChannelData>>(response);
} }
public virtual async Task OpenLightningChannel(string cryptoCode, OpenLightningChannelRequest request, public virtual async Task OpenLightningChannel(string cryptoCode, OpenLightningChannelRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/server/lightning/{cryptoCode}/channels", request, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/channels", bodyPayload: request,
method: HttpMethod.Post), token);
await HandleResponse(response);
} }
public virtual async Task<string> GetLightningDepositAddress(string cryptoCode, CancellationToken token = default) public virtual async Task<string> GetLightningDepositAddress(string cryptoCode, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<string>($"api/v1/server/lightning/{cryptoCode}/address", null, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/address", method: HttpMethod.Post), token);
return await HandleResponse<string>(response);
} }
public virtual async Task<LightningPaymentData> PayLightningInvoice(string cryptoCode, PayLightningInvoiceRequest request, public virtual async Task<LightningPaymentData> PayLightningInvoice(string cryptoCode, PayLightningInvoiceRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<LightningPaymentData>($"api/v1/server/lightning/{cryptoCode}/invoices/pay", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices/pay", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<LightningPaymentData>(response);
} }
public virtual async Task<LightningPaymentData> GetLightningPayment(string cryptoCode, public virtual async Task<LightningPaymentData> GetLightningPayment(string cryptoCode,
string paymentHash, CancellationToken token = default) string paymentHash, CancellationToken token = default)
{ {
if (paymentHash == null) if (paymentHash == null) throw new ArgumentNullException(nameof(paymentHash));
throw new ArgumentNullException(nameof(paymentHash)); return await SendHttpRequest<LightningPaymentData>($"api/v1/server/lightning/{cryptoCode}/payments/{paymentHash}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/payments/{paymentHash}",
method: HttpMethod.Get), token);
return await HandleResponse<LightningPaymentData>(response);
} }
public virtual async Task<LightningInvoiceData> GetLightningInvoice(string cryptoCode, public virtual async Task<LightningInvoiceData> GetLightningInvoice(string cryptoCode,
string invoiceId, CancellationToken token = default) string invoiceId, CancellationToken token = default)
{ {
if (invoiceId == null) if (invoiceId == null) throw new ArgumentNullException(nameof(invoiceId));
throw new ArgumentNullException(nameof(invoiceId)); return await SendHttpRequest<LightningInvoiceData>($"api/v1/server/lightning/{cryptoCode}/invoices/{invoiceId}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices/{invoiceId}",
method: HttpMethod.Get), token);
return await HandleResponse<LightningInvoiceData>(response);
} }
public virtual async Task<LightningInvoiceData[]> GetLightningInvoices(string cryptoCode, public virtual async Task<LightningInvoiceData[]> GetLightningInvoices(string cryptoCode,
@@ -108,10 +78,7 @@ namespace BTCPayServer.Client
{ {
queryPayload.Add("offsetIndex", offsetIndex); queryPayload.Add("offsetIndex", offsetIndex);
} }
return await SendHttpRequest<LightningInvoiceData[]>($"api/v1/server/lightning/{cryptoCode}/invoices", queryPayload, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices", queryPayload), token);
return await HandleResponse<LightningInvoiceData[]>(response);
} }
public virtual async Task<LightningPaymentData[]> GetLightningPayments(string cryptoCode, public virtual async Task<LightningPaymentData[]> GetLightningPayments(string cryptoCode,
@@ -126,21 +93,13 @@ namespace BTCPayServer.Client
{ {
queryPayload.Add("offsetIndex", offsetIndex); queryPayload.Add("offsetIndex", offsetIndex);
} }
return await SendHttpRequest<LightningPaymentData[]>($"api/v1/server/lightning/{cryptoCode}/payments", queryPayload, HttpMethod.Get, token);
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, public virtual async Task<LightningInvoiceData> CreateLightningInvoice(string cryptoCode, CreateLightningInvoiceRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<LightningInvoiceData>($"api/v1/server/lightning/{cryptoCode}/invoices", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/server/lightning/{cryptoCode}/invoices", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<LightningInvoiceData>(response);
}
} }
} }

View File

@@ -5,97 +5,66 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<LightningNodeInformationData> GetLightningNodeInfo(string storeId, string cryptoCode, public virtual async Task<LightningNodeInformationData> GetLightningNodeInfo(string storeId, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningNodeInformationData>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/info", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/info",
method: HttpMethod.Get), token);
return await HandleResponse<LightningNodeInformationData>(response);
} }
public virtual async Task<LightningNodeBalanceData> GetLightningNodeBalance(string storeId, string cryptoCode, public virtual async Task<LightningNodeBalanceData> GetLightningNodeBalance(string storeId, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningNodeBalanceData>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/balance", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/balance",
method: HttpMethod.Get), token);
return await HandleResponse<LightningNodeBalanceData>(response);
} }
public virtual async Task ConnectToLightningNode(string storeId, string cryptoCode, ConnectToNodeRequest request, public virtual async Task ConnectToLightningNode(string storeId, string cryptoCode, ConnectToNodeRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); await SendHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/connect", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/connect", bodyPayload: request,
method: HttpMethod.Post), token);
await HandleResponse(response);
} }
public virtual async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string storeId, string cryptoCode, public virtual async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string storeId, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<IEnumerable<LightningChannelData>>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/channels", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/channels",
method: HttpMethod.Get), token);
return await HandleResponse<IEnumerable<LightningChannelData>>(response);
} }
public virtual async Task OpenLightningChannel(string storeId, string cryptoCode, OpenLightningChannelRequest request, public virtual async Task OpenLightningChannel(string storeId, string cryptoCode, OpenLightningChannelRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/channels", request, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/channels", bodyPayload: request,
method: HttpMethod.Post), token);
await HandleResponse(response);
} }
public virtual async Task<string> GetLightningDepositAddress(string storeId, string cryptoCode, public virtual async Task<string> GetLightningDepositAddress(string storeId, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<string>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/address", null, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/address", method: HttpMethod.Post),
token);
return await HandleResponse<string>(response);
} }
public virtual async Task<LightningPaymentData> PayLightningInvoice(string storeId, string cryptoCode, PayLightningInvoiceRequest request, public virtual async Task<LightningPaymentData> PayLightningInvoice(string storeId, string cryptoCode, PayLightningInvoiceRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<LightningPaymentData>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/pay", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/pay", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<LightningPaymentData>(response);
} }
public virtual async Task<LightningPaymentData> GetLightningPayment(string storeId, string cryptoCode, public virtual async Task<LightningPaymentData> GetLightningPayment(string storeId, string cryptoCode,
string paymentHash, CancellationToken token = default) string paymentHash, CancellationToken token = default)
{ {
if (paymentHash == null) if (paymentHash == null) throw new ArgumentNullException(nameof(paymentHash));
throw new ArgumentNullException(nameof(paymentHash)); return await SendHttpRequest<LightningPaymentData>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/payments/{paymentHash}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/payments/{paymentHash}",
method: HttpMethod.Get), token);
return await HandleResponse<LightningPaymentData>(response);
} }
public virtual async Task<LightningInvoiceData> GetLightningInvoice(string storeId, string cryptoCode, public virtual async Task<LightningInvoiceData> GetLightningInvoice(string storeId, string cryptoCode,
string invoiceId, CancellationToken token = default) string invoiceId, CancellationToken token = default)
{ {
if (invoiceId == null) if (invoiceId == null) throw new ArgumentNullException(nameof(invoiceId));
throw new ArgumentNullException(nameof(invoiceId)); return await SendHttpRequest<LightningInvoiceData>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/{invoiceId}", null, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/{invoiceId}",
method: HttpMethod.Get), token);
return await HandleResponse<LightningInvoiceData>(response);
} }
public virtual async Task<LightningInvoiceData[]> GetLightningInvoices(string storeId, string cryptoCode, public virtual async Task<LightningInvoiceData[]> GetLightningInvoices(string storeId, string cryptoCode,
@@ -110,10 +79,7 @@ namespace BTCPayServer.Client
{ {
queryPayload.Add("offsetIndex", offsetIndex); queryPayload.Add("offsetIndex", offsetIndex);
} }
return await SendHttpRequest<LightningInvoiceData[]>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices", queryPayload, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
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, public virtual async Task<LightningPaymentData[]> GetLightningPayments(string storeId, string cryptoCode,
@@ -128,21 +94,13 @@ namespace BTCPayServer.Client
{ {
queryPayload.Add("offsetIndex", offsetIndex); queryPayload.Add("offsetIndex", offsetIndex);
} }
return await SendHttpRequest<LightningPaymentData[]>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/payments", queryPayload, HttpMethod.Get, token);
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, public virtual async Task<LightningInvoiceData> CreateLightningInvoice(string storeId, string cryptoCode,
CreateLightningInvoiceRequest request, CancellationToken token = default) CreateLightningInvoiceRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<LightningInvoiceData>($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<LightningInvoiceData>(response);
}
} }
} }

View File

@@ -3,46 +3,32 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<LightningAddressData[]> GetStoreLightningAddresses(string storeId, public virtual async Task<LightningAddressData[]> GetStoreLightningAddresses(string storeId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningAddressData[]>($"api/v1/stores/{storeId}/lightning-addresses", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning-addresses",
method: HttpMethod.Get), token);
return await HandleResponse<LightningAddressData[]>(response);
} }
public virtual async Task<LightningAddressData> GetStoreLightningAddress(string storeId, string username, public virtual async Task<LightningAddressData> GetStoreLightningAddress(string storeId, string username,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningAddressData>($"api/v1/stores/{storeId}/lightning-addresses/{username}", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning-addresses/{username}",
method: HttpMethod.Get), token);
return await HandleResponse<LightningAddressData>(response);
} }
public virtual async Task RemoveStoreLightningAddress(string storeId, string username, public virtual async Task RemoveStoreLightningAddress(string storeId, string username,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/lightning-addresses/{username}", null, HttpMethod.Delete, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning-addresses/{username}",
method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task<LightningAddressData> AddOrUpdateStoreLightningAddress(string storeId, public virtual async Task<LightningAddressData> AddOrUpdateStoreLightningAddress(string storeId,
string username, LightningAddressData data, string username, LightningAddressData data,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<LightningAddressData>($"api/v1/stores/{storeId}/lightning-addresses/{username}", data, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/lightning-addresses/{username}",
method: HttpMethod.Post, bodyPayload: data), token);
return await HandleResponse<LightningAddressData>(response);
}
} }
} }

View File

@@ -1,23 +1,19 @@
using System; using System.Net.Http;
using System.Collections.Generic;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<PermissionMetadata[]> GetPermissionMetadata(CancellationToken token = default) public virtual async Task<PermissionMetadata[]> GetPermissionMetadata(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("misc/permissions"), token); return await SendHttpRequest<PermissionMetadata[]>("misc/permissions", null, HttpMethod.Get, token);
return await HandleResponse<PermissionMetadata[]>(response);
} }
public virtual async Task<Language[]> GetAvailableLanguages(CancellationToken token = default) public virtual async Task<Language[]> GetAvailableLanguages(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("misc/lang"), token); return await SendHttpRequest<Language[]>("misc/lang", null, HttpMethod.Get, token);
return await HandleResponse<Language[]>(response);
}
} }
} }

View File

@@ -1,56 +1,40 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null, int? skip = null, public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null, int? skip = null,
int? take = null, CancellationToken token = default) int? take = null, CancellationToken token = default)
{ {
Dictionary<string, object> queryPayload = new Dictionary<string, object>(); var queryPayload = new Dictionary<string, object>();
if (seen != null) if (seen != null)
queryPayload.Add(nameof(seen), seen); queryPayload.Add(nameof(seen), seen);
if (skip != null) if (skip != null)
queryPayload.Add(nameof(skip), skip); queryPayload.Add(nameof(skip), skip);
if (take != null) if (take != null)
queryPayload.Add(nameof(take), take); queryPayload.Add(nameof(take), take);
return await SendHttpRequest<IEnumerable<NotificationData>>("api/v1/users/me/notifications", queryPayload, HttpMethod.Get, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/users/me/notifications",
queryPayload), token);
return await HandleResponse<IEnumerable<NotificationData>>(response);
} }
public virtual async Task<NotificationData> GetNotification(string notificationId, public virtual async Task<NotificationData> GetNotification(string notificationId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<NotificationData>($"api/v1/users/me/notifications/{notificationId}", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}"), token);
return await HandleResponse<NotificationData>(response);
} }
public virtual async Task<NotificationData> UpdateNotification(string notificationId, bool? seen, public virtual async Task<NotificationData> UpdateNotification(string notificationId, bool? seen,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<NotificationData>($"api/v1/users/me/notifications/{notificationId}", new UpdateNotification { Seen = seen }, HttpMethod.Put, token);
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}",
method: HttpMethod.Put, bodyPayload: new UpdateNotification() { Seen = seen }), token);
return await HandleResponse<NotificationData>(response);
} }
public virtual async Task RemoveNotification(string notificationId, CancellationToken token = default) public virtual async Task RemoveNotification(string notificationId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/users/me/notifications/{notificationId}", null, HttpMethod.Delete, token);
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}",
method: HttpMethod.Delete), token);
await HandleResponse(response);
}
} }
} }

View File

@@ -5,45 +5,35 @@ using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<OnChainPaymentMethodPreviewResultData> public virtual async Task<OnChainPaymentMethodPreviewResultData>
PreviewProposedStoreOnChainPaymentMethodAddresses( PreviewProposedStoreOnChainPaymentMethodAddresses(
string storeId, string paymentMethodId, string derivationScheme, int offset = 0, string storeId, string paymentMethodId, string derivationScheme, int offset = 0,
int amount = 10, int amount = 10,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<UpdatePaymentMethodRequest, OnChainPaymentMethodPreviewResultData>($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}/preview",
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}/preview", new Dictionary<string, object> { { "offset", offset }, { "amount", amount } },
bodyPayload: new UpdatePaymentMethodRequest() { Config = JValue.CreateString(derivationScheme) }, new UpdatePaymentMethodRequest { Config = JValue.CreateString(derivationScheme) },
queryPayload: new Dictionary<string, object>() { { "offset", offset }, { "amount", amount } }, HttpMethod.Post, token);
method: HttpMethod.Post), token);
return await HandleResponse<OnChainPaymentMethodPreviewResultData>(response);
} }
public virtual async Task<OnChainPaymentMethodPreviewResultData> PreviewStoreOnChainPaymentMethodAddresses( public virtual async Task<OnChainPaymentMethodPreviewResultData> PreviewStoreOnChainPaymentMethodAddresses(
string storeId, string paymentMethodId, int offset = 0, int amount = 10, string storeId, string paymentMethodId, int offset = 0, int amount = 10,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<OnChainPaymentMethodPreviewResultData>($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}/preview",
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}/preview", new Dictionary<string, object> { { "offset", offset }, { "amount", amount } }, HttpMethod.Get, token);
queryPayload: new Dictionary<string, object>() { { "offset", offset }, { "amount", amount } },
method: HttpMethod.Get), token);
return await HandleResponse<OnChainPaymentMethodPreviewResultData>(response);
} }
public virtual async Task<GenerateOnChainWalletResponse> GenerateOnChainWallet(string storeId, public virtual async Task<GenerateOnChainWalletResponse> GenerateOnChainWallet(string storeId,
string paymentMethodId, GenerateOnChainWalletRequest request, string paymentMethodId, GenerateOnChainWalletRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<GenerateOnChainWalletResponse>($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}/generate", request, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}/generate",
bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<GenerateOnChainWalletResponse>(response);
} }
}
} }

View File

@@ -1,27 +1,21 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using NBitcoin;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<OnChainWalletObjectData> GetOnChainWalletObject(string storeId, string cryptoCode, OnChainWalletObjectId objectId, bool? includeNeighbourData = null, CancellationToken token = default) public virtual async Task<OnChainWalletObjectData> GetOnChainWalletObject(string storeId, string cryptoCode, OnChainWalletObjectId objectId, bool? includeNeighbourData = null, CancellationToken token = default)
{ {
Dictionary<string, object> parameters = new Dictionary<string, object>(); var parameters = new Dictionary<string, object>();
if (includeNeighbourData is bool v) if (includeNeighbourData is bool v)
parameters.Add("includeNeighbourData", v); parameters.Add("includeNeighbourData", v);
var response =
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}", parameters, method: HttpMethod.Get), token);
try try
{ {
return await HandleResponse<OnChainWalletObjectData>(response); return await SendHttpRequest<OnChainWalletObjectData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}", parameters, HttpMethod.Get, token);
} }
catch (GreenfieldAPIException err) when (err.APIError.Code == "wallet-object-not-found") catch (GreenfieldAPIException err) when (err.APIError.Code == "wallet-object-not-found")
{ {
@@ -37,46 +31,32 @@ namespace BTCPayServer.Client
parameters.Add("ids", ids); parameters.Add("ids", ids);
if (query?.IncludeNeighbourData is bool v) if (query?.IncludeNeighbourData is bool v)
parameters.Add("includeNeighbourData", v); parameters.Add("includeNeighbourData", v);
var response = return await SendHttpRequest<OnChainWalletObjectData[]>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects", parameters, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects", parameters, method: HttpMethod.Get), token);
return await HandleResponse<OnChainWalletObjectData[]>(response);
} }
public virtual async Task RemoveOnChainWalletObject(string storeId, string cryptoCode, OnChainWalletObjectId objectId, public virtual async Task RemoveOnChainWalletObject(string storeId, string cryptoCode, OnChainWalletObjectId objectId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await SendHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}", null, HttpMethod.Delete, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}", method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task<OnChainWalletObjectData> AddOrUpdateOnChainWalletObject(string storeId, string cryptoCode, AddOnChainWalletObjectRequest request, public virtual async Task<OnChainWalletObjectData> AddOrUpdateOnChainWalletObject(string storeId, string cryptoCode, AddOnChainWalletObjectRequest request,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = return await SendHttpRequest<OnChainWalletObjectData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects", request, HttpMethod.Post, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects", method: HttpMethod.Post, bodyPayload: request), token);
return await HandleResponse<OnChainWalletObjectData>(response);
} }
public virtual async Task AddOrUpdateOnChainWalletLink(string storeId, string cryptoCode, public virtual async Task AddOrUpdateOnChainWalletLink(string storeId, string cryptoCode,
OnChainWalletObjectId objectId, OnChainWalletObjectId objectId,
AddOnChainWalletObjectLinkRequest request = null, AddOnChainWalletObjectLinkRequest request = null,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await SendHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}/links", request, HttpMethod.Post, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}/links", method: HttpMethod.Post, bodyPayload: request), token);
await HandleResponse(response);
} }
public virtual async Task RemoveOnChainWalletLinks(string storeId, string cryptoCode, public virtual async Task RemoveOnChainWalletLinks(string storeId, string cryptoCode,
OnChainWalletObjectId objectId, OnChainWalletObjectId objectId,
OnChainWalletObjectId link, OnChainWalletObjectId link,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await SendHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}/links/{link.Type}/{link.Id}", null, HttpMethod.Delete, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/objects/{objectId.Type}/{objectId.Id}/links/{link.Type}/{link.Id}", method: HttpMethod.Delete), token);
await HandleResponse(response);
}
} }
} }

View File

@@ -7,51 +7,39 @@ using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using NBitcoin; using NBitcoin;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<OnChainWalletOverviewData> ShowOnChainWalletOverview(string storeId, string cryptoCode, public virtual async Task<OnChainWalletOverviewData> ShowOnChainWalletOverview(string storeId, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = return await SendHttpRequest<OnChainWalletOverviewData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet", null, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet"), token);
return await HandleResponse<OnChainWalletOverviewData>(response);
} }
public virtual async Task<OnChainWalletFeeRateData> GetOnChainFeeRate(string storeId, string cryptoCode, int? blockTarget = null, public virtual async Task<OnChainWalletFeeRateData> GetOnChainFeeRate(string storeId, string cryptoCode, int? blockTarget = null,
CancellationToken token = default) CancellationToken token = default)
{ {
Dictionary<string, object> queryParams = new Dictionary<string, object>(); var queryParams = new Dictionary<string, object>();
if (blockTarget != null) if (blockTarget != null)
{ {
queryParams.Add("blockTarget", blockTarget); queryParams.Add("blockTarget", blockTarget);
} }
var response = return await SendHttpRequest<OnChainWalletFeeRateData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/feeRate", queryParams, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/feeRate", queryParams), token);
return await HandleResponse<OnChainWalletFeeRateData>(response);
} }
public virtual async Task<OnChainWalletAddressData> GetOnChainWalletReceiveAddress(string storeId, string cryptoCode, bool forceGenerate = false, public virtual async Task<OnChainWalletAddressData> GetOnChainWalletReceiveAddress(string storeId, string cryptoCode, bool forceGenerate = false,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = return await SendHttpRequest<OnChainWalletAddressData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/address", new Dictionary<string, object>
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/address", new Dictionary<string, object>()
{ {
{"forceGenerate", forceGenerate} {"forceGenerate", forceGenerate}
}), token); }, HttpMethod.Get, token);
return await HandleResponse<OnChainWalletAddressData>(response);
} }
public virtual async Task UnReserveOnChainWalletReceiveAddress(string storeId, string cryptoCode, public virtual async Task UnReserveOnChainWalletReceiveAddress(string storeId, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await SendHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/address", null, HttpMethod.Delete, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/address", method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task<IEnumerable<OnChainWalletTransactionData>> ShowOnChainWalletTransactions( public virtual async Task<IEnumerable<OnChainWalletTransactionData>> ShowOnChainWalletTransactions(
@@ -71,20 +59,14 @@ namespace BTCPayServer.Client
{ {
query.Add(nameof(skip), skip); query.Add(nameof(skip), skip);
} }
var response = return await SendHttpRequest<IEnumerable<OnChainWalletTransactionData>>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", query, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", query), token);
return await HandleResponse<IEnumerable<OnChainWalletTransactionData>>(response);
} }
public virtual async Task<OnChainWalletTransactionData> GetOnChainWalletTransaction( public virtual async Task<OnChainWalletTransactionData> GetOnChainWalletTransaction(
string storeId, string cryptoCode, string transactionId, string storeId, string cryptoCode, string transactionId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = return await SendHttpRequest<OnChainWalletTransactionData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions/{transactionId}", null, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions/{transactionId}"), token);
return await HandleResponse<OnChainWalletTransactionData>(response);
} }
public virtual async Task<OnChainWalletTransactionData> PatchOnChainWalletTransaction( public virtual async Task<OnChainWalletTransactionData> PatchOnChainWalletTransaction(
@@ -92,23 +74,15 @@ namespace BTCPayServer.Client
PatchOnChainTransactionRequest request, PatchOnChainTransactionRequest request,
bool force = false, CancellationToken token = default) bool force = false, CancellationToken token = default)
{ {
var response = return await SendHttpRequest<PatchOnChainTransactionRequest, OnChainWalletTransactionData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions/{transactionId}",
await _httpClient.SendAsync( new Dictionary<string, object> { {"force", force} }, request, HttpMethod.Patch, token);
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions/{transactionId}", queryPayload: new Dictionary<string, object>()
{
{"force", force}
}, bodyPayload: request, HttpMethod.Patch), token);
return await HandleResponse<OnChainWalletTransactionData>(response);
} }
public virtual async Task<IEnumerable<OnChainWalletUTXOData>> GetOnChainWalletUTXOs(string storeId, public virtual async Task<IEnumerable<OnChainWalletUTXOData>> GetOnChainWalletUTXOs(string storeId,
string cryptoCode, string cryptoCode,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = return await SendHttpRequest<IEnumerable<OnChainWalletUTXOData>>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/utxos", null, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/utxos"), token);
return await HandleResponse<IEnumerable<OnChainWalletUTXOData>>(response);
} }
public virtual async Task<OnChainWalletTransactionData> CreateOnChainTransaction(string storeId, public virtual async Task<OnChainWalletTransactionData> CreateOnChainTransaction(string storeId,
@@ -120,10 +94,7 @@ namespace BTCPayServer.Client
throw new ArgumentOutOfRangeException(nameof(request.ProceedWithBroadcast), throw new ArgumentOutOfRangeException(nameof(request.ProceedWithBroadcast),
"Please use CreateOnChainTransactionButDoNotBroadcast when wanting to only create the transaction"); "Please use CreateOnChainTransactionButDoNotBroadcast when wanting to only create the transaction");
} }
var response = return await SendHttpRequest<OnChainWalletTransactionData>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", request, HttpMethod.Post, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", null, request, HttpMethod.Post), token);
return await HandleResponse<OnChainWalletTransactionData>(response);
} }
public virtual async Task<Transaction> CreateOnChainTransactionButDoNotBroadcast(string storeId, public virtual async Task<Transaction> CreateOnChainTransactionButDoNotBroadcast(string storeId,
@@ -135,10 +106,6 @@ namespace BTCPayServer.Client
throw new ArgumentOutOfRangeException(nameof(request.ProceedWithBroadcast), throw new ArgumentOutOfRangeException(nameof(request.ProceedWithBroadcast),
"Please use CreateOnChainTransaction when wanting to also broadcast the transaction"); "Please use CreateOnChainTransaction when wanting to also broadcast the transaction");
} }
var response = return Transaction.Parse(await SendHttpRequest<string>($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", request, HttpMethod.Post, token), network);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", null, request, HttpMethod.Post), token);
return Transaction.Parse(await HandleResponse<string>(response), network);
}
} }
} }

View File

@@ -5,72 +5,49 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<IEnumerable<PaymentRequestData>> GetPaymentRequests(string storeId, public virtual async Task<IEnumerable<PaymentRequestData>> GetPaymentRequests(string storeId,
bool includeArchived = false, bool includeArchived = false,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = return await SendHttpRequest<IEnumerable<PaymentRequestData>>($"api/v1/stores/{storeId}/payment-requests",
await _httpClient.SendAsync( new Dictionary<string, object> { { nameof(includeArchived), includeArchived } }, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests",
new Dictionary<string, object>() { { nameof(includeArchived), includeArchived } }), token);
return await HandleResponse<IEnumerable<PaymentRequestData>>(response);
} }
public virtual async Task<PaymentRequestData> GetPaymentRequest(string storeId, string paymentRequestId, public virtual async Task<PaymentRequestData> GetPaymentRequest(string storeId, string paymentRequestId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<PaymentRequestData>($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}"), token);
return await HandleResponse<PaymentRequestData>(response);
} }
public virtual async Task ArchivePaymentRequest(string storeId, string paymentRequestId, public virtual async Task ArchivePaymentRequest(string storeId, string paymentRequestId,
CancellationToken token = default) CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}", null, HttpMethod.Delete, token);
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}",
method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task<Client.Models.InvoiceData> PayPaymentRequest(string storeId, string paymentRequestId, PayPaymentRequestRequest request, CancellationToken token = default) public virtual async Task<Client.Models.InvoiceData> PayPaymentRequest(string storeId, string paymentRequestId, PayPaymentRequestRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); if (storeId is null) throw new ArgumentNullException(nameof(storeId));
if (storeId is null) if (paymentRequestId is null) throw new ArgumentNullException(nameof(paymentRequestId));
throw new ArgumentNullException(nameof(storeId)); return await SendHttpRequest<InvoiceData>($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}/pay", request, HttpMethod.Post, token);
if (paymentRequestId is null)
throw new ArgumentNullException(nameof(paymentRequestId));
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}/pay", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<Client.Models.InvoiceData>(response);
} }
public virtual async Task<PaymentRequestData> CreatePaymentRequest(string storeId, public virtual async Task<PaymentRequestData> CreatePaymentRequest(string storeId,
CreatePaymentRequestRequest request, CancellationToken token = default) CreatePaymentRequestRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<PaymentRequestData>($"api/v1/stores/{storeId}/payment-requests", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests", bodyPayload: request,
method: HttpMethod.Post), token);
return await HandleResponse<PaymentRequestData>(response);
} }
public virtual async Task<PaymentRequestData> UpdatePaymentRequest(string storeId, string paymentRequestId, public virtual async Task<PaymentRequestData> UpdatePaymentRequest(string storeId, string paymentRequestId,
UpdatePaymentRequestRequest request, CancellationToken token = default) UpdatePaymentRequestRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<PaymentRequestData>($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}", request, HttpMethod.Put, token);
var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}", bodyPayload: request,
method: HttpMethod.Put), token);
return await HandleResponse<PaymentRequestData>(response);
}
} }
} }

View File

@@ -1,18 +1,16 @@
#nullable enable #nullable enable
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<IEnumerable<PayoutProcessorData>> GetPayoutProcessors(CancellationToken token = default)
{ {
public virtual async Task<IEnumerable<PayoutProcessorData>> GetPayoutProcessors( return await SendHttpRequest<IEnumerable<PayoutProcessorData>>("api/v1/payout-processors", null, HttpMethod.Get, token);
CancellationToken token = default)
{
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/payout-processors"), token);
return await HandleResponse<IEnumerable<PayoutProcessorData>>(response);
}
} }
} }

View File

@@ -5,113 +5,90 @@ using System.Threading.Tasks;
using System.Web; using System.Web;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<PullPaymentData> CreatePullPayment(string storeId, CreatePullPaymentRequest request, CancellationToken cancellationToken = default) public virtual async Task<PullPaymentData> CreatePullPayment(string storeId, CreatePullPaymentRequest request, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/pull-payments", bodyPayload: request, method: HttpMethod.Post), cancellationToken); return await SendHttpRequest<PullPaymentData>($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/pull-payments", request, HttpMethod.Post, cancellationToken);
return await HandleResponse<PullPaymentData>(response);
} }
public virtual async Task<PullPaymentData> GetPullPayment(string pullPaymentId, CancellationToken cancellationToken = default) public virtual async Task<PullPaymentData> GetPullPayment(string pullPaymentId, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}", method: HttpMethod.Get), cancellationToken); return await SendHttpRequest<PullPaymentData>($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}", null, HttpMethod.Get, cancellationToken);
return await HandleResponse<PullPaymentData>(response);
} }
public virtual async Task<RegisterBoltcardResponse> RegisterBoltcard(string pullPaymentId, RegisterBoltcardRequest request, CancellationToken cancellationToken = default) public virtual async Task<RegisterBoltcardResponse> RegisterBoltcard(string pullPaymentId, RegisterBoltcardRequest request, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/boltcards", bodyPayload: request, method: HttpMethod.Post), cancellationToken); return await SendHttpRequest<RegisterBoltcardResponse>($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/boltcards", request, HttpMethod.Post, cancellationToken);
return await HandleResponse<RegisterBoltcardResponse>(response);
} }
public virtual async Task<PullPaymentData[]> GetPullPayments(string storeId, bool includeArchived = false, CancellationToken cancellationToken = default) public virtual async Task<PullPaymentData[]> GetPullPayments(string storeId, bool includeArchived = false, CancellationToken cancellationToken = default)
{ {
Dictionary<string, object> query = new Dictionary<string, object>(); var query = new Dictionary<string, object> { { "includeArchived", includeArchived } };
query.Add("includeArchived", includeArchived); return await SendHttpRequest<PullPaymentData[]>($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/pull-payments", query, HttpMethod.Get, cancellationToken);
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/pull-payments", queryPayload: query, method: HttpMethod.Get), cancellationToken);
return await HandleResponse<PullPaymentData[]>(response);
} }
public virtual async Task ArchivePullPayment(string storeId, string pullPaymentId, CancellationToken cancellationToken = default) public virtual async Task ArchivePullPayment(string storeId, string pullPaymentId, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}", method: HttpMethod.Delete), cancellationToken); await SendHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}", null, HttpMethod.Delete, cancellationToken);
await HandleResponse(response);
} }
public virtual async Task<PayoutData[]> GetPayouts(string pullPaymentId, bool includeCancelled = false, CancellationToken cancellationToken = default) public virtual async Task<PayoutData[]> GetPayouts(string pullPaymentId, bool includeCancelled = false, CancellationToken cancellationToken = default)
{ {
Dictionary<string, object> query = new Dictionary<string, object>(); var query = new Dictionary<string, object> { { "includeCancelled", includeCancelled } };
query.Add("includeCancelled", includeCancelled); return await SendHttpRequest<PayoutData[]>($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/payouts", query, HttpMethod.Get, cancellationToken);
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/payouts", queryPayload: query, method: HttpMethod.Get), cancellationToken);
return await HandleResponse<PayoutData[]>(response);
} }
public virtual async Task<PayoutData[]> GetStorePayouts(string storeId, bool includeCancelled = false, CancellationToken cancellationToken = default) public virtual async Task<PayoutData[]> GetStorePayouts(string storeId, bool includeCancelled = false, CancellationToken cancellationToken = default)
{ {
Dictionary<string, object> query = new Dictionary<string, object>(); var query = new Dictionary<string, object> { { "includeCancelled", includeCancelled } };
query.Add("includeCancelled", includeCancelled); return await SendHttpRequest<PayoutData[]>($"api/v1/stores/{storeId}/payouts", queryPayload: query, method: HttpMethod.Get, cancellationToken);
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payouts", queryPayload: query, method: HttpMethod.Get), cancellationToken);
return await HandleResponse<PayoutData[]>(response);
} }
public virtual async Task<PayoutData> CreatePayout(string pullPaymentId, CreatePayoutRequest payoutRequest, CancellationToken cancellationToken = default) public virtual async Task<PayoutData> CreatePayout(string pullPaymentId, CreatePayoutRequest payoutRequest, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/payouts", bodyPayload: payoutRequest, method: HttpMethod.Post), cancellationToken); return await SendHttpRequest<PayoutData>($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/payouts", bodyPayload: payoutRequest, HttpMethod.Post, cancellationToken);
return await HandleResponse<PayoutData>(response);
} }
public virtual async Task<PayoutData> GetPullPaymentPayout(string pullPaymentId, string payoutId, CancellationToken cancellationToken = default) public virtual async Task<PayoutData> GetPullPaymentPayout(string pullPaymentId, string payoutId, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/payouts/{payoutId}", method: HttpMethod.Get), cancellationToken); return await SendHttpRequest<PayoutData>($"api/v1/pull-payments/{HttpUtility.UrlEncode(pullPaymentId)}/payouts/{payoutId}", null, HttpMethod.Get, cancellationToken);
return await HandleResponse<PayoutData>(response);
} }
public virtual async Task<PayoutData> GetStorePayout(string storeId, string payoutId, CancellationToken cancellationToken = default) public virtual async Task<PayoutData> GetStorePayout(string storeId, string payoutId, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payouts/{payoutId}", method: HttpMethod.Get), cancellationToken); return await SendHttpRequest<PayoutData>($"api/v1/stores/{storeId}/payouts/{payoutId}", null, HttpMethod.Get, cancellationToken);
return await HandleResponse<PayoutData>(response);
} }
public virtual async Task<PayoutData> CreatePayout(string storeId, CreatePayoutThroughStoreRequest payoutRequest, CancellationToken cancellationToken = default) public virtual async Task<PayoutData> CreatePayout(string storeId, CreatePayoutThroughStoreRequest payoutRequest, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payouts", bodyPayload: payoutRequest, method: HttpMethod.Post), cancellationToken); return await SendHttpRequest<PayoutData>($"api/v1/stores/{storeId}/payouts", bodyPayload: payoutRequest, method: HttpMethod.Post, cancellationToken);
return await HandleResponse<PayoutData>(response);
} }
public virtual async Task CancelPayout(string storeId, string payoutId, CancellationToken cancellationToken = default) public virtual async Task CancelPayout(string storeId, string payoutId, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}", method: HttpMethod.Delete), cancellationToken); await SendHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}", null, HttpMethod.Delete, cancellationToken);
await HandleResponse(response);
} }
public virtual async Task<PayoutData> ApprovePayout(string storeId, string payoutId, ApprovePayoutRequest request, CancellationToken cancellationToken = default) public virtual async Task<PayoutData> ApprovePayout(string storeId, string payoutId, ApprovePayoutRequest request, CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}", bodyPayload: request, method: HttpMethod.Post), cancellationToken); return await SendHttpRequest<PayoutData>($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}", request, HttpMethod.Post, cancellationToken);
return await HandleResponse<PayoutData>(response);
} }
public virtual async Task MarkPayoutPaid(string storeId, string payoutId, public virtual async Task MarkPayoutPaid(string storeId, string payoutId, CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}/mark-paid", null, HttpMethod.Post, cancellationToken);
CreateHttpRequest(
$"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}/mark-paid",
method: HttpMethod.Post), cancellationToken);
await HandleResponse(response);
}
public virtual async Task MarkPayout(string storeId, string payoutId, MarkPayoutRequest request,
CancellationToken cancellationToken = default)
{
var response = await _httpClient.SendAsync(
CreateHttpRequest(
$"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}/mark",
method: HttpMethod.Post, bodyPayload: request), cancellationToken);
await HandleResponse(response);
} }
public virtual async Task<PullPaymentLNURL> GetPullPaymentLNURL(string pullPaymentId, public virtual async Task MarkPayout(string storeId, string payoutId, MarkPayoutRequest request, CancellationToken cancellationToken = default)
CancellationToken cancellationToken = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{HttpUtility.UrlEncode(storeId)}/payouts/{HttpUtility.UrlEncode(payoutId)}/mark", request, HttpMethod.Post, cancellationToken);
CreateHttpRequest(
$"/api/v1/pull-payments/{pullPaymentId}/lnurl",
method: HttpMethod.Get), cancellationToken);
return await HandleResponse<PullPaymentLNURL>(response);
} }
public virtual async Task<PullPaymentLNURL> GetPullPaymentLNURL(string pullPaymentId, CancellationToken cancellationToken = default)
{
return await SendHttpRequest<PullPaymentLNURL>($"/api/v1/pull-payments/{pullPaymentId}/lnurl", null, HttpMethod.Get, cancellationToken);
} }
} }

View File

@@ -1,22 +1,20 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<ServerInfoData> GetServerInfo(CancellationToken token = default) public virtual async Task<ServerInfoData> GetServerInfo(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/server/info"), token); return await SendHttpRequest<ServerInfoData>("api/v1/server/info", null, HttpMethod.Get, token);
return await HandleResponse<ServerInfoData>(response);
} }
public virtual async Task<List<RoleData>> GetServerRoles(CancellationToken token = default) public virtual async Task<List<RoleData>> GetServerRoles(CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/server/roles"), token); return await SendHttpRequest<List<RoleData>>("api/v1/server/roles", null, HttpMethod.Get, token);
return await HandleResponse<List<RoleData>>(response);
}
} }
} }

View File

@@ -3,35 +3,22 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<EmailSettingsData> GetStoreEmailSettings(string storeId, CancellationToken token = default)
{ {
public virtual async Task<EmailSettingsData> GetStoreEmailSettings(string storeId, return await SendHttpRequest<EmailSettingsData>($"api/v1/stores/{storeId}/email", null, HttpMethod.Get, token);
CancellationToken token = default)
{
using var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/email", method: HttpMethod.Get),
token);
return await HandleResponse<EmailSettingsData>(response);
} }
public virtual async Task<EmailSettingsData> UpdateStoreEmailSettings(string storeId, EmailSettingsData request, public virtual async Task<EmailSettingsData> UpdateStoreEmailSettings(string storeId, EmailSettingsData request, CancellationToken token = default)
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( return await SendHttpRequest<EmailSettingsData>($"api/v1/stores/{storeId}/email", request, method: HttpMethod.Put, token);
CreateHttpRequest($"api/v1/stores/{storeId}/email", bodyPayload: request, method: HttpMethod.Put),
token);
return await HandleResponse<EmailSettingsData>(response);
} }
public virtual async Task SendEmail(string storeId, SendEmailRequest request, public virtual async Task SendEmail(string storeId, SendEmailRequest request, CancellationToken token = default)
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/email/send", request, HttpMethod.Post, token);
CreateHttpRequest($"api/v1/stores/{storeId}/email/send", bodyPayload: request, method: HttpMethod.Post),
token);
await HandleResponse(response);
}
} }
} }

View File

@@ -4,48 +4,31 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<GenericPaymentMethodData> UpdateStorePaymentMethod(string storeId, string paymentMethodId, UpdatePaymentMethodRequest request, CancellationToken token = default)
{ {
public virtual async Task<GenericPaymentMethodData> UpdateStorePaymentMethod( return await SendHttpRequest<GenericPaymentMethodData>($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}", request, HttpMethod.Put, token);
string storeId,
string paymentMethodId,
UpdatePaymentMethodRequest request,
CancellationToken token = default)
{
var response =
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}", bodyPayload: request, method: HttpMethod.Put),
token);
return await HandleResponse<GenericPaymentMethodData>(response);
}
public virtual async Task RemoveStorePaymentMethod(string storeId, string paymentMethodId)
{
var response =
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}", method: HttpMethod.Delete),
CancellationToken.None);
await HandleResponse(response);
} }
public virtual async Task<GenericPaymentMethodData> GetStorePaymentMethod(string storeId, public virtual async Task RemoveStorePaymentMethod(string storeId, string paymentMethodId)
string paymentMethodId, bool? includeConfig = null, CancellationToken token = default) {
await SendHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}", null, HttpMethod.Delete, CancellationToken.None);
}
public virtual async Task<GenericPaymentMethodData> GetStorePaymentMethod(string storeId, string paymentMethodId, bool? includeConfig = null, CancellationToken token = default)
{ {
var query = new Dictionary<string, object>(); var query = new Dictionary<string, object>();
if (includeConfig != null) if (includeConfig != null)
{ {
query.Add(nameof(includeConfig), includeConfig); query.Add(nameof(includeConfig), includeConfig);
} }
return await SendHttpRequest<GenericPaymentMethodData>($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}", query, HttpMethod.Get, token);
var response =
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/{paymentMethodId}",
query), token);
return await HandleResponse<GenericPaymentMethodData>(response);
} }
public virtual async Task<GenericPaymentMethodData[]> GetStorePaymentMethods(string storeId,
bool? onlyEnabled = null, bool? includeConfig = null, CancellationToken token = default) public virtual async Task<GenericPaymentMethodData[]> GetStorePaymentMethods(string storeId, bool? onlyEnabled = null, bool? includeConfig = null, CancellationToken token = default)
{ {
var query = new Dictionary<string, object>(); var query = new Dictionary<string, object>();
if (onlyEnabled != null) if (onlyEnabled != null)
@@ -57,11 +40,6 @@ namespace BTCPayServer.Client
query.Add(nameof(includeConfig), includeConfig); query.Add(nameof(includeConfig), includeConfig);
} }
var response = return await SendHttpRequest<GenericPaymentMethodData[]>($"api/v1/stores/{storeId}/payment-methods", query, HttpMethod.Get, token);
await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods",
query), token);
return await HandleResponse<GenericPaymentMethodData[]>(response);
}
} }
} }

View File

@@ -5,44 +5,37 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<IEnumerable<PayoutProcessorData>> GetPayoutProcessors(string storeId, CancellationToken token = default)
{ {
public virtual async Task<IEnumerable<PayoutProcessorData>> GetPayoutProcessors(string storeId, return await SendHttpRequest<IEnumerable<PayoutProcessorData>>($"api/v1/stores/{storeId}/payout-processors", null, HttpMethod.Get, token);
CancellationToken token = default)
{
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payout-processors"), token);
return await HandleResponse<IEnumerable<PayoutProcessorData>>(response);
} }
public virtual async Task RemovePayoutProcessor(string storeId, string processor, string paymentMethod, CancellationToken token = default) public virtual async Task RemovePayoutProcessor(string storeId, string processor, string paymentMethod, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payout-processors/{processor}/{paymentMethod}", null, HttpMethod.Delete), token); await SendHttpRequest($"api/v1/stores/{storeId}/payout-processors/{processor}/{paymentMethod}", null, HttpMethod.Delete, token);
await HandleResponse(response);
} }
public virtual async Task<IEnumerable<LightningAutomatedPayoutSettings>> GetStoreLightningAutomatedPayoutProcessors(string storeId, string? paymentMethod = null, public virtual async Task<IEnumerable<LightningAutomatedPayoutSettings>> GetStoreLightningAutomatedPayoutProcessors(string storeId, string? paymentMethod = null, CancellationToken token = default)
CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payout-processors/LightningAutomatedPayoutSenderFactory{(paymentMethod is null ? string.Empty : $"/{paymentMethod}")}"), token); return await SendHttpRequest<IEnumerable<LightningAutomatedPayoutSettings>>($"api/v1/stores/{storeId}/payout-processors/LightningAutomatedPayoutSenderFactory{(paymentMethod is null ? string.Empty : $"/{paymentMethod}")}", null, HttpMethod.Get, token);
return await HandleResponse<IEnumerable<LightningAutomatedPayoutSettings>>(response);
} }
public virtual async Task<LightningAutomatedPayoutSettings> UpdateStoreLightningAutomatedPayoutProcessors(string storeId, string paymentMethod, LightningAutomatedPayoutSettings request, CancellationToken token = default) public virtual async Task<LightningAutomatedPayoutSettings> UpdateStoreLightningAutomatedPayoutProcessors(string storeId, string paymentMethod, LightningAutomatedPayoutSettings request, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payout-processors/LightningAutomatedPayoutSenderFactory/{paymentMethod}", null, request, HttpMethod.Put), token); return await SendHttpRequest<LightningAutomatedPayoutSettings>($"api/v1/stores/{storeId}/payout-processors/LightningAutomatedPayoutSenderFactory/{paymentMethod}", request, HttpMethod.Put, token);
return await HandleResponse<LightningAutomatedPayoutSettings>(response);
}
public virtual async Task<OnChainAutomatedPayoutSettings> UpdateStoreOnChainAutomatedPayoutProcessors(string storeId, string paymentMethod, OnChainAutomatedPayoutSettings request, CancellationToken token = default)
{
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payout-processors/OnChainAutomatedPayoutSenderFactory/{paymentMethod}", null, request, HttpMethod.Put), token);
return await HandleResponse<OnChainAutomatedPayoutSettings>(response);
} }
public virtual async Task<IEnumerable<OnChainAutomatedPayoutSettings>> GetStoreOnChainAutomatedPayoutProcessors(string storeId, string? paymentMethod = null, public virtual async Task<OnChainAutomatedPayoutSettings> UpdateStoreOnChainAutomatedPayoutProcessors(string storeId, string paymentMethod, OnChainAutomatedPayoutSettings request, CancellationToken token = default)
CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/payout-processors/OnChainAutomatedPayoutSenderFactory{(paymentMethod is null ? string.Empty : $"/{paymentMethod}")}"), token); return await SendHttpRequest<OnChainAutomatedPayoutSettings>($"api/v1/stores/{storeId}/payout-processors/OnChainAutomatedPayoutSenderFactory/{paymentMethod}", request, HttpMethod.Put, token);
return await HandleResponse<IEnumerable<OnChainAutomatedPayoutSettings>>(response);
} }
public virtual async Task<IEnumerable<OnChainAutomatedPayoutSettings>> GetStoreOnChainAutomatedPayoutProcessors(string storeId, string? paymentMethod = null, CancellationToken token = default)
{
return await SendHttpRequest<IEnumerable<OnChainAutomatedPayoutSettings>>($"api/v1/stores/{storeId}/payout-processors/OnChainAutomatedPayoutSenderFactory{(paymentMethod is null ? string.Empty : $"/{paymentMethod}")}", null, HttpMethod.Get, token);
} }
} }

View File

@@ -4,61 +4,34 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<StoreRateConfiguration> GetStoreRateConfiguration(string storeId, CancellationToken token = default)
{ {
public virtual async Task<StoreRateConfiguration> GetStoreRateConfiguration(string storeId, return await SendHttpRequest<StoreRateConfiguration>($"api/v1/stores/{storeId}/rates/configuration", null, HttpMethod.Get, token);
CancellationToken token = default)
{
using var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/rates/configuration", method: HttpMethod.Get),
token);
return await HandleResponse<StoreRateConfiguration>(response);
} }
public virtual async Task<List<RateSource>> GetRateSources( public virtual async Task<List<RateSource>> GetRateSources(CancellationToken token = default)
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( return await SendHttpRequest<List<RateSource>>("misc/rate-sources", null, HttpMethod.Get, token);
CreateHttpRequest($"misc/rate-sources", method: HttpMethod.Get),
token);
return await HandleResponse<List<RateSource>>(response);
} }
public virtual async Task<StoreRateConfiguration> UpdateStoreRateConfiguration(string storeId, public virtual async Task<StoreRateConfiguration> UpdateStoreRateConfiguration(string storeId, StoreRateConfiguration request, CancellationToken token = default)
StoreRateConfiguration request,
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( return await SendHttpRequest<StoreRateConfiguration>($"api/v1/stores/{storeId}/rates/configuration", request, HttpMethod.Put, token);
CreateHttpRequest($"api/v1/stores/{storeId}/rates/configuration", bodyPayload: request,
method: HttpMethod.Put),
token);
return await HandleResponse<StoreRateConfiguration>(response);
} }
public virtual async Task<List<StoreRateResult>> PreviewUpdateStoreRateConfiguration(string storeId, public virtual async Task<List<StoreRateResult>> PreviewUpdateStoreRateConfiguration(string storeId, StoreRateConfiguration request, string[] currencyPair = null, CancellationToken token = default)
StoreRateConfiguration request,
string[] currencyPair,
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( var queryPayload = currencyPair == null ? null : new Dictionary<string, object> { { "currencyPair", currencyPair } };
CreateHttpRequest($"api/v1/stores/{storeId}/rates/configuration/preview", bodyPayload: request, return await SendHttpRequest<StoreRateConfiguration, List<StoreRateResult>>($"api/v1/stores/{storeId}/rates/configuration/preview", queryPayload, request, HttpMethod.Post, token);
queryPayload: new Dictionary<string, object>() { { "currencyPair", currencyPair } },
method: HttpMethod.Post),
token);
return await HandleResponse<List<StoreRateResult>>(response);
} }
public virtual async Task<List<StoreRateResult>> GetStoreRates(string storeId, string[] currencyPair, public virtual async Task<List<StoreRateResult>> GetStoreRates(string storeId, string[] currencyPair = null, CancellationToken token = default)
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( var queryPayload = currencyPair == null ? null : new Dictionary<string, object> { { "currencyPair", currencyPair } };
CreateHttpRequest($"api/v1/stores/{storeId}/rates", return await SendHttpRequest<List<StoreRateResult>>($"api/v1/stores/{storeId}/rates", queryPayload, HttpMethod.Get, token);
queryPayload: new Dictionary<string, object>() { { "currencyPair", currencyPair } },
method: HttpMethod.Get),
token);
return await HandleResponse<List<StoreRateResult>>(response);
}
} }
} }

View File

@@ -5,40 +5,28 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<List<RoleData>> GetStoreRoles(string storeId, CancellationToken token = default)
{ {
public virtual async Task<List<RoleData>> GetStoreRoles(string storeId, return await SendHttpRequest<List<RoleData>>($"api/v1/stores/{storeId}/roles", null, HttpMethod.Get,token);
CancellationToken token = default)
{
using var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/roles"), token);
return await HandleResponse<List<RoleData>>(response);
} }
public virtual async Task<IEnumerable<StoreUserData>> GetStoreUsers(string storeId, public virtual async Task<IEnumerable<StoreUserData>> GetStoreUsers(string storeId, CancellationToken token = default)
CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/users"), token); return await SendHttpRequest<IEnumerable<StoreUserData>>($"api/v1/stores/{storeId}/users", null, HttpMethod.Get, token);
return await HandleResponse<IEnumerable<StoreUserData>>(response);
} }
public virtual async Task RemoveStoreUser(string storeId, string userId, CancellationToken token = default) public virtual async Task RemoveStoreUser(string storeId, string userId, CancellationToken token = default)
{ {
using var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}/users/{userId}", null, HttpMethod.Delete, token);
CreateHttpRequest($"api/v1/stores/{storeId}/users/{userId}", method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task AddStoreUser(string storeId, StoreUserData request, public virtual async Task AddStoreUser(string storeId, StoreUserData request, CancellationToken token = default)
CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); await SendHttpRequest<StoreUserData>($"api/v1/stores/{storeId}/users", request, HttpMethod.Post, token);
using var response = await _httpClient.SendAsync(
CreateHttpRequest($"api/v1/stores/{storeId}/users", bodyPayload: request, method: HttpMethod.Post),
token);
await HandleResponse(response);
}
} }
} }

View File

@@ -5,47 +5,36 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<IEnumerable<StoreData>> GetStores(CancellationToken token = default) public virtual async Task<IEnumerable<StoreData>> GetStores(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/stores"), token); return await SendHttpRequest<IEnumerable<StoreData>>("api/v1/stores", null, HttpMethod.Get, token);
return await HandleResponse<IEnumerable<StoreData>>(response);
} }
public virtual async Task<StoreData> GetStore(string storeId, CancellationToken token = default) public virtual async Task<StoreData> GetStore(string storeId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( return await SendHttpRequest<StoreData>($"api/v1/stores/{storeId}", null, HttpMethod.Get, token);
CreateHttpRequest($"api/v1/stores/{storeId}"), token);
return await HandleResponse<StoreData>(response);
} }
public virtual async Task RemoveStore(string storeId, CancellationToken token = default) public virtual async Task RemoveStore(string storeId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync( await SendHttpRequest($"api/v1/stores/{storeId}", null, HttpMethod.Delete, token);
CreateHttpRequest($"api/v1/stores/{storeId}", method: HttpMethod.Delete), token);
await HandleResponse(response);
} }
public virtual async Task<StoreData> CreateStore(CreateStoreRequest request, CancellationToken token = default) public virtual async Task<StoreData> CreateStore(CreateStoreRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); return await SendHttpRequest<StoreData>("api/v1/stores", request, HttpMethod.Post, token);
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/stores", bodyPayload: request, method: HttpMethod.Post), token);
return await HandleResponse<StoreData>(response);
} }
public virtual async Task<StoreData> UpdateStore(string storeId, UpdateStoreRequest request, CancellationToken token = default) public virtual async Task<StoreData> UpdateStore(string storeId, UpdateStoreRequest request, CancellationToken token = default)
{ {
if (request == null) if (request == null) throw new ArgumentNullException(nameof(request));
throw new ArgumentNullException(nameof(request)); if (storeId == null) throw new ArgumentNullException(nameof(storeId));
if (storeId == null) return await SendHttpRequest<StoreData>($"api/v1/stores/{storeId}", request, HttpMethod.Put, token);
throw new ArgumentNullException(nameof(storeId));
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}", bodyPayload: request, method: HttpMethod.Put), token);
return await HandleResponse<StoreData>(response);
} }
}
} }

View File

@@ -4,33 +4,28 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
public virtual async Task<ApplicationUserData> GetCurrentUser(CancellationToken token = default) public virtual async Task<ApplicationUserData> GetCurrentUser(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/users/me"), token); return await SendHttpRequest<ApplicationUserData>("api/v1/users/me", null, HttpMethod.Get, token);
return await HandleResponse<ApplicationUserData>(response);
} }
public virtual async Task<ApplicationUserData> CreateUser(CreateApplicationUserRequest request, public virtual async Task<ApplicationUserData> CreateUser(CreateApplicationUserRequest request, CancellationToken token = default)
CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/users", null, request, HttpMethod.Post), token); return await SendHttpRequest<ApplicationUserData>("api/v1/users", request, HttpMethod.Post, token);
return await HandleResponse<ApplicationUserData>(response);
} }
public virtual async Task DeleteUser(string userId, CancellationToken token = default) public virtual async Task DeleteUser(string userId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{userId}", null, HttpMethod.Delete), token); await SendHttpRequest($"api/v1/users/{userId}", null, HttpMethod.Delete, token);
await HandleResponse(response);
} }
public virtual async Task<ApplicationUserData> GetUserByIdOrEmail(string idOrEmail, CancellationToken token = default) public virtual async Task<ApplicationUserData> GetUserByIdOrEmail(string idOrEmail, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{idOrEmail}", null, HttpMethod.Get), token); return await SendHttpRequest<ApplicationUserData>($"api/v1/users/{idOrEmail}", null, HttpMethod.Get, token);
return await HandleResponse<ApplicationUserData>(response);
} }
public virtual async Task<bool> LockUser(string idOrEmail, bool locked, CancellationToken token = default) public virtual async Task<bool> LockUser(string idOrEmail, bool locked, CancellationToken token = default)
@@ -51,13 +46,11 @@ namespace BTCPayServer.Client
public virtual async Task<ApplicationUserData[]> GetUsers(CancellationToken token = default) public virtual async Task<ApplicationUserData[]> GetUsers(CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/", null, HttpMethod.Get), token); return await SendHttpRequest<ApplicationUserData[]>("api/v1/users/", null, HttpMethod.Get, token);
return await HandleResponse<ApplicationUserData[]>(response);
} }
public virtual async Task DeleteCurrentUser(CancellationToken token = default) public virtual async Task DeleteCurrentUser(CancellationToken token = default)
{ {
await DeleteUser("me", token); await DeleteUser("me", token);
} }
}
} }

View File

@@ -3,61 +3,56 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient public virtual async Task<StoreWebhookData> CreateWebhook(string storeId, CreateStoreWebhookRequest create, CancellationToken token = default)
{ {
public virtual async Task<StoreWebhookData> CreateWebhook(string storeId, Client.Models.CreateStoreWebhookRequest create, CancellationToken token = default) return await SendHttpRequest<StoreWebhookData>($"api/v1/stores/{storeId}/webhooks", create, HttpMethod.Post, token);
{
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks", bodyPayload: create, method: HttpMethod.Post), token);
return await HandleResponse<StoreWebhookData>(response);
} }
public virtual async Task<StoreWebhookData> GetWebhook(string storeId, string webhookId, CancellationToken token = default) public virtual async Task<StoreWebhookData> GetWebhook(string storeId, string webhookId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}"), token); var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}"), token);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound) return response.StatusCode == System.Net.HttpStatusCode.NotFound ? null : await HandleResponse<StoreWebhookData>(response);
return null;
return await HandleResponse<StoreWebhookData>(response);
} }
public virtual async Task<StoreWebhookData> UpdateWebhook(string storeId, string webhookId, Models.UpdateStoreWebhookRequest update, CancellationToken token = default)
public virtual async Task<StoreWebhookData> UpdateWebhook(string storeId, string webhookId, UpdateStoreWebhookRequest update, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}", bodyPayload: update, method: HttpMethod.Put), token); return await SendHttpRequest<StoreWebhookData>($"api/v1/stores/{storeId}/webhooks/{webhookId}", update, HttpMethod.Put, token);
return await HandleResponse<StoreWebhookData>(response);
} }
public virtual async Task<bool> DeleteWebhook(string storeId, string webhookId, CancellationToken token = default) public virtual async Task<bool> DeleteWebhook(string storeId, string webhookId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}", method: HttpMethod.Delete), token); var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}", method: HttpMethod.Delete), token);
return response.IsSuccessStatusCode; return response.IsSuccessStatusCode;
} }
public virtual async Task<StoreWebhookData[]> GetWebhooks(string storeId, CancellationToken token = default) public virtual async Task<StoreWebhookData[]> GetWebhooks(string storeId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks"), token); return await SendHttpRequest<StoreWebhookData[]>($"api/v1/stores/{storeId}/webhooks", null, HttpMethod.Get, token);
return await HandleResponse<StoreWebhookData[]>(response);
} }
public virtual async Task<WebhookDeliveryData[]> GetWebhookDeliveries(string storeId, string webhookId, CancellationToken token = default) public virtual async Task<WebhookDeliveryData[]> GetWebhookDeliveries(string storeId, string webhookId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries"), token); return await SendHttpRequest<WebhookDeliveryData[]>($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries", null, HttpMethod.Get, token);
return await HandleResponse<WebhookDeliveryData[]>(response);
} }
public virtual async Task<WebhookDeliveryData> GetWebhookDelivery(string storeId, string webhookId, string deliveryId, CancellationToken token = default) public virtual async Task<WebhookDeliveryData> GetWebhookDelivery(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}"), token); var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}"), token);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound) return response.StatusCode == System.Net.HttpStatusCode.NotFound ? null : await HandleResponse<WebhookDeliveryData>(response);
return null;
return await HandleResponse<WebhookDeliveryData>(response);
} }
public virtual async Task<string> RedeliverWebhook(string storeId, string webhookId, string deliveryId, CancellationToken token = default) public virtual async Task<string> RedeliverWebhook(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/redeliver", null, HttpMethod.Post), token); return await SendHttpRequest<string>($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/redeliver", null, HttpMethod.Post, token);
return await HandleResponse<string>(response);
} }
public virtual async Task<WebhookEvent> GetWebhookDeliveryRequest(string storeId, string webhookId, string deliveryId, CancellationToken token = default) public virtual async Task<WebhookEvent> GetWebhookDeliveryRequest(string storeId, string webhookId, string deliveryId, CancellationToken token = default)
{ {
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/request"), token); var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/stores/{storeId}/webhooks/{webhookId}/deliveries/{deliveryId}/request"), token);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound) return response.StatusCode == System.Net.HttpStatusCode.NotFound ? null : await HandleResponse<WebhookEvent>(response);
return null;
return await HandleResponse<WebhookEvent>(response);
}
} }
} }

View File

@@ -9,26 +9,26 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public partial class BTCPayServerClient
{ {
public partial class BTCPayServerClient
{
private readonly string _apiKey; private readonly string _apiKey;
private readonly Uri _btcpayHost; private readonly Uri _btcpayHost;
private readonly string _username; private readonly string _username;
private readonly string _password; private readonly string _password;
private readonly HttpClient _httpClient; protected readonly HttpClient _httpClient;
public Uri Host => _btcpayHost; public Uri Host => _btcpayHost;
public string APIKey => _apiKey; public string APIKey => _apiKey;
public BTCPayServerClient(Uri btcpayHost, HttpClient httpClient = null) public BTCPayServerClient(Uri btcpayHost, HttpClient httpClient = null)
{ {
if (btcpayHost == null) if (btcpayHost == null) throw new ArgumentNullException(nameof(btcpayHost));
throw new ArgumentNullException(nameof(btcpayHost));
_btcpayHost = btcpayHost; _btcpayHost = btcpayHost;
_httpClient = httpClient ?? new HttpClient(); _httpClient = httpClient ?? new HttpClient();
} }
public BTCPayServerClient(Uri btcpayHost, string APIKey, HttpClient httpClient = null) public BTCPayServerClient(Uri btcpayHost, string APIKey, HttpClient httpClient = null)
{ {
_apiKey = APIKey; _apiKey = APIKey;
@@ -70,32 +70,59 @@ namespace BTCPayServer.Client
message.EnsureSuccessStatusCode(); message.EnsureSuccessStatusCode();
} }
protected async Task<T> HandleResponse<T>(HttpResponseMessage message) protected virtual async Task<T> HandleResponse<T>(HttpResponseMessage message)
{ {
await HandleResponse(message); await HandleResponse(message);
var str = await message.Content.ReadAsStringAsync(); var str = await message.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(str); return JsonConvert.DeserializeObject<T>(str);
} }
public async Task<T> SendHttpRequest<T>(string path, public virtual async Task SendHttpRequest(string path,
Dictionary<string, object> queryPayload = null,
HttpMethod method = null, CancellationToken cancellationToken = default)
{
using var resp = await _httpClient.SendAsync(CreateHttpRequest(path, queryPayload, method), cancellationToken);
await HandleResponse(resp);
}
public virtual async Task<T> SendHttpRequest<T>(string path,
Dictionary<string, object> queryPayload = null, Dictionary<string, object> queryPayload = null,
HttpMethod method = null, CancellationToken cancellationToken = default) HttpMethod method = null, CancellationToken cancellationToken = default)
{ {
using var resp = await _httpClient.SendAsync(CreateHttpRequest(path, queryPayload, method), cancellationToken); using var resp = await _httpClient.SendAsync(CreateHttpRequest(path, queryPayload, method), cancellationToken);
return await HandleResponse<T>(resp); return await HandleResponse<T>(resp);
} }
public async Task<T> SendHttpRequest<T>(string path,
public virtual async Task SendHttpRequest(string path,
object bodyPayload = null,
HttpMethod method = null, CancellationToken cancellationToken = default)
{
using var resp = await _httpClient.SendAsync(CreateHttpRequest(path: path, bodyPayload: bodyPayload, method: method), cancellationToken);
await HandleResponse(resp);
}
protected virtual async Task<T> SendHttpRequest<T>(string path,
object bodyPayload = null, object bodyPayload = null,
HttpMethod method = null, CancellationToken cancellationToken = default) HttpMethod method = null, CancellationToken cancellationToken = default)
{ {
using var resp = await _httpClient.SendAsync(CreateHttpRequest(path: path, bodyPayload: bodyPayload, method: method), cancellationToken); using var resp = await _httpClient.SendAsync(CreateHttpRequest(path: path, bodyPayload: bodyPayload, method: method), cancellationToken);
return await HandleResponse<T>(resp); return await HandleResponse<T>(resp);
} }
protected virtual async Task<TRes> SendHttpRequest<TReq, TRes>(string path,
Dictionary<string, object> queryPayload = null,
TReq bodyPayload = default, HttpMethod method = null, CancellationToken cancellationToken = default)
{
using var resp = await _httpClient.SendAsync(CreateHttpRequest(path: path, bodyPayload: bodyPayload, queryPayload: queryPayload, method: method), cancellationToken);
return await HandleResponse<TRes>(resp);
}
protected virtual HttpRequestMessage CreateHttpRequest(string path, protected virtual HttpRequestMessage CreateHttpRequest(string path,
Dictionary<string, object> queryPayload = null, Dictionary<string, object> queryPayload = null,
HttpMethod method = null) HttpMethod method = null)
{ {
UriBuilder uriBuilder = new UriBuilder(_btcpayHost) { Path = path }; var uriBuilder = new UriBuilder(_btcpayHost);
uriBuilder.Path += (uriBuilder.Path.EndsWith("/") || path.StartsWith("/") ? "" : "/") + path;
if (queryPayload != null && queryPayload.Any()) if (queryPayload != null && queryPayload.Any())
{ {
AppendPayloadToQuery(uriBuilder, queryPayload); AppendPayloadToQuery(uriBuilder, queryPayload);
@@ -106,10 +133,9 @@ namespace BTCPayServer.Client
httpRequest.Headers.Authorization = new AuthenticationHeaderValue("token", _apiKey); httpRequest.Headers.Authorization = new AuthenticationHeaderValue("token", _apiKey);
else if (!string.IsNullOrEmpty(_username)) else if (!string.IsNullOrEmpty(_username))
{ {
httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(Encoding.ASCII.GetBytes(_username + ":" + _password))); httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(_username + ":" + _password)));
} }
return httpRequest; return httpRequest;
} }
@@ -158,5 +184,4 @@ namespace BTCPayServer.Client
AppendPayloadToQuery(uri, keyValuePair); AppendPayloadToQuery(uri, keyValuePair);
} }
} }
}
} }

View File

@@ -1,17 +1,15 @@
using System; using System;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public class GreenfieldAPIException : Exception
{ {
public class GreenfieldAPIException : Exception
{
public GreenfieldAPIException(int httpCode, Models.GreenfieldAPIError error) : base(error.Message) public GreenfieldAPIException(int httpCode, Models.GreenfieldAPIError error) : base(error.Message)
{ {
if (error == null) if (error == null) throw new ArgumentNullException(nameof(error));
throw new ArgumentNullException(nameof(error));
HttpCode = httpCode; HttpCode = httpCode;
APIError = error; APIError = error;
} }
public Models.GreenfieldAPIError APIError { get; } public Models.GreenfieldAPIError APIError { get; }
public int HttpCode { get; set; } public int HttpCode { get; set; }
}
} }

View File

@@ -2,20 +2,19 @@ using System;
using System.Text; using System.Text;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
namespace BTCPayServer.Client namespace BTCPayServer.Client;
public class GreenfieldValidationException : Exception
{ {
public class GreenfieldValidationException : Exception public GreenfieldValidationException(GreenfieldValidationError[] errors) : base(BuildMessage(errors))
{
public GreenfieldValidationException(Models.GreenfieldValidationError[] errors) : base(BuildMessage(errors))
{ {
ValidationErrors = errors; ValidationErrors = errors;
} }
private static string BuildMessage(GreenfieldValidationError[] errors) private static string BuildMessage(GreenfieldValidationError[] errors)
{ {
if (errors == null) if (errors == null) throw new ArgumentNullException(nameof(errors));
throw new ArgumentNullException(nameof(errors)); var builder = new StringBuilder();
StringBuilder builder = new StringBuilder();
foreach (var error in errors) foreach (var error in errors)
{ {
builder.AppendLine($"{error.Path}: {error.Message}"); builder.AppendLine($"{error.Path}: {error.Message}");
@@ -23,6 +22,5 @@ namespace BTCPayServer.Client
return builder.ToString(); return builder.ToString();
} }
public Models.GreenfieldValidationError[] ValidationErrors { get; } public GreenfieldValidationError[] ValidationErrors { get; }
}
} }

View File

@@ -11,8 +11,7 @@ namespace BTCPayServer.Client.Models
public GreenfieldAPIError(string code, string message) public GreenfieldAPIError(string code, string message)
{ {
code = code ?? "generic-error"; code = code ?? "generic-error";
if (message == null) if (message == null) throw new ArgumentNullException(nameof(message));
throw new ArgumentNullException(nameof(message));
Code = code; Code = code;
Message = message; Message = message;
} }

View File

@@ -6,14 +6,12 @@ namespace BTCPayServer.Client.Models
{ {
public GreenfieldValidationError() public GreenfieldValidationError()
{ {
} }
public GreenfieldValidationError(string path, string message) public GreenfieldValidationError(string path, string message)
{ {
if (path == null) if (path == null) throw new ArgumentNullException(nameof(path));
throw new ArgumentNullException(nameof(path)); if (message == null) throw new ArgumentNullException(nameof(message));
if (message == null)
throw new ArgumentNullException(nameof(message));
Path = path; Path = path;
Message = message; Message = message;
} }

View File

@@ -1128,14 +1128,14 @@ namespace BTCPayServer.Controllers.Greenfield
} }
public override async Task<List<StoreRateResult>> GetStoreRates(string storeId, public override async Task<List<StoreRateResult>> GetStoreRates(string storeId,
string[] currencyPair, CancellationToken token = default) string[] currencyPair = null, CancellationToken token = default)
{ {
return GetFromActionResult<List<StoreRateResult>>(await GetController<GreenfieldStoreRatesController>().GetStoreRates(currencyPair)); return GetFromActionResult<List<StoreRateResult>>(await GetController<GreenfieldStoreRatesController>().GetStoreRates(currencyPair));
} }
public override async Task<List<StoreRateResult>> PreviewUpdateStoreRateConfiguration(string storeId, public override async Task<List<StoreRateResult>> PreviewUpdateStoreRateConfiguration(string storeId,
StoreRateConfiguration request, StoreRateConfiguration request,
string[] currencyPair, string[] currencyPair = null,
CancellationToken token = default) CancellationToken token = default)
{ {
return GetFromActionResult<List<StoreRateResult>>( return GetFromActionResult<List<StoreRateResult>>(