integarte into payoit processor

This commit is contained in:
Kukks
2023-01-30 12:49:38 +01:00
parent 5a2985fcdb
commit 2c84539bc3
3 changed files with 79 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="BTCPayServer: Altcoins-HTTPS" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<configuration default="false" name="BTCPayServer: Bitcoin-HTTPS" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/submodules/btcpayserver/BTCPayServer/BTCPayServer.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net6.0" />
<option name="LAUNCH_PROFILE_NAME" value="Altcoins-HTTPS" />
<option name="LAUNCH_PROFILE_NAME" value="Bitcoin-HTTPS" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />

View File

@@ -11,9 +11,13 @@ using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Abstractions.Models;
using BTCPayServer.Abstractions.Services;
using BTCPayServer.Common;
using BTCPayServer.Data.Data;
using BTCPayServer.Payments;
using BTCPayServer.Payments.PayJoin;
using BTCPayServer.PayoutProcessors;
using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Formatters;
@@ -21,6 +25,7 @@ using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Options;
@@ -90,6 +95,7 @@ public class WabisabiPlugin : BaseBTCPayServerPlugin
applicationBuilder.AddSingleton<IUIExtension>(new UIExtension("Wabisabi/WabisabiDashboard",
"dashboard"));
applicationBuilder.AddSingleton<IPayoutProcessorFactory, WabisabiPayoutProcessor>();
Logger.SetMinimumLevel(LogLevel.Info);
Logger.SetModes(LogMode.DotNetLoggers);
@@ -97,6 +103,50 @@ public class WabisabiPlugin : BaseBTCPayServerPlugin
base.Execute(applicationBuilder);
}
public class WabisabiPayoutProcessor: IPayoutProcessorFactory
{
private readonly LinkGenerator _linkGenerator;
public WabisabiPayoutProcessor(LinkGenerator linkGenerator)
{
_linkGenerator = linkGenerator;
}
public string Processor { get; } = "Wabisabi";
public string FriendlyName { get; } = "Coinjoin";
public string ConfigureLink(string storeId, PaymentMethodId paymentMethodId, HttpRequest request)
{
return _linkGenerator.GetUriByAction(
nameof(WabisabiStoreController.UpdateWabisabiStoreSettings),
"WabisabiStore",
new { storeId},
request.Scheme,
request.Host,
request.PathBase);
}
public IEnumerable<PaymentMethodId> GetSupportedPaymentMethods()
{
return new[] {new PaymentMethodId("BTC", PaymentTypes.BTCLike)};
}
public Task<IHostedService> ConstructProcessor(PayoutProcessorData settings)
{
return Task.FromResult<IHostedService>(new ShellSerice());
}
public class ShellSerice:IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}
public override void Execute(IApplicationBuilder applicationBuilder,
IServiceProvider applicationBuilderApplicationServices)

View File

@@ -4,6 +4,8 @@ using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
using BTCPayServer.Client;
using BTCPayServer.Data.Data;
using BTCPayServer.PayoutProcessors;
using BTCPayServer.Services;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json.Linq;
@@ -17,17 +19,22 @@ namespace BTCPayServer.Plugins.Wabisabi
private readonly WabisabiCoordinatorClientInstanceManager _coordinatorClientInstanceManager;
private readonly WalletProvider _walletProvider;
private readonly WalletRepository _walletRepository;
private readonly PayoutProcessorService _payoutProcessorService;
private readonly EventAggregator _eventAggregator;
private string[] _ids => _coordinatorClientInstanceManager.HostedServices.Keys.ToArray();
public WabisabiService( IStoreRepository storeRepository,
WabisabiCoordinatorClientInstanceManager coordinatorClientInstanceManager,
WalletProvider walletProvider,
WalletRepository walletRepository)
WalletRepository walletRepository,PayoutProcessorService payoutProcessorService, EventAggregator eventAggregator)
{
_storeRepository = storeRepository;
_coordinatorClientInstanceManager = coordinatorClientInstanceManager;
_walletProvider = walletProvider;
_walletRepository = walletRepository;
_payoutProcessorService = payoutProcessorService;
_eventAggregator = eventAggregator;
_eventAggregator.Subscribe()
}
public async Task<WabisabiStoreSettings> GetWabisabiForStore(string storeId)
@@ -52,7 +59,8 @@ namespace BTCPayServer.Plugins.Wabisabi
public async Task SetWabisabiForStore(string storeId, WabisabiStoreSettings wabisabiSettings)
{
var paybatching = wabisabiSettings.PlebMode || wabisabiSettings.BatchPayments &&
wabisabiSettings.Settings.Any(settings => settings.Enabled);
foreach (var setting in wabisabiSettings.Settings)
{
if (setting.Enabled) continue;
@@ -71,7 +79,23 @@ namespace BTCPayServer.Plugins.Wabisabi
}
await _walletProvider.SettingsUpdated(storeId, wabisabiSettings);
var existingProcessor = (await _payoutProcessorService.GetProcessors(new PayoutProcessorService.PayoutProcessorQuery()
{
Stores = new[] {storeId},
Processors = new[] {"Wabisabi"},
})).FirstOrDefault();
_eventAggregator.Publish(new PayoutProcessorUpdated()
{
Id = existingProcessor?.Id,
Data = paybatching? new PayoutProcessorData()
{
Id = existingProcessor?.Id,
Processor = "Wabisabi",
StoreId = storeId,
PaymentMethod = "BTC",
}: null
});
}