2021-07-27 14:11:47 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net.Http;
|
2022-02-02 12:09:08 +01:00
|
|
|
using System.Reflection;
|
2021-07-27 14:11:47 +02:00
|
|
|
using System.Security.Claims;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Abstractions.Contracts;
|
|
|
|
using BTCPayServer.Client;
|
|
|
|
using BTCPayServer.Client.Models;
|
2022-03-11 10:17:40 +01:00
|
|
|
using BTCPayServer.Controllers.GreenField;
|
2021-07-27 14:11:47 +02:00
|
|
|
using BTCPayServer.Data;
|
2022-06-06 15:57:55 +02:00
|
|
|
using BTCPayServer.Security;
|
2022-01-14 05:05:23 +01:00
|
|
|
using BTCPayServer.Security.Greenfield;
|
2022-03-11 10:17:50 +01:00
|
|
|
using BTCPayServer.Services.Mails;
|
2021-07-27 14:11:47 +02:00
|
|
|
using BTCPayServer.Services.Stores;
|
2022-02-02 12:09:08 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-07-27 14:11:47 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-02-02 12:09:08 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-07-27 14:11:47 +02:00
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
using NBitcoin;
|
2021-07-27 16:53:44 +02:00
|
|
|
using NBXplorer.Models;
|
2022-03-11 10:17:50 +01:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
2021-07-27 14:11:47 +02:00
|
|
|
using InvoiceData = BTCPayServer.Client.Models.InvoiceData;
|
|
|
|
using Language = BTCPayServer.Client.Models.Language;
|
|
|
|
using NotificationData = BTCPayServer.Client.Models.NotificationData;
|
|
|
|
using PaymentRequestData = BTCPayServer.Client.Models.PaymentRequestData;
|
|
|
|
using PayoutData = BTCPayServer.Client.Models.PayoutData;
|
|
|
|
using PullPaymentData = BTCPayServer.Client.Models.PullPaymentData;
|
|
|
|
using StoreData = BTCPayServer.Client.Models.StoreData;
|
|
|
|
using StoreWebhookData = BTCPayServer.Client.Models.StoreWebhookData;
|
|
|
|
using WebhookDeliveryData = BTCPayServer.Client.Models.WebhookDeliveryData;
|
|
|
|
|
2022-01-14 05:05:23 +01:00
|
|
|
namespace BTCPayServer.Controllers.Greenfield
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
public class BTCPayServerClientFactory : IBTCPayServerClientFactory
|
|
|
|
{
|
|
|
|
private readonly StoreRepository _storeRepository;
|
|
|
|
private readonly IOptionsMonitor<IdentityOptions> _identityOptions;
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldStoreOnChainPaymentMethodsController _chainPaymentMethodsController;
|
|
|
|
private readonly GreenfieldStoreOnChainWalletsController _storeOnChainWalletsController;
|
2022-03-11 10:17:50 +01:00
|
|
|
|
|
|
|
private readonly GreenfieldStoreLightningNetworkPaymentMethodsController
|
|
|
|
_storeLightningNetworkPaymentMethodsController;
|
|
|
|
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldStoreLNURLPayPaymentMethodsController _storeLnurlPayPaymentMethodsController;
|
|
|
|
private readonly GreenfieldHealthController _healthController;
|
|
|
|
private readonly GreenfieldPaymentRequestsController _paymentRequestController;
|
|
|
|
private readonly GreenfieldApiKeysController _apiKeysController;
|
|
|
|
private readonly GreenfieldNotificationsController _notificationsController;
|
|
|
|
private readonly GreenfieldUsersController _usersController;
|
|
|
|
private readonly GreenfieldStoresController _storesController;
|
|
|
|
private readonly GreenfieldInternalLightningNodeApiController _internalLightningNodeApiController;
|
|
|
|
private readonly GreenfieldStoreLightningNodeApiController _storeLightningNodeApiController;
|
|
|
|
private readonly GreenfieldInvoiceController _greenFieldInvoiceController;
|
2021-07-27 14:11:47 +02:00
|
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldServerInfoController _greenFieldServerInfoController;
|
|
|
|
private readonly GreenfieldStoreWebhooksController _storeWebhooksController;
|
2021-07-27 14:11:47 +02:00
|
|
|
private readonly GreenfieldPullPaymentController _greenfieldPullPaymentController;
|
2022-01-07 04:32:00 +01:00
|
|
|
private readonly UIHomeController _homeController;
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldStorePaymentMethodsController _storePaymentMethodsController;
|
2022-03-11 10:17:40 +01:00
|
|
|
private readonly GreenfieldStoreEmailController _greenfieldStoreEmailController;
|
2022-03-11 10:17:50 +01:00
|
|
|
private readonly GreenfieldStoreUsersController _greenfieldStoreUsersController;
|
2022-04-24 05:19:34 +02:00
|
|
|
private readonly GreenfieldStorePayoutProcessorsController _greenfieldStorePayoutProcessorsController;
|
|
|
|
private readonly GreenfieldPayoutProcessorsController _greenfieldPayoutProcessorsController;
|
2022-06-06 15:57:55 +02:00
|
|
|
|
|
|
|
private readonly GreenfieldStoreAutomatedOnChainPayoutProcessorsController
|
|
|
|
_greenfieldStoreAutomatedOnChainPayoutProcessorsController;
|
|
|
|
|
|
|
|
private readonly GreenfieldStoreAutomatedLightningPayoutProcessorsController
|
|
|
|
_greenfieldStoreAutomatedLightningPayoutProcessorsController;
|
|
|
|
|
2022-02-02 12:09:08 +01:00
|
|
|
private readonly IServiceProvider _serviceProvider;
|
2021-07-27 14:11:47 +02:00
|
|
|
|
|
|
|
public BTCPayServerClientFactory(StoreRepository storeRepository,
|
|
|
|
IOptionsMonitor<IdentityOptions> identityOptions,
|
2022-01-07 04:17:59 +01:00
|
|
|
GreenfieldStoreOnChainPaymentMethodsController chainPaymentMethodsController,
|
|
|
|
GreenfieldStoreOnChainWalletsController storeOnChainWalletsController,
|
|
|
|
GreenfieldStoreLightningNetworkPaymentMethodsController storeLightningNetworkPaymentMethodsController,
|
|
|
|
GreenfieldStoreLNURLPayPaymentMethodsController storeLnurlPayPaymentMethodsController,
|
|
|
|
GreenfieldHealthController healthController,
|
|
|
|
GreenfieldPaymentRequestsController paymentRequestController,
|
|
|
|
GreenfieldApiKeysController apiKeysController,
|
|
|
|
GreenfieldNotificationsController notificationsController,
|
|
|
|
GreenfieldUsersController usersController,
|
|
|
|
GreenfieldStoresController storesController,
|
|
|
|
GreenfieldInternalLightningNodeApiController internalLightningNodeApiController,
|
|
|
|
GreenfieldStoreLightningNodeApiController storeLightningNodeApiController,
|
|
|
|
GreenfieldInvoiceController greenFieldInvoiceController,
|
2021-07-27 14:11:47 +02:00
|
|
|
UserManager<ApplicationUser> userManager,
|
2022-01-07 04:17:59 +01:00
|
|
|
GreenfieldServerInfoController greenFieldServerInfoController,
|
|
|
|
GreenfieldStoreWebhooksController storeWebhooksController,
|
2021-07-27 14:11:47 +02:00
|
|
|
GreenfieldPullPaymentController greenfieldPullPaymentController,
|
2022-01-07 04:32:00 +01:00
|
|
|
UIHomeController homeController,
|
2022-02-02 12:09:08 +01:00
|
|
|
GreenfieldStorePaymentMethodsController storePaymentMethodsController,
|
2022-03-11 10:17:40 +01:00
|
|
|
GreenfieldStoreEmailController greenfieldStoreEmailController,
|
2022-03-11 10:17:50 +01:00
|
|
|
GreenfieldStoreUsersController greenfieldStoreUsersController,
|
2022-04-24 05:19:34 +02:00
|
|
|
GreenfieldStorePayoutProcessorsController greenfieldStorePayoutProcessorsController,
|
|
|
|
GreenfieldPayoutProcessorsController greenfieldPayoutProcessorsController,
|
2022-06-06 15:57:55 +02:00
|
|
|
GreenfieldStoreAutomatedOnChainPayoutProcessorsController
|
|
|
|
greenfieldStoreAutomatedOnChainPayoutProcessorsController,
|
|
|
|
GreenfieldStoreAutomatedLightningPayoutProcessorsController
|
|
|
|
greenfieldStoreAutomatedLightningPayoutProcessorsController,
|
2022-02-02 12:09:08 +01:00
|
|
|
IServiceProvider serviceProvider)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
_storeRepository = storeRepository;
|
|
|
|
_identityOptions = identityOptions;
|
|
|
|
_chainPaymentMethodsController = chainPaymentMethodsController;
|
|
|
|
_storeOnChainWalletsController = storeOnChainWalletsController;
|
|
|
|
_storeLightningNetworkPaymentMethodsController = storeLightningNetworkPaymentMethodsController;
|
2021-10-25 08:18:02 +02:00
|
|
|
_storeLnurlPayPaymentMethodsController = storeLnurlPayPaymentMethodsController;
|
2021-07-27 14:11:47 +02:00
|
|
|
_healthController = healthController;
|
|
|
|
_paymentRequestController = paymentRequestController;
|
|
|
|
_apiKeysController = apiKeysController;
|
|
|
|
_notificationsController = notificationsController;
|
|
|
|
_usersController = usersController;
|
|
|
|
_storesController = storesController;
|
|
|
|
_internalLightningNodeApiController = internalLightningNodeApiController;
|
|
|
|
_storeLightningNodeApiController = storeLightningNodeApiController;
|
|
|
|
_greenFieldInvoiceController = greenFieldInvoiceController;
|
|
|
|
_userManager = userManager;
|
|
|
|
_greenFieldServerInfoController = greenFieldServerInfoController;
|
|
|
|
_storeWebhooksController = storeWebhooksController;
|
|
|
|
_greenfieldPullPaymentController = greenfieldPullPaymentController;
|
|
|
|
_homeController = homeController;
|
|
|
|
_storePaymentMethodsController = storePaymentMethodsController;
|
2022-03-11 10:17:40 +01:00
|
|
|
_greenfieldStoreEmailController = greenfieldStoreEmailController;
|
2022-03-11 10:17:50 +01:00
|
|
|
_greenfieldStoreUsersController = greenfieldStoreUsersController;
|
2022-04-24 05:19:34 +02:00
|
|
|
_greenfieldStorePayoutProcessorsController = greenfieldStorePayoutProcessorsController;
|
|
|
|
_greenfieldPayoutProcessorsController = greenfieldPayoutProcessorsController;
|
2022-06-06 15:57:55 +02:00
|
|
|
_greenfieldStoreAutomatedOnChainPayoutProcessorsController =
|
|
|
|
greenfieldStoreAutomatedOnChainPayoutProcessorsController;
|
|
|
|
_greenfieldStoreAutomatedLightningPayoutProcessorsController =
|
|
|
|
greenfieldStoreAutomatedLightningPayoutProcessorsController;
|
2022-02-02 12:09:08 +01:00
|
|
|
_serviceProvider = serviceProvider;
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
2022-03-30 15:04:51 +02:00
|
|
|
public Task<BTCPayServerClient> Create(string userId, params string[] storeIds)
|
|
|
|
{
|
|
|
|
return Create(userId, storeIds, new DefaultHttpContext()
|
|
|
|
{
|
|
|
|
Request =
|
|
|
|
{
|
|
|
|
Scheme = "https",
|
|
|
|
Host = new HostString("dummy.com"),
|
|
|
|
Path = new PathString(),
|
|
|
|
PathBase = new PathString(),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<BTCPayServerClient> Create(string userId, string[] storeIds, HttpContext context)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(userId))
|
|
|
|
{
|
|
|
|
var user = await _userManager.FindByIdAsync(userId);
|
|
|
|
List<Claim> claims = new List<Claim>
|
|
|
|
{
|
|
|
|
new Claim(_identityOptions.CurrentValue.ClaimsIdentity.UserIdClaimType, userId),
|
2022-01-14 05:05:23 +01:00
|
|
|
new Claim(GreenfieldConstants.ClaimTypes.Permission,
|
2021-07-27 14:11:47 +02:00
|
|
|
Permission.Create(Policies.Unrestricted).ToString())
|
|
|
|
};
|
|
|
|
claims.AddRange((await _userManager.GetRolesAsync(user)).Select(s =>
|
|
|
|
new Claim(_identityOptions.CurrentValue.ClaimsIdentity.RoleClaimType, s)));
|
|
|
|
context.User =
|
2022-03-11 10:17:50 +01:00
|
|
|
new ClaimsPrincipal(new ClaimsIdentity(claims,
|
|
|
|
$"Local{GreenfieldConstants.AuthenticationType}WithUser"));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.User =
|
2022-03-11 10:17:50 +01:00
|
|
|
new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>(),
|
|
|
|
$"Local{GreenfieldConstants.AuthenticationType}"));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (storeIds?.Any() is true)
|
|
|
|
{
|
|
|
|
context.SetStoreData(await _storeRepository.FindStore(storeIds.First()));
|
|
|
|
context.SetStoresData(await _storeRepository.GetStoresByUserId(userId, storeIds));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
context.SetStoresData(await _storeRepository.GetStoresByUserId(userId));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new LocalBTCPayServerClient(
|
2022-02-02 12:09:08 +01:00
|
|
|
_serviceProvider,
|
2021-07-27 14:11:47 +02:00
|
|
|
_chainPaymentMethodsController,
|
|
|
|
_storeOnChainWalletsController,
|
|
|
|
_healthController,
|
|
|
|
_paymentRequestController,
|
|
|
|
_apiKeysController,
|
|
|
|
_notificationsController,
|
|
|
|
_usersController,
|
|
|
|
_storesController,
|
|
|
|
_storeLightningNodeApiController,
|
|
|
|
_internalLightningNodeApiController,
|
|
|
|
_storeLightningNetworkPaymentMethodsController,
|
2021-10-25 08:18:02 +02:00
|
|
|
_storeLnurlPayPaymentMethodsController,
|
2021-07-27 14:11:47 +02:00
|
|
|
_greenFieldInvoiceController,
|
|
|
|
_greenFieldServerInfoController,
|
|
|
|
_storeWebhooksController,
|
|
|
|
_greenfieldPullPaymentController,
|
|
|
|
_homeController,
|
|
|
|
_storePaymentMethodsController,
|
2022-03-11 10:17:40 +01:00
|
|
|
_greenfieldStoreEmailController,
|
2022-03-11 10:17:50 +01:00
|
|
|
_greenfieldStoreUsersController,
|
2022-04-24 05:19:34 +02:00
|
|
|
_greenfieldStorePayoutProcessorsController,
|
|
|
|
_greenfieldPayoutProcessorsController,
|
|
|
|
_greenfieldStoreAutomatedOnChainPayoutProcessorsController,
|
|
|
|
_greenfieldStoreAutomatedLightningPayoutProcessorsController,
|
2022-06-06 15:57:55 +02:00
|
|
|
new LocalHttpContextAccessor() {HttpContext = context}
|
2021-07-27 14:11:47 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 10:17:50 +01:00
|
|
|
public class LocalHttpContextAccessor : IHttpContextAccessor
|
2022-02-21 11:48:40 +01:00
|
|
|
{
|
2022-04-24 05:19:34 +02:00
|
|
|
public HttpContext HttpContext { get; set; }
|
2022-03-11 10:17:50 +01:00
|
|
|
}
|
2022-02-21 11:48:40 +01:00
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public class LocalBTCPayServerClient : BTCPayServerClient
|
|
|
|
{
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldStoreOnChainPaymentMethodsController _chainPaymentMethodsController;
|
|
|
|
private readonly GreenfieldStoreOnChainWalletsController _storeOnChainWalletsController;
|
|
|
|
private readonly GreenfieldHealthController _healthController;
|
|
|
|
private readonly GreenfieldPaymentRequestsController _paymentRequestController;
|
|
|
|
private readonly GreenfieldApiKeysController _apiKeysController;
|
|
|
|
private readonly GreenfieldNotificationsController _notificationsController;
|
|
|
|
private readonly GreenfieldUsersController _usersController;
|
|
|
|
private readonly GreenfieldStoresController _storesController;
|
|
|
|
private readonly GreenfieldStoreLightningNodeApiController _storeLightningNodeApiController;
|
|
|
|
private readonly GreenfieldInternalLightningNodeApiController _lightningNodeApiController;
|
2022-03-11 10:17:50 +01:00
|
|
|
|
|
|
|
private readonly GreenfieldStoreLightningNetworkPaymentMethodsController
|
|
|
|
_storeLightningNetworkPaymentMethodsController;
|
|
|
|
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldStoreLNURLPayPaymentMethodsController _storeLnurlPayPaymentMethodsController;
|
|
|
|
private readonly GreenfieldInvoiceController _greenFieldInvoiceController;
|
|
|
|
private readonly GreenfieldServerInfoController _greenFieldServerInfoController;
|
|
|
|
private readonly GreenfieldStoreWebhooksController _storeWebhooksController;
|
2021-07-27 14:11:47 +02:00
|
|
|
private readonly GreenfieldPullPaymentController _greenfieldPullPaymentController;
|
2022-01-07 04:32:00 +01:00
|
|
|
private readonly UIHomeController _homeController;
|
2022-01-07 04:17:59 +01:00
|
|
|
private readonly GreenfieldStorePaymentMethodsController _storePaymentMethodsController;
|
2022-03-11 10:17:40 +01:00
|
|
|
private readonly GreenfieldStoreEmailController _greenfieldStoreEmailController;
|
2022-04-24 05:19:34 +02:00
|
|
|
private readonly GreenfieldStorePayoutProcessorsController _greenfieldStorePayoutProcessorsController;
|
|
|
|
private readonly GreenfieldPayoutProcessorsController _greenfieldPayoutProcessorsController;
|
2022-06-06 15:57:55 +02:00
|
|
|
|
|
|
|
private readonly GreenfieldStoreAutomatedOnChainPayoutProcessorsController
|
|
|
|
_greenfieldStoreAutomatedOnChainPayoutProcessorsController;
|
|
|
|
|
|
|
|
private readonly GreenfieldStoreAutomatedLightningPayoutProcessorsController
|
|
|
|
_greenfieldStoreAutomatedLightningPayoutProcessorsController;
|
|
|
|
|
2022-03-11 10:17:50 +01:00
|
|
|
private readonly GreenfieldStoreUsersController _greenfieldStoreUsersController;
|
2021-07-27 14:11:47 +02:00
|
|
|
|
2022-02-02 12:09:08 +01:00
|
|
|
public LocalBTCPayServerClient(
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
GreenfieldStoreOnChainPaymentMethodsController chainPaymentMethodsController,
|
2022-01-07 04:17:59 +01:00
|
|
|
GreenfieldStoreOnChainWalletsController storeOnChainWalletsController,
|
|
|
|
GreenfieldHealthController healthController,
|
|
|
|
GreenfieldPaymentRequestsController paymentRequestController,
|
|
|
|
GreenfieldApiKeysController apiKeysController,
|
|
|
|
GreenfieldNotificationsController notificationsController,
|
|
|
|
GreenfieldUsersController usersController,
|
|
|
|
GreenfieldStoresController storesController,
|
|
|
|
GreenfieldStoreLightningNodeApiController storeLightningNodeApiController,
|
|
|
|
GreenfieldInternalLightningNodeApiController lightningNodeApiController,
|
|
|
|
GreenfieldStoreLightningNetworkPaymentMethodsController storeLightningNetworkPaymentMethodsController,
|
|
|
|
GreenfieldStoreLNURLPayPaymentMethodsController storeLnurlPayPaymentMethodsController,
|
|
|
|
GreenfieldInvoiceController greenFieldInvoiceController,
|
|
|
|
GreenfieldServerInfoController greenFieldServerInfoController,
|
|
|
|
GreenfieldStoreWebhooksController storeWebhooksController,
|
2021-07-27 14:11:47 +02:00
|
|
|
GreenfieldPullPaymentController greenfieldPullPaymentController,
|
2022-01-07 04:32:00 +01:00
|
|
|
UIHomeController homeController,
|
2022-01-07 04:17:59 +01:00
|
|
|
GreenfieldStorePaymentMethodsController storePaymentMethodsController,
|
2022-03-11 10:17:40 +01:00
|
|
|
GreenfieldStoreEmailController greenfieldStoreEmailController,
|
2022-03-11 10:17:50 +01:00
|
|
|
GreenfieldStoreUsersController greenfieldStoreUsersController,
|
2022-04-24 05:19:34 +02:00
|
|
|
GreenfieldStorePayoutProcessorsController greenfieldStorePayoutProcessorsController,
|
|
|
|
GreenfieldPayoutProcessorsController greenfieldPayoutProcessorsController,
|
2022-06-06 15:57:55 +02:00
|
|
|
GreenfieldStoreAutomatedOnChainPayoutProcessorsController
|
|
|
|
greenfieldStoreAutomatedOnChainPayoutProcessorsController,
|
|
|
|
GreenfieldStoreAutomatedLightningPayoutProcessorsController
|
|
|
|
greenfieldStoreAutomatedLightningPayoutProcessorsController,
|
2021-07-27 14:11:47 +02:00
|
|
|
IHttpContextAccessor httpContextAccessor) : base(new Uri("https://dummy.local"), "", "")
|
|
|
|
{
|
|
|
|
_chainPaymentMethodsController = chainPaymentMethodsController;
|
|
|
|
_storeOnChainWalletsController = storeOnChainWalletsController;
|
|
|
|
_healthController = healthController;
|
|
|
|
_paymentRequestController = paymentRequestController;
|
|
|
|
_apiKeysController = apiKeysController;
|
|
|
|
_notificationsController = notificationsController;
|
|
|
|
_usersController = usersController;
|
|
|
|
_storesController = storesController;
|
|
|
|
_storeLightningNodeApiController = storeLightningNodeApiController;
|
|
|
|
_lightningNodeApiController = lightningNodeApiController;
|
|
|
|
_storeLightningNetworkPaymentMethodsController = storeLightningNetworkPaymentMethodsController;
|
2021-10-25 08:18:02 +02:00
|
|
|
_storeLnurlPayPaymentMethodsController = storeLnurlPayPaymentMethodsController;
|
2021-07-27 14:11:47 +02:00
|
|
|
_greenFieldInvoiceController = greenFieldInvoiceController;
|
|
|
|
_greenFieldServerInfoController = greenFieldServerInfoController;
|
|
|
|
_storeWebhooksController = storeWebhooksController;
|
|
|
|
_greenfieldPullPaymentController = greenfieldPullPaymentController;
|
|
|
|
_homeController = homeController;
|
|
|
|
_storePaymentMethodsController = storePaymentMethodsController;
|
2022-03-11 10:17:40 +01:00
|
|
|
_greenfieldStoreEmailController = greenfieldStoreEmailController;
|
2022-03-11 10:17:50 +01:00
|
|
|
_greenfieldStoreUsersController = greenfieldStoreUsersController;
|
2022-04-24 05:19:34 +02:00
|
|
|
_greenfieldStorePayoutProcessorsController = greenfieldStorePayoutProcessorsController;
|
|
|
|
_greenfieldPayoutProcessorsController = greenfieldPayoutProcessorsController;
|
2022-06-06 15:57:55 +02:00
|
|
|
_greenfieldStoreAutomatedOnChainPayoutProcessorsController =
|
|
|
|
greenfieldStoreAutomatedOnChainPayoutProcessorsController;
|
|
|
|
_greenfieldStoreAutomatedLightningPayoutProcessorsController =
|
|
|
|
greenfieldStoreAutomatedLightningPayoutProcessorsController;
|
2021-07-27 14:11:47 +02:00
|
|
|
|
|
|
|
var controllers = new[]
|
|
|
|
{
|
|
|
|
chainPaymentMethodsController, storeOnChainWalletsController, healthController,
|
|
|
|
paymentRequestController, apiKeysController, notificationsController, usersController,
|
|
|
|
storeLightningNetworkPaymentMethodsController, greenFieldInvoiceController, storeWebhooksController,
|
|
|
|
greenFieldServerInfoController, greenfieldPullPaymentController, storesController, homeController,
|
2022-06-06 15:57:55 +02:00
|
|
|
storePaymentMethodsController, greenfieldStoreUsersController, lightningNodeApiController,
|
|
|
|
storeLightningNodeApiController as ControllerBase, greenfieldStoreEmailController,
|
|
|
|
greenfieldStorePayoutProcessorsController, greenfieldPayoutProcessorsController,
|
2022-04-24 05:19:34 +02:00
|
|
|
greenfieldStoreAutomatedOnChainPayoutProcessorsController,
|
2022-06-06 15:57:55 +02:00
|
|
|
greenfieldStoreAutomatedLightningPayoutProcessorsController, storeLnurlPayPaymentMethodsController
|
2021-07-27 14:11:47 +02:00
|
|
|
};
|
2022-02-02 12:09:08 +01:00
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
var authoverride = new AuthorizationService(new GreenfieldAuthorizationHandler(httpContextAccessor,
|
|
|
|
serviceProvider.GetService<UserManager<ApplicationUser>>(),
|
|
|
|
serviceProvider.GetService<StoreRepository>()));
|
2022-02-02 12:09:08 +01:00
|
|
|
|
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
foreach (var controller in controllers)
|
|
|
|
{
|
|
|
|
controller.ControllerContext.HttpContext = httpContextAccessor.HttpContext;
|
2022-02-02 12:09:08 +01:00
|
|
|
var authInterface = typeof(IAuthorizationService);
|
2022-06-06 15:57:55 +02:00
|
|
|
var type = controller.GetType();
|
|
|
|
do
|
2022-02-02 12:09:08 +01:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.FlattenHierarchy |
|
|
|
|
BindingFlags.Instance |
|
|
|
|
BindingFlags.NonPublic |
|
|
|
|
BindingFlags.Public |
|
|
|
|
BindingFlags.Static)
|
|
|
|
.Where(info =>
|
|
|
|
authInterface == info.FieldType || authInterface.IsAssignableFrom(info.FieldType)))
|
|
|
|
{
|
|
|
|
fieldInfo.SetValue(controller, authoverride);
|
|
|
|
}
|
|
|
|
|
|
|
|
type = type.BaseType;
|
|
|
|
} while (type is not null);
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
class AuthorizationService : IAuthorizationService
|
2022-02-02 12:09:08 +01:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
private readonly GreenfieldAuthorizationHandler _greenfieldAuthorizationHandler;
|
2022-02-02 12:09:08 +01:00
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public AuthorizationService(GreenfieldAuthorizationHandler greenfieldAuthorizationHandler)
|
|
|
|
{
|
|
|
|
_greenfieldAuthorizationHandler = greenfieldAuthorizationHandler;
|
|
|
|
}
|
2022-02-02 12:09:08 +01:00
|
|
|
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public async Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object resource,
|
|
|
|
IEnumerable<IAuthorizationRequirement> requirements)
|
2022-02-02 12:09:08 +01:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
var withuser = user.Identity?.AuthenticationType ==
|
|
|
|
$"Local{GreenfieldConstants.AuthenticationType}WithUser";
|
|
|
|
if (withuser)
|
|
|
|
{
|
|
|
|
var newUser = new ClaimsPrincipal(new ClaimsIdentity(user.Claims,
|
|
|
|
$"{GreenfieldConstants.AuthenticationType}"));
|
|
|
|
var newContext = new AuthorizationHandlerContext(requirements, newUser, resource);
|
|
|
|
await _greenfieldAuthorizationHandler.HandleAsync(newContext);
|
|
|
|
if (newContext.HasSucceeded)
|
|
|
|
{
|
|
|
|
return AuthorizationResult.Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AuthorizationResult.Failed();
|
|
|
|
}
|
|
|
|
|
|
|
|
var succeed = user.Identity.AuthenticationType == $"Local{GreenfieldConstants.AuthenticationType}";
|
|
|
|
|
|
|
|
if (succeed)
|
|
|
|
{
|
|
|
|
return AuthorizationResult.Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
return AuthorizationResult.Failed();
|
2022-02-02 12:09:08 +01:00
|
|
|
}
|
2022-03-11 10:17:50 +01:00
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public Task<AuthorizationResult> AuthorizeAsync(ClaimsPrincipal user, object resource, string policyName)
|
2022-02-02 12:09:08 +01:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
return AuthorizeAsync(user, resource,
|
|
|
|
new List<IAuthorizationRequirement>(new[] {new PolicyRequirement(policyName)}));
|
2022-02-02 12:09:08 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 10:17:50 +01:00
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
protected override HttpRequestMessage CreateHttpRequest(string path,
|
|
|
|
Dictionary<string, object> queryPayload = null, HttpMethod method = null)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException("This method is not supported by the LocalBTCPayServerClient.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<StoreWebhookData> CreateWebhook(string storeId, CreateStoreWebhookRequest create,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<StoreWebhookData>(
|
|
|
|
await _storeWebhooksController.CreateWebhook(storeId, create));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<StoreWebhookData> GetWebhook(string storeId, string webhookId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<StoreWebhookData>(
|
|
|
|
await _storeWebhooksController.ListWebhooks(storeId, webhookId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<StoreWebhookData> UpdateWebhook(string storeId, string webhookId,
|
|
|
|
UpdateStoreWebhookRequest update,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<StoreWebhookData>(
|
|
|
|
await _storeWebhooksController.UpdateWebhook(storeId, webhookId, update));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<bool> DeleteWebhook(string storeId, string webhookId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _storeWebhooksController.DeleteWebhook(storeId, webhookId));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<StoreWebhookData[]> GetWebhooks(string storeId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<StoreWebhookData[]>(
|
|
|
|
await _storeWebhooksController.ListWebhooks(storeId, null));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<WebhookDeliveryData[]> GetWebhookDeliveries(string storeId, string webhookId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<WebhookDeliveryData[]>(
|
|
|
|
await _storeWebhooksController.ListDeliveries(storeId, webhookId, null));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<WebhookDeliveryData> GetWebhookDelivery(string storeId, string webhookId,
|
|
|
|
string deliveryId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<WebhookDeliveryData>(
|
|
|
|
await _storeWebhooksController.ListDeliveries(storeId, webhookId, deliveryId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<string> RedeliverWebhook(string storeId, string webhookId, string deliveryId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<string>(
|
|
|
|
await _storeWebhooksController.RedeliverWebhook(storeId, webhookId, deliveryId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<WebhookEvent> GetWebhookDeliveryRequest(string storeId, string webhookId,
|
|
|
|
string deliveryId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<WebhookEvent>(
|
|
|
|
await _storeWebhooksController.GetDeliveryRequest(storeId, webhookId, deliveryId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PullPaymentData> CreatePullPayment(string storeId, CreatePullPaymentRequest request,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PullPaymentData>(
|
|
|
|
await _greenfieldPullPaymentController.CreatePullPayment(storeId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PullPaymentData> GetPullPayment(string pullPaymentId,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PullPaymentData>(
|
|
|
|
await _greenfieldPullPaymentController.GetPullPayment(pullPaymentId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PullPaymentData[]> GetPullPayments(string storeId, bool includeArchived = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PullPaymentData[]>(
|
|
|
|
await _greenfieldPullPaymentController.GetPullPayments(storeId, includeArchived));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task ArchivePullPayment(string storeId, string pullPaymentId,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _greenfieldPullPaymentController.ArchivePullPayment(storeId, pullPaymentId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PayoutData[]> GetPayouts(string pullPaymentId, bool includeCancelled = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PayoutData[]>(
|
|
|
|
await _greenfieldPullPaymentController.GetPayouts(pullPaymentId, includeCancelled));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PayoutData> CreatePayout(string pullPaymentId, CreatePayoutRequest payoutRequest,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PayoutData>(
|
|
|
|
await _greenfieldPullPaymentController.CreatePayout(pullPaymentId, payoutRequest));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task CancelPayout(string storeId, string payoutId,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _greenfieldPullPaymentController.CancelPayout(storeId, payoutId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PayoutData> ApprovePayout(string storeId, string payoutId,
|
2022-04-26 03:29:20 +02:00
|
|
|
ApprovePayoutRequest request, CancellationToken cancellationToken = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<PayoutData>(
|
|
|
|
await _greenfieldPullPaymentController.ApprovePayout(storeId, payoutId, request, cancellationToken));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningNodeInformationData> GetLightningNodeInfo(string storeId, string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningNodeInformationData>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _storeLightningNodeApiController.GetInfo(cryptoCode, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task ConnectToLightningNode(string storeId, string cryptoCode,
|
2022-04-26 03:29:20 +02:00
|
|
|
ConnectToNodeRequest request, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2022-05-18 15:22:08 +02:00
|
|
|
HandleActionResult(await _storeLightningNodeApiController.ConnectToNode(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string storeId,
|
|
|
|
string cryptoCode, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<LightningChannelData>>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _storeLightningNodeApiController.GetChannels(cryptoCode, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task OpenLightningChannel(string storeId, string cryptoCode,
|
|
|
|
OpenLightningChannelRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
2022-04-26 03:29:20 +02:00
|
|
|
HandleActionResult(await _storeLightningNodeApiController.OpenChannel(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<string> GetLightningDepositAddress(string storeId, string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<string>(
|
2022-05-18 15:22:08 +02:00
|
|
|
await _storeLightningNodeApiController.GetDepositAddress(cryptoCode, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task PayLightningInvoice(string storeId, string cryptoCode,
|
2022-04-26 03:29:20 +02:00
|
|
|
PayLightningInvoiceRequest request, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2022-04-26 03:29:20 +02:00
|
|
|
HandleActionResult(await _storeLightningNodeApiController.PayInvoice(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningInvoiceData> GetLightningInvoice(string storeId, string cryptoCode,
|
|
|
|
string invoiceId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningInvoiceData>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _storeLightningNodeApiController.GetInvoice(cryptoCode, invoiceId, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningInvoiceData> CreateLightningInvoice(string storeId, string cryptoCode,
|
2022-04-26 03:29:20 +02:00
|
|
|
CreateLightningInvoiceRequest request, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningInvoiceData>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _storeLightningNodeApiController.CreateInvoice(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningNodeInformationData> GetLightningNodeInfo(string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningNodeInformationData>(
|
|
|
|
await _lightningNodeApiController.GetInfo(cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task ConnectToLightningNode(string cryptoCode, ConnectToNodeRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
2022-05-18 15:22:08 +02:00
|
|
|
HandleActionResult(await _lightningNodeApiController.ConnectToNode(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<LightningChannelData>> GetLightningNodeChannels(string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<LightningChannelData>>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _lightningNodeApiController.GetChannels(cryptoCode, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task OpenLightningChannel(string cryptoCode, OpenLightningChannelRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
2022-04-26 03:29:20 +02:00
|
|
|
HandleActionResult(await _lightningNodeApiController.OpenChannel(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<string> GetLightningDepositAddress(string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<string>(
|
2022-05-18 15:22:08 +02:00
|
|
|
await _lightningNodeApiController.GetDepositAddress(cryptoCode, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
2022-03-11 10:17:50 +01:00
|
|
|
public override async Task<LightningPaymentData> PayLightningInvoice(string cryptoCode,
|
2022-04-26 03:29:20 +02:00
|
|
|
PayLightningInvoiceRequest request, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2022-02-17 10:01:39 +01:00
|
|
|
return GetFromActionResult<LightningPaymentData>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _lightningNodeApiController.PayInvoice(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningInvoiceData> GetLightningInvoice(string cryptoCode, string invoiceId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningInvoiceData>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _lightningNodeApiController.GetInvoice(cryptoCode, invoiceId, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningInvoiceData> CreateLightningInvoice(string cryptoCode,
|
|
|
|
CreateLightningInvoiceRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningInvoiceData>(
|
2022-04-26 03:29:20 +02:00
|
|
|
await _lightningNodeApiController.CreateInvoice(cryptoCode, request, token));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private T GetFromActionResult<T>(IActionResult result)
|
|
|
|
{
|
|
|
|
HandleActionResult(result);
|
2022-04-26 03:29:20 +02:00
|
|
|
return result switch
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2022-04-26 03:29:20 +02:00
|
|
|
JsonResult jsonResult => (T)jsonResult.Value,
|
2022-06-06 15:57:55 +02:00
|
|
|
OkObjectResult {Value: T res} => res,
|
|
|
|
OkObjectResult {Value: JValue res} => res.Value<T>(),
|
2022-04-26 03:29:20 +02:00
|
|
|
_ => default
|
|
|
|
};
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void HandleActionResult(IActionResult result)
|
|
|
|
{
|
|
|
|
switch (result)
|
|
|
|
{
|
2022-04-26 14:27:35 +02:00
|
|
|
case UnprocessableEntityObjectResult {Value: List<GreenfieldValidationError> validationErrors}:
|
2022-01-14 05:05:23 +01:00
|
|
|
throw new GreenfieldValidationException(validationErrors.ToArray());
|
2022-04-26 14:27:35 +02:00
|
|
|
case BadRequestObjectResult {Value: GreenfieldAPIError error}:
|
2022-01-14 05:05:23 +01:00
|
|
|
throw new GreenfieldAPIException(400, error);
|
2021-07-27 14:11:47 +02:00
|
|
|
case NotFoundResult _:
|
2022-01-14 05:05:23 +01:00
|
|
|
throw new GreenfieldAPIException(404, new GreenfieldAPIError("not-found", ""));
|
2021-07-27 14:11:47 +02:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private T GetFromActionResult<T>(ActionResult result)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<T>((IActionResult)result);
|
|
|
|
}
|
|
|
|
|
|
|
|
private T GetFromActionResult<T>(ActionResult<T> result)
|
|
|
|
{
|
|
|
|
return result.Value ?? GetFromActionResult<T>(result.Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<IEnumerable<OnChainPaymentMethodData>> GetStoreOnChainPaymentMethods(string storeId,
|
2022-04-26 03:29:20 +02:00
|
|
|
bool? enabled, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2022-03-11 10:17:50 +01:00
|
|
|
return Task.FromResult(
|
|
|
|
GetFromActionResult(_chainPaymentMethodsController.GetOnChainPaymentMethods(storeId, enabled)));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
2021-07-29 13:29:34 +02:00
|
|
|
public override Task<OnChainPaymentMethodData> GetStoreOnChainPaymentMethod(string storeId,
|
2021-07-27 14:11:47 +02:00
|
|
|
string cryptoCode, CancellationToken token = default)
|
|
|
|
{
|
2021-07-29 13:29:34 +02:00
|
|
|
return Task.FromResult(GetFromActionResult(
|
|
|
|
_chainPaymentMethodsController.GetOnChainPaymentMethod(storeId, cryptoCode)));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RemoveStoreOnChainPaymentMethod(string storeId, string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _chainPaymentMethodsController.RemoveOnChainPaymentMethod(storeId, cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<OnChainPaymentMethodData> UpdateStoreOnChainPaymentMethod(string storeId,
|
2022-04-26 03:29:20 +02:00
|
|
|
string cryptoCode, UpdateOnChainPaymentMethodRequest paymentMethod, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<OnChainPaymentMethodData>(
|
2022-03-11 10:17:50 +01:00
|
|
|
await _chainPaymentMethodsController.UpdateOnChainPaymentMethod(storeId, cryptoCode,
|
|
|
|
new UpdateOnChainPaymentMethodRequest(
|
|
|
|
enabled: paymentMethod.Enabled,
|
|
|
|
label: paymentMethod.Label,
|
|
|
|
accountKeyPath: paymentMethod.AccountKeyPath,
|
|
|
|
derivationScheme: paymentMethod.DerivationScheme
|
|
|
|
)));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<OnChainPaymentMethodPreviewResultData> PreviewProposedStoreOnChainPaymentMethodAddresses(
|
|
|
|
string storeId, string cryptoCode,
|
2022-03-11 10:17:50 +01:00
|
|
|
UpdateOnChainPaymentMethodRequest paymentMethod, int offset = 0, int amount = 10,
|
|
|
|
CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult<OnChainPaymentMethodPreviewResultData>(
|
|
|
|
_chainPaymentMethodsController.GetProposedOnChainPaymentMethodPreview(storeId, cryptoCode,
|
|
|
|
paymentMethod, offset, amount)));
|
|
|
|
}
|
|
|
|
|
2021-07-29 13:29:34 +02:00
|
|
|
public override Task<OnChainPaymentMethodPreviewResultData> PreviewStoreOnChainPaymentMethodAddresses(
|
2022-04-26 03:29:20 +02:00
|
|
|
string storeId, string cryptoCode, int offset = 0, int amount = 10, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2021-07-29 13:29:34 +02:00
|
|
|
return Task.FromResult(GetFromActionResult<OnChainPaymentMethodPreviewResultData>(
|
2022-03-11 10:17:50 +01:00
|
|
|
_chainPaymentMethodsController.GetOnChainPaymentMethodPreview(storeId, cryptoCode, offset,
|
2021-07-29 13:29:34 +02:00
|
|
|
amount)));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<ApiHealthData> GetHealth(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult<ApiHealthData>(_healthController.GetHealth()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<PaymentRequestData>> GetPaymentRequests(string storeId,
|
|
|
|
bool includeArchived = false, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult(await _paymentRequestController.GetPaymentRequests(storeId, includeArchived));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PaymentRequestData> GetPaymentRequest(string storeId, string paymentRequestId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
2022-03-11 10:17:50 +01:00
|
|
|
return GetFromActionResult<PaymentRequestData>(
|
|
|
|
await _paymentRequestController.GetPaymentRequest(storeId, paymentRequestId));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task ArchivePaymentRequest(string storeId, string paymentRequestId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _paymentRequestController.ArchivePaymentRequest(storeId, paymentRequestId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PaymentRequestData> CreatePaymentRequest(string storeId,
|
|
|
|
CreatePaymentRequestRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PaymentRequestData>(
|
|
|
|
await _paymentRequestController.CreatePaymentRequest(storeId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<PaymentRequestData> UpdatePaymentRequest(string storeId, string paymentRequestId,
|
|
|
|
UpdatePaymentRequestRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PaymentRequestData>(
|
|
|
|
await _paymentRequestController.UpdatePaymentRequest(storeId, paymentRequestId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ApiKeyData> GetCurrentAPIKeyInfo(CancellationToken token = default)
|
|
|
|
{
|
2021-12-23 05:32:08 +01:00
|
|
|
return GetFromActionResult<ApiKeyData>(await _apiKeysController.GetKey());
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ApiKeyData> CreateAPIKey(CreateApiKeyRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<ApiKeyData>(await _apiKeysController.CreateKey(request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RevokeCurrentAPIKeyInfo(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _apiKeysController.RevokeCurrentKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RevokeAPIKey(string apikey, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _apiKeysController.RevokeKey(apikey));
|
|
|
|
}
|
2021-12-31 08:59:02 +01:00
|
|
|
|
|
|
|
public override async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
2021-11-26 03:55:59 +01:00
|
|
|
int? skip = null, int? take = null, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<NotificationData>>(
|
2021-11-26 03:55:59 +01:00
|
|
|
await _notificationsController.GetNotifications(seen, skip, take));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<NotificationData> GetNotification(string notificationId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<NotificationData>(
|
|
|
|
await _notificationsController.GetNotification(notificationId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<NotificationData> UpdateNotification(string notificationId, bool? seen,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<NotificationData>(
|
|
|
|
await _notificationsController.UpdateNotification(notificationId,
|
2022-04-26 14:27:35 +02:00
|
|
|
new UpdateNotification() {Seen = seen}));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RemoveNotification(string notificationId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _notificationsController.DeleteNotification(notificationId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ApplicationUserData> GetCurrentUser(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult(await _usersController.GetCurrentUser());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ApplicationUserData> CreateUser(CreateApplicationUserRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<ApplicationUserData>(await _usersController.CreateUser(request, token));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<OnChainWalletOverviewData> ShowOnChainWalletOverview(string storeId,
|
|
|
|
string cryptoCode, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<OnChainWalletOverviewData>(
|
|
|
|
await _storeOnChainWalletsController.ShowOnChainWalletOverview(storeId, cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<OnChainWalletAddressData> GetOnChainWalletReceiveAddress(string storeId,
|
|
|
|
string cryptoCode, bool forceGenerate = false,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<OnChainWalletAddressData>(
|
|
|
|
await _storeOnChainWalletsController.GetOnChainWalletReceiveAddress(storeId, cryptoCode,
|
|
|
|
forceGenerate));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task UnReserveOnChainWalletReceiveAddress(string storeId, string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(
|
|
|
|
await _storeOnChainWalletsController.UnReserveOnChainWalletReceiveAddress(storeId, cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<OnChainWalletTransactionData>> ShowOnChainWalletTransactions(
|
2022-04-18 04:20:15 +02:00
|
|
|
string storeId, string cryptoCode, TransactionStatus[] statusFilter = null, string labelFilter = null,
|
2021-07-27 14:11:47 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<OnChainWalletTransactionData>>(
|
|
|
|
await _storeOnChainWalletsController.ShowOnChainWalletTransactions(storeId, cryptoCode, statusFilter));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<OnChainWalletTransactionData> GetOnChainWalletTransaction(string storeId,
|
2022-04-26 03:29:20 +02:00
|
|
|
string cryptoCode, string transactionId, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<OnChainWalletTransactionData>(
|
|
|
|
await _storeOnChainWalletsController.GetOnChainWalletTransaction(storeId, cryptoCode, transactionId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<OnChainWalletUTXOData>> GetOnChainWalletUTXOs(string storeId,
|
|
|
|
string cryptoCode, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<OnChainWalletUTXOData>>(
|
|
|
|
await _storeOnChainWalletsController.GetOnChainWalletUTXOs(storeId, cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<OnChainWalletTransactionData> CreateOnChainTransaction(string storeId,
|
2022-04-26 03:29:20 +02:00
|
|
|
string cryptoCode, CreateOnChainTransactionRequest request, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
if (!request.ProceedWithBroadcast)
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(request.ProceedWithBroadcast),
|
|
|
|
"Please use CreateOnChainTransactionButDoNotBroadcast when wanting to only create the transaction");
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetFromActionResult<OnChainWalletTransactionData>(
|
|
|
|
await _storeOnChainWalletsController.CreateOnChainTransaction(storeId, cryptoCode, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<Transaction> CreateOnChainTransactionButDoNotBroadcast(string storeId,
|
|
|
|
string cryptoCode,
|
|
|
|
CreateOnChainTransactionRequest request, Network network, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request.ProceedWithBroadcast)
|
|
|
|
{
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(request.ProceedWithBroadcast),
|
|
|
|
"Please use CreateOnChainTransaction when wanting to also broadcast the transaction");
|
|
|
|
}
|
|
|
|
|
|
|
|
return Transaction.Parse(
|
|
|
|
GetFromActionResult<string>(
|
|
|
|
await _storeOnChainWalletsController.CreateOnChainTransaction(storeId, cryptoCode, request)),
|
|
|
|
network);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<StoreData>> GetStores(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult(await _storesController.GetStores());
|
|
|
|
}
|
|
|
|
|
2021-12-27 05:46:31 +01:00
|
|
|
public override Task<StoreData> GetStore(string storeId, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2021-12-27 05:46:31 +01:00
|
|
|
return Task.FromResult(GetFromActionResult<StoreData>(_storesController.GetStore(storeId)));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RemoveStore(string storeId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _storesController.RemoveStore(storeId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<StoreData> CreateStore(CreateStoreRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<StoreData>(await _storesController.CreateStore(request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<StoreData> UpdateStore(string storeId, UpdateStoreRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<StoreData>(await _storesController.UpdateStore(storeId, request));
|
|
|
|
}
|
2021-12-31 08:59:02 +01:00
|
|
|
|
2021-10-25 08:18:02 +02:00
|
|
|
public override Task<IEnumerable<LNURLPayPaymentMethodData>>
|
|
|
|
GetStoreLNURLPayPaymentMethods(string storeId, bool? enabled,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult(
|
|
|
|
_storeLnurlPayPaymentMethodsController.GetLNURLPayPaymentMethods(storeId, enabled)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<LNURLPayPaymentMethodData> GetStoreLNURLPayPaymentMethod(
|
|
|
|
string storeId, string cryptoCode, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult<LNURLPayPaymentMethodData>(
|
|
|
|
_storeLnurlPayPaymentMethodsController.GetLNURLPayPaymentMethod(storeId, cryptoCode)));
|
|
|
|
}
|
2021-07-27 14:11:47 +02:00
|
|
|
|
2021-10-25 08:18:02 +02:00
|
|
|
public override async Task RemoveStoreLNURLPayPaymentMethod(string storeId, string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(
|
|
|
|
await _storeLnurlPayPaymentMethodsController.RemoveLNURLPayPaymentMethod(storeId,
|
|
|
|
cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LNURLPayPaymentMethodData> UpdateStoreLNURLPayPaymentMethod(
|
|
|
|
string storeId, string cryptoCode,
|
|
|
|
LNURLPayPaymentMethodData paymentMethod, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LNURLPayPaymentMethodData>(await
|
|
|
|
_storeLnurlPayPaymentMethodsController.UpdateLNURLPayPaymentMethod(storeId, cryptoCode,
|
|
|
|
paymentMethod));
|
|
|
|
}
|
2021-12-31 08:59:02 +01:00
|
|
|
|
2021-07-27 14:11:47 +02:00
|
|
|
public override Task<IEnumerable<LightningNetworkPaymentMethodData>>
|
|
|
|
GetStoreLightningNetworkPaymentMethods(string storeId, bool? enabled,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult(
|
|
|
|
_storeLightningNetworkPaymentMethodsController.GetLightningPaymentMethods(storeId, enabled)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<LightningNetworkPaymentMethodData> GetStoreLightningNetworkPaymentMethod(
|
|
|
|
string storeId, string cryptoCode, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult(
|
|
|
|
_storeLightningNetworkPaymentMethodsController.GetLightningNetworkPaymentMethod(storeId, cryptoCode)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RemoveStoreLightningNetworkPaymentMethod(string storeId, string cryptoCode,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(
|
|
|
|
await _storeLightningNetworkPaymentMethodsController.RemoveLightningNetworkPaymentMethod(storeId,
|
|
|
|
cryptoCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<LightningNetworkPaymentMethodData> UpdateStoreLightningNetworkPaymentMethod(
|
|
|
|
string storeId, string cryptoCode,
|
2021-09-25 07:04:34 +02:00
|
|
|
UpdateLightningNetworkPaymentMethodRequest paymentMethod, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningNetworkPaymentMethodData>(await
|
|
|
|
_storeLightningNetworkPaymentMethodsController.UpdateLightningNetworkPaymentMethod(storeId, cryptoCode,
|
2022-03-11 10:17:50 +01:00
|
|
|
new UpdateLightningNetworkPaymentMethodRequest(paymentMethod.ConnectionString,
|
|
|
|
paymentMethod.Enabled)));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<InvoiceData>> GetInvoices(string storeId, string[] orderId = null,
|
|
|
|
InvoiceStatus[] status = null,
|
|
|
|
DateTimeOffset? startDate = null,
|
|
|
|
DateTimeOffset? endDate = null,
|
|
|
|
string textSearch = null,
|
|
|
|
bool includeArchived = false,
|
2021-10-31 11:47:12 +01:00
|
|
|
int? skip = null,
|
|
|
|
int? take = null,
|
|
|
|
CancellationToken token = default
|
2022-03-11 10:17:50 +01:00
|
|
|
)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<InvoiceData>>(
|
|
|
|
await _greenFieldInvoiceController.GetInvoices(storeId, orderId,
|
|
|
|
status?.Select(invoiceStatus => invoiceStatus.ToString())?.ToArray(), startDate,
|
2021-12-31 08:59:02 +01:00
|
|
|
endDate, textSearch, includeArchived, skip, take));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<InvoiceData> GetInvoice(string storeId, string invoiceId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<InvoiceData>(await _greenFieldInvoiceController.GetInvoice(storeId, invoiceId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<InvoicePaymentMethodDataModel[]> GetInvoicePaymentMethods(string storeId,
|
|
|
|
string invoiceId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<InvoicePaymentMethodDataModel[]>(
|
|
|
|
await _greenFieldInvoiceController.GetInvoicePaymentMethods(storeId, invoiceId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task ArchiveInvoice(string storeId, string invoiceId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _greenFieldInvoiceController.ArchiveInvoice(storeId, invoiceId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<InvoiceData> CreateInvoice(string storeId, CreateInvoiceRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<InvoiceData>(await _greenFieldInvoiceController.CreateInvoice(storeId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<InvoiceData> UpdateInvoice(string storeId, string invoiceId,
|
|
|
|
UpdateInvoiceRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<InvoiceData>(
|
|
|
|
await _greenFieldInvoiceController.UpdateInvoice(storeId, invoiceId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<InvoiceData> MarkInvoiceStatus(string storeId, string invoiceId,
|
|
|
|
MarkInvoiceStatusRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<InvoiceData>(
|
|
|
|
await _greenFieldInvoiceController.MarkInvoiceStatus(storeId, invoiceId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<InvoiceData> UnarchiveInvoice(string storeId, string invoiceId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<InvoiceData>(
|
|
|
|
await _greenFieldInvoiceController.UnarchiveInvoice(storeId, invoiceId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<ServerInfoData> GetServerInfo(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult<ServerInfoData>(_greenFieldServerInfoController.ServerInfo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task ActivateInvoicePaymentMethod(string storeId, string invoiceId, string paymentMethod,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(
|
|
|
|
await _greenFieldInvoiceController.ActivateInvoicePaymentMethod(storeId, invoiceId, paymentMethod));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<OnChainWalletFeeRateData> GetOnChainFeeRate(string storeId, string cryptoCode,
|
|
|
|
int? blockTarget = null, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<OnChainWalletFeeRateData>(
|
|
|
|
await _storeOnChainWalletsController.GetOnChainFeeRate(storeId, cryptoCode, blockTarget));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task DeleteCurrentUser(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _usersController.DeleteCurrentUser());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task DeleteUser(string userId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _usersController.DeleteUser(userId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<Language[]> GetAvailableLanguages(CancellationToken token = default)
|
|
|
|
{
|
2022-03-11 10:17:50 +01:00
|
|
|
return Task.FromResult(_homeController.LanguageService.GetLanguages()
|
|
|
|
.Select(language => new Language(language.Code, language.DisplayName)).ToArray());
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<PermissionMetadata[]> GetPermissionMetadata(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(GetFromActionResult<PermissionMetadata[]>(_homeController.Permissions()));
|
|
|
|
}
|
|
|
|
|
2022-03-11 10:17:50 +01:00
|
|
|
public override async Task<Dictionary<string, GenericPaymentMethodData>> GetStorePaymentMethods(string storeId,
|
|
|
|
bool? enabled = null, CancellationToken token = default)
|
2021-07-27 14:11:47 +02:00
|
|
|
{
|
2021-10-01 12:30:00 +02:00
|
|
|
return GetFromActionResult(await _storePaymentMethodsController.GetStorePaymentMethods(storeId, enabled));
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
2021-07-27 16:53:44 +02:00
|
|
|
|
2022-03-11 10:17:50 +01:00
|
|
|
public override async Task<OnChainPaymentMethodDataWithSensitiveData> GenerateOnChainWallet(string storeId,
|
|
|
|
string cryptoCode, GenerateOnChainWalletRequest request,
|
2021-07-27 16:53:44 +02:00
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
2022-03-11 10:17:50 +01:00
|
|
|
return GetFromActionResult<OnChainPaymentMethodDataWithSensitiveData>(
|
|
|
|
await _chainPaymentMethodsController.GenerateOnChainWallet(storeId, cryptoCode,
|
|
|
|
new GenerateWalletRequest()
|
|
|
|
{
|
|
|
|
Passphrase = request.Passphrase,
|
|
|
|
AccountNumber = request.AccountNumber,
|
|
|
|
ExistingMnemonic = request.ExistingMnemonic?.ToString(),
|
|
|
|
WordCount = request.WordCount,
|
|
|
|
WordList = request.WordList,
|
|
|
|
SavePrivateKeys = request.SavePrivateKeys,
|
|
|
|
ScriptPubKeyType = request.ScriptPubKeyType,
|
|
|
|
ImportKeysToRPC = request.ImportKeysToRPC
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task SendEmail(string storeId, SendEmailRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _greenfieldStoreEmailController.SendEmailFromStore(storeId, request));
|
2021-07-27 16:53:44 +02:00
|
|
|
}
|
2022-03-11 10:17:40 +01:00
|
|
|
|
2022-03-11 10:17:50 +01:00
|
|
|
public override Task<EmailSettingsData> GetStoreEmailSettings(string storeId, CancellationToken token = default)
|
2022-03-11 10:17:40 +01:00
|
|
|
{
|
2022-03-11 10:17:50 +01:00
|
|
|
return Task.FromResult(
|
|
|
|
GetFromActionResult<EmailSettingsData>(_greenfieldStoreEmailController.GetStoreEmailSettings()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<EmailSettingsData> UpdateStoreEmailSettings(string storeId,
|
|
|
|
EmailSettingsData request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<EmailSettingsData>(
|
|
|
|
await _greenfieldStoreEmailController.UpdateStoreEmailSettings(storeId,
|
|
|
|
JObject.FromObject(request).ToObject<EmailSettings>()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ApplicationUserData[]> GetUsers(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult(await _usersController.GetUsers());
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<IEnumerable<StoreUserData>> GetStoreUsers(string storeId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return Task.FromResult(
|
|
|
|
GetFromActionResult<IEnumerable<StoreUserData>>(_greenfieldStoreUsersController.GetStoreUsers()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task AddStoreUser(string storeId, StoreUserData request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _greenfieldStoreUsersController.AddStoreUser(storeId, request));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task RemoveStoreUser(string storeId, string userId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
HandleActionResult(await _greenfieldStoreUsersController.RemoveStoreUser(storeId, userId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<ApplicationUserData> GetUserByIdOrEmail(string idOrEmail,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<ApplicationUserData>(await _usersController.GetUser(idOrEmail));
|
2022-03-11 10:17:40 +01:00
|
|
|
}
|
2022-06-06 15:57:55 +02:00
|
|
|
|
2022-04-26 14:27:35 +02:00
|
|
|
public override async Task LockUser(string idOrEmail, bool disabled, CancellationToken token = default)
|
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
HandleActionResult(await _usersController.LockUser(idOrEmail, new LockUserRequest() {Locked = disabled}));
|
2022-04-26 14:27:35 +02:00
|
|
|
}
|
2022-04-24 05:19:34 +02:00
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<OnChainWalletTransactionData> PatchOnChainWalletTransaction(string storeId,
|
|
|
|
string cryptoCode, string transactionId,
|
2022-04-26 14:27:35 +02:00
|
|
|
PatchOnChainTransactionRequest request, CancellationToken token = default)
|
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
return GetFromActionResult<OnChainWalletTransactionData>(
|
|
|
|
await _storeOnChainWalletsController.PatchOnChainWalletTransaction(storeId, cryptoCode, transactionId,
|
|
|
|
request));
|
2022-04-26 14:27:35 +02:00
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<LightningPaymentData> GetLightningPayment(string cryptoCode, string paymentHash,
|
|
|
|
CancellationToken token = default)
|
2022-04-26 14:27:35 +02:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
return GetFromActionResult<LightningPaymentData>(
|
|
|
|
await _lightningNodeApiController.GetPayment(cryptoCode, paymentHash, token));
|
2022-04-26 14:27:35 +02:00
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<LightningPaymentData> GetLightningPayment(string storeId, string cryptoCode,
|
|
|
|
string paymentHash, CancellationToken token = default)
|
2022-04-26 14:27:35 +02:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
return GetFromActionResult<LightningPaymentData>(
|
|
|
|
await _storeLightningNodeApiController.GetPayment(cryptoCode, paymentHash, token));
|
2022-04-26 14:27:35 +02:00
|
|
|
}
|
2022-06-06 15:57:55 +02:00
|
|
|
|
|
|
|
public override async Task<PayoutData> CreatePayout(string storeId,
|
|
|
|
CreatePayoutThroughStoreRequest payoutRequest,
|
2022-04-24 05:19:34 +02:00
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<PayoutData>(
|
|
|
|
await _greenfieldPullPaymentController.CreatePayoutThroughStore(storeId, payoutRequest));
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<IEnumerable<PayoutProcessorData>> GetPayoutProcessors(string storeId,
|
|
|
|
CancellationToken token = default)
|
2022-04-24 05:19:34 +02:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
return GetFromActionResult<IEnumerable<PayoutProcessorData>>(
|
|
|
|
await _greenfieldStorePayoutProcessorsController.GetStorePayoutProcessors(storeId));
|
2022-04-24 05:19:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<IEnumerable<PayoutProcessorData>> GetPayoutProcessors(CancellationToken token = default)
|
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
return Task.FromResult(
|
|
|
|
GetFromActionResult<IEnumerable<PayoutProcessorData>>(_greenfieldPayoutProcessorsController
|
|
|
|
.GetPayoutProcessors()));
|
2022-04-24 05:19:34 +02:00
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task RemovePayoutProcessor(string storeId, string processor, string paymentMethod,
|
|
|
|
CancellationToken token = default)
|
2022-04-24 05:19:34 +02:00
|
|
|
{
|
2022-06-06 15:57:55 +02:00
|
|
|
HandleActionResult(
|
|
|
|
await _greenfieldStorePayoutProcessorsController.RemoveStorePayoutProcessor(storeId, processor,
|
|
|
|
paymentMethod));
|
2022-04-24 05:19:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IEnumerable<OnChainAutomatedPayoutSettings>>
|
|
|
|
GetStoreOnChainAutomatedPayoutProcessors(string storeId, string paymentMethod = null,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<OnChainAutomatedPayoutSettings>>(
|
|
|
|
await _greenfieldStoreAutomatedOnChainPayoutProcessorsController
|
|
|
|
.GetStoreOnChainAutomatedPayoutProcessors(storeId, paymentMethod));
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<IEnumerable<LightningAutomatedPayoutSettings>>
|
|
|
|
GetStoreLightningAutomatedPayoutProcessors(string storeId, string paymentMethod = null,
|
|
|
|
CancellationToken token = default)
|
2022-04-24 05:19:34 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<IEnumerable<LightningAutomatedPayoutSettings>>(
|
|
|
|
await _greenfieldStoreAutomatedLightningPayoutProcessorsController
|
|
|
|
.GetStoreLightningAutomatedPayoutProcessors(storeId, paymentMethod));
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<OnChainAutomatedPayoutSettings> UpdateStoreOnChainAutomatedPayoutProcessors(
|
|
|
|
string storeId, string paymentMethod,
|
2022-04-24 05:19:34 +02:00
|
|
|
OnChainAutomatedPayoutSettings request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<OnChainAutomatedPayoutSettings>(
|
|
|
|
await _greenfieldStoreAutomatedOnChainPayoutProcessorsController
|
|
|
|
.UpdateStoreOnchainAutomatedPayoutProcessor(storeId, paymentMethod, request));
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<LightningAutomatedPayoutSettings> UpdateStoreLightningAutomatedPayoutProcessors(
|
|
|
|
string storeId, string paymentMethod,
|
2022-04-24 05:19:34 +02:00
|
|
|
LightningAutomatedPayoutSettings request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return GetFromActionResult<LightningAutomatedPayoutSettings>(
|
|
|
|
await _greenfieldStoreAutomatedLightningPayoutProcessorsController
|
|
|
|
.UpdateStoreLightningAutomatedPayoutProcessor(storeId, paymentMethod, request));
|
|
|
|
}
|
|
|
|
|
2022-06-06 15:57:55 +02:00
|
|
|
public override async Task<PayoutData[]> GetStorePayouts(string storeId, bool includeCancelled = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
2022-04-24 05:19:34 +02:00
|
|
|
{
|
|
|
|
return GetFromActionResult<PayoutData[]>(
|
|
|
|
await _greenfieldPullPaymentController
|
2022-06-06 15:57:55 +02:00
|
|
|
.GetStorePayouts(storeId, includeCancelled));
|
2022-04-24 05:19:34 +02:00
|
|
|
}
|
2021-07-27 14:11:47 +02:00
|
|
|
}
|
|
|
|
}
|