2022-05-18 07:59:56 +02:00
|
|
|
using System;
|
2022-04-24 05:19:34 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
2023-02-21 15:06:34 +09:00
|
|
|
using BTCPayServer.Data;
|
2022-04-24 05:19:34 +02:00
|
|
|
using BTCPayServer.Payments;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
namespace BTCPayServer.PayoutProcessors.Lightning;
|
|
|
|
|
|
|
|
public class LightningAutomatedPayoutSenderFactory : IPayoutProcessorFactory
|
|
|
|
{
|
|
|
|
private readonly BTCPayNetworkProvider _btcPayNetworkProvider;
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly LinkGenerator _linkGenerator;
|
|
|
|
|
2023-07-20 15:05:14 +02:00
|
|
|
|
2022-04-24 05:19:34 +02:00
|
|
|
public LightningAutomatedPayoutSenderFactory(BTCPayNetworkProvider btcPayNetworkProvider, IServiceProvider serviceProvider, LinkGenerator linkGenerator)
|
|
|
|
{
|
|
|
|
_btcPayNetworkProvider = btcPayNetworkProvider;
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_linkGenerator = linkGenerator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string FriendlyName { get; } = "Automated Lightning Sender";
|
|
|
|
|
|
|
|
public string ConfigureLink(string storeId, PaymentMethodId paymentMethodId, HttpRequest request)
|
|
|
|
{
|
2023-01-06 14:18:07 +01:00
|
|
|
return _linkGenerator.GetUriByAction("Configure",
|
|
|
|
"UILightningAutomatedPayoutProcessors", new
|
2022-04-24 05:19:34 +02:00
|
|
|
{
|
|
|
|
storeId,
|
|
|
|
cryptoCode = paymentMethodId.CryptoCode
|
|
|
|
}, request.Scheme, request.Host, request.PathBase);
|
|
|
|
}
|
|
|
|
public string Processor => ProcessorName;
|
|
|
|
public static string ProcessorName => nameof(LightningAutomatedPayoutSenderFactory);
|
|
|
|
public IEnumerable<PaymentMethodId> GetSupportedPaymentMethods()
|
|
|
|
{
|
2023-01-06 14:18:07 +01:00
|
|
|
return _btcPayNetworkProvider.GetAll().OfType<BTCPayNetwork>()
|
2022-04-24 05:19:34 +02:00
|
|
|
.Where(network => network.SupportLightning)
|
|
|
|
.Select(network =>
|
|
|
|
new PaymentMethodId(network.CryptoCode, LightningPaymentType.Instance));
|
|
|
|
}
|
|
|
|
|
2022-04-26 14:27:35 +02:00
|
|
|
public Task<IHostedService> ConstructProcessor(PayoutProcessorData settings)
|
2022-04-24 05:19:34 +02:00
|
|
|
{
|
|
|
|
if (settings.Processor != Processor)
|
|
|
|
{
|
|
|
|
throw new NotSupportedException("This processor cannot handle the provided requirements");
|
|
|
|
}
|
|
|
|
|
2022-04-26 14:27:35 +02:00
|
|
|
return Task.FromResult<IHostedService>(ActivatorUtilities.CreateInstance<LightningAutomatedPayoutProcessor>(_serviceProvider, settings));
|
2022-04-24 05:19:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|