mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-04 01:53:52 +01:00
Allow plugins to do something before and after automatic payouts (#4224)
This commit is contained in:
parent
eff6be9643
commit
e02abb509f
5 changed files with 56 additions and 5 deletions
19
BTCPayServer/PayoutProcessors/AfterPayoutFilterData.cs
Normal file
19
BTCPayServer/PayoutProcessors/AfterPayoutFilterData.cs
Normal file
|
@ -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<PayoutData> _payoutDatas;
|
||||
|
||||
public AfterPayoutFilterData(StoreData store, ISupportedPaymentMethod paymentMethod, List<PayoutData> payoutDatas)
|
||||
{
|
||||
_store = store;
|
||||
_paymentMethod = paymentMethod;
|
||||
_payoutDatas = payoutDatas;
|
||||
}
|
||||
}
|
|
@ -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<T> : 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<T> : 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<T> : BaseAsyncService where T
|
|||
_applicationDbContextFactory = applicationDbContextFactory;
|
||||
_pullPaymentHostedService = pullPaymentHostedService;
|
||||
_btcPayNetworkProvider = btcPayNetworkProvider;
|
||||
_pluginHookService = pluginHookService;
|
||||
this.NoLogsOnExit = true;
|
||||
}
|
||||
|
||||
|
@ -58,6 +62,10 @@ public abstract class BaseAutomatedPayoutProcessor<T> : 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<T> : 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);
|
||||
|
|
16
BTCPayServer/PayoutProcessors/BeforePayoutFilterData.cs
Normal file
16
BTCPayServer/PayoutProcessors/BeforePayoutFilterData.cs
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<Au
|
|||
UserService userService,
|
||||
ILoggerFactory logger, IOptions<LightningNetworkOptions> 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue