using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BTCPayServer.Services.Invoices;
namespace BTCPayServer.Payments
{
///
/// This class customize invoice creation by the creation of payment details for the PaymentMethod during invoice creation
///
public interface IPaymentMethodHandler
{
///
/// Returns true if the dependencies for a specific payment method are satisfied.
///
///
///
/// true if this payment method is available
Task IsAvailable(ISupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network);
///
/// Create needed to track payments of this invoice
///
///
///
///
///
Task CreatePaymentMethodDetails(ISupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, BTCPayNetwork network);
}
public interface IPaymentMethodHandler : IPaymentMethodHandler where T : ISupportedPaymentMethod
{
Task IsAvailable(T supportedPaymentMethod, BTCPayNetwork network);
Task CreatePaymentMethodDetails(T supportedPaymentMethod, PaymentMethod paymentMethod, BTCPayNetwork network);
}
public abstract class PaymentMethodHandlerBase : IPaymentMethodHandler where T : ISupportedPaymentMethod
{
public abstract Task CreatePaymentMethodDetails(T supportedPaymentMethod, PaymentMethod paymentMethod, BTCPayNetwork network);
Task IPaymentMethodHandler.CreatePaymentMethodDetails(ISupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, BTCPayNetwork network)
{
if (supportedPaymentMethod is T method)
{
return CreatePaymentMethodDetails(method, paymentMethod, network);
}
throw new NotSupportedException("Invalid supportedPaymentMethod");
}
public abstract Task IsAvailable(T supportedPaymentMethod, BTCPayNetwork network);
Task IPaymentMethodHandler.IsAvailable(ISupportedPaymentMethod supportedPaymentMethod, BTCPayNetwork network)
{
if(supportedPaymentMethod is T method)
{
return IsAvailable(method, network);
}
return Task.FromResult(false);
}
}
}