diff --git a/BTCPayServer/PayoutProcessors/AfterPayoutFilterData.cs b/BTCPayServer/PayoutProcessors/AfterPayoutFilterData.cs new file mode 100644 index 000000000..e014590d5 --- /dev/null +++ b/BTCPayServer/PayoutProcessors/AfterPayoutFilterData.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using BTCPayServer.Data; +using BTCPayServer.Payments; + +namespace BTCPayServer.PayoutProcessors; + +public class AfterPayoutFilterData +{ + private readonly StoreData _store; + private readonly ISupportedPaymentMethod _paymentMethod; + private readonly List _payoutDatas; + + public AfterPayoutFilterData(StoreData store, ISupportedPaymentMethod paymentMethod, List payoutDatas) + { + _store = store; + _paymentMethod = paymentMethod; + _payoutDatas = payoutDatas; + } +} diff --git a/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs b/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs index e5410dc75..26194fd5c 100644 --- a/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs +++ b/BTCPayServer/PayoutProcessors/BaseAutomatedPayoutProcessor.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Client.Models; using BTCPayServer.Data; using BTCPayServer.HostedServices; @@ -23,6 +24,7 @@ public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T private readonly PullPaymentHostedService _pullPaymentHostedService; protected readonly BTCPayNetworkProvider _btcPayNetworkProvider; protected readonly PaymentMethodId PaymentMethodId; + private readonly IPluginHookService _pluginHookService; protected BaseAutomatedPayoutProcessor( ILoggerFactory logger, @@ -30,7 +32,8 @@ public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T PayoutProcessorData payoutProcesserSettings, ApplicationDbContextFactory applicationDbContextFactory, PullPaymentHostedService pullPaymentHostedService, - BTCPayNetworkProvider btcPayNetworkProvider) : base(logger.CreateLogger($"{payoutProcesserSettings.Processor}:{payoutProcesserSettings.StoreId}:{payoutProcesserSettings.PaymentMethod}")) + BTCPayNetworkProvider btcPayNetworkProvider, + IPluginHookService pluginHookService) : base(logger.CreateLogger($"{payoutProcesserSettings.Processor}:{payoutProcesserSettings.StoreId}:{payoutProcesserSettings.PaymentMethod}")) { _storeRepository = storeRepository; _PayoutProcesserSettings = payoutProcesserSettings; @@ -38,6 +41,7 @@ public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T _applicationDbContextFactory = applicationDbContextFactory; _pullPaymentHostedService = pullPaymentHostedService; _btcPayNetworkProvider = btcPayNetworkProvider; + _pluginHookService = pluginHookService; this.NoLogsOnExit = true; } @@ -58,6 +62,10 @@ public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T var blob = GetBlob(_PayoutProcesserSettings); if (paymentMethod is not null) { + + // Allow plugins to do something before the automatic payouts are executed + await _pluginHookService.ApplyFilter("before-automated-payout-processing", + new BeforePayoutFilterData(store, paymentMethod)); await using var context = _applicationDbContextFactory.CreateContext(); var payouts = await PullPaymentHostedService.GetPayouts( @@ -72,6 +80,10 @@ public abstract class BaseAutomatedPayoutProcessor : BaseAsyncService where T Logs.PayServer.LogInformation($"{payouts.Count} found to process. Starting (and after will sleep for {blob.Interval})"); await Process(paymentMethod, payouts); await context.SaveChangesAsync(); + + // Allow plugins do to something after automatic payout processing + await _pluginHookService.ApplyFilter("after-automated-payout-processing", + new AfterPayoutFilterData(store, paymentMethod, payouts)); } } await Task.Delay(blob.Interval, CancellationToken); diff --git a/BTCPayServer/PayoutProcessors/BeforePayoutFilterData.cs b/BTCPayServer/PayoutProcessors/BeforePayoutFilterData.cs new file mode 100644 index 000000000..7b6df23e7 --- /dev/null +++ b/BTCPayServer/PayoutProcessors/BeforePayoutFilterData.cs @@ -0,0 +1,16 @@ +using BTCPayServer.Data; +using BTCPayServer.Payments; + +namespace BTCPayServer.PayoutProcessors; + +public class BeforePayoutFilterData +{ + private readonly StoreData _store; + private readonly ISupportedPaymentMethod _paymentMethod; + + public BeforePayoutFilterData(StoreData store, ISupportedPaymentMethod paymentMethod) + { + _store = store; + _paymentMethod = paymentMethod; + } +} diff --git a/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs b/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs index fe9c00c6f..687068219 100644 --- a/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs +++ b/BTCPayServer/PayoutProcessors/Lightning/LightningAutomatedPayoutProcessor.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Client.Models; using BTCPayServer.Configuration; using BTCPayServer.Data; @@ -37,9 +38,10 @@ public class LightningAutomatedPayoutProcessor : BaseAutomatedPayoutProcessor options, StoreRepository storeRepository, PayoutProcessorData payoutProcesserSettings, - ApplicationDbContextFactory applicationDbContextFactory, PullPaymentHostedService pullPaymentHostedService, BTCPayNetworkProvider btcPayNetworkProvider) : + ApplicationDbContextFactory applicationDbContextFactory, PullPaymentHostedService pullPaymentHostedService, BTCPayNetworkProvider btcPayNetworkProvider, + IPluginHookService pluginHookService) : base(logger, storeRepository, payoutProcesserSettings, applicationDbContextFactory, pullPaymentHostedService, - btcPayNetworkProvider) + btcPayNetworkProvider, pluginHookService) { _btcPayNetworkJsonSerializerSettings = btcPayNetworkJsonSerializerSettings; _lightningClientFactoryService = lightningClientFactoryService; diff --git a/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs b/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs index 88577b020..745b9c2fe 100644 --- a/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs +++ b/BTCPayServer/PayoutProcessors/OnChain/OnChainAutomatedPayoutProcessor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Client.Models; using BTCPayServer.Data; using BTCPayServer.Events; @@ -41,9 +42,10 @@ namespace BTCPayServer.PayoutProcessors.OnChain StoreRepository storeRepository, PayoutProcessorData payoutProcesserSettings, PullPaymentHostedService pullPaymentHostedService, - BTCPayNetworkProvider btcPayNetworkProvider) : + BTCPayNetworkProvider btcPayNetworkProvider, + IPluginHookService pluginHookService) : base(logger, storeRepository, payoutProcesserSettings, applicationDbContextFactory, pullPaymentHostedService, - btcPayNetworkProvider) + btcPayNetworkProvider, pluginHookService) { _explorerClientProvider = explorerClientProvider; _btcPayWalletProvider = btcPayWalletProvider;