2020-05-19 19:59:23 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Client.Models;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Client
|
|
|
|
{
|
|
|
|
public partial class BTCPayServerClient
|
|
|
|
{
|
|
|
|
public virtual async Task<IEnumerable<PaymentRequestData>> GetPaymentRequests(string storeId,
|
2020-07-24 12:46:46 +02:00
|
|
|
bool includeArchived = false,
|
2020-05-19 19:59:23 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response =
|
2020-07-24 12:46:46 +02:00
|
|
|
await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests",
|
2021-12-31 16:59:02 +09:00
|
|
|
new Dictionary<string, object>() { { nameof(includeArchived), includeArchived } }), token);
|
2020-05-19 19:59:23 +02:00
|
|
|
return await HandleResponse<IEnumerable<PaymentRequestData>>(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task<PaymentRequestData> GetPaymentRequest(string storeId, string paymentRequestId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}"), token);
|
|
|
|
return await HandleResponse<PaymentRequestData>(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task ArchivePaymentRequest(string storeId, string paymentRequestId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}",
|
|
|
|
method: HttpMethod.Delete), token);
|
2020-06-08 23:40:58 +09:00
|
|
|
await HandleResponse(response);
|
2020-05-19 19:59:23 +02:00
|
|
|
}
|
|
|
|
|
2022-11-02 18:41:19 +09:00
|
|
|
public virtual async Task<Client.Models.InvoiceData> PayPaymentRequest(string storeId, string paymentRequestId, PayPaymentRequestRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null)
|
|
|
|
throw new ArgumentNullException(nameof(request));
|
|
|
|
if (storeId is null)
|
|
|
|
throw new ArgumentNullException(nameof(storeId));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-05-19 19:59:23 +02:00
|
|
|
public virtual async Task<PaymentRequestData> CreatePaymentRequest(string storeId,
|
|
|
|
CreatePaymentRequestRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null)
|
|
|
|
throw new ArgumentNullException(nameof(request));
|
|
|
|
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,
|
|
|
|
UpdatePaymentRequestRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null)
|
|
|
|
throw new ArgumentNullException(nameof(request));
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/stores/{storeId}/payment-requests/{paymentRequestId}", bodyPayload: request,
|
|
|
|
method: HttpMethod.Put), token);
|
|
|
|
return await HandleResponse<PaymentRequestData>(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|