2018-02-20 04:45:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-04-07 09:27:46 +02:00
|
|
|
|
using BTCPayServer.Data;
|
2018-02-20 04:45:04 +01:00
|
|
|
|
using BTCPayServer.Services.Invoices;
|
|
|
|
|
|
|
|
|
|
namespace BTCPayServer.Payments
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class customize invoice creation by the creation of payment details for the PaymentMethod during invoice creation
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IPaymentMethodHandler
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create needed to track payments of this invoice
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="supportedPaymentMethod"></param>
|
|
|
|
|
/// <param name="paymentMethod"></param>
|
2018-04-07 09:27:46 +02:00
|
|
|
|
/// <param name="store"></param>
|
2018-02-20 04:45:04 +01:00
|
|
|
|
/// <param name="network"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-08-21 06:54:52 +02:00
|
|
|
|
Task<IPaymentMethodDetails> CreatePaymentMethodDetails(ISupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store, BTCPayNetwork network, object preparePaymentObject);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This method called before the rate have been fetched
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="supportedPaymentMethod"></param>
|
|
|
|
|
/// <param name="store"></param>
|
|
|
|
|
/// <param name="network"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
object PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetwork network);
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface IPaymentMethodHandler<T> : IPaymentMethodHandler where T : ISupportedPaymentMethod
|
|
|
|
|
{
|
2018-08-21 06:54:52 +02:00
|
|
|
|
Task<IPaymentMethodDetails> CreatePaymentMethodDetails(T supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store, BTCPayNetwork network, object preparePaymentObject);
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class PaymentMethodHandlerBase<T> : IPaymentMethodHandler<T> where T : ISupportedPaymentMethod
|
|
|
|
|
{
|
2018-08-21 06:54:52 +02:00
|
|
|
|
|
|
|
|
|
public abstract Task<IPaymentMethodDetails> CreatePaymentMethodDetails(T supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store, BTCPayNetwork network, object preparePaymentObject);
|
|
|
|
|
public virtual object PreparePayment(T supportedPaymentMethod, StoreData store, BTCPayNetwork network)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object IPaymentMethodHandler.PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetwork network)
|
|
|
|
|
{
|
|
|
|
|
if (supportedPaymentMethod is T method)
|
|
|
|
|
{
|
|
|
|
|
return PreparePayment(method, store, network);
|
|
|
|
|
}
|
|
|
|
|
throw new NotSupportedException("Invalid supportedPaymentMethod");
|
|
|
|
|
}
|
2018-02-20 04:45:04 +01:00
|
|
|
|
|
2018-08-21 06:54:52 +02:00
|
|
|
|
Task<IPaymentMethodDetails> IPaymentMethodHandler.CreatePaymentMethodDetails(ISupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, StoreData store, BTCPayNetwork network, object preparePaymentObject)
|
2018-02-20 04:45:04 +01:00
|
|
|
|
{
|
|
|
|
|
if (supportedPaymentMethod is T method)
|
|
|
|
|
{
|
2018-08-21 06:54:52 +02:00
|
|
|
|
return CreatePaymentMethodDetails(method, paymentMethod, store, network, preparePaymentObject);
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
throw new NotSupportedException("Invalid supportedPaymentMethod");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|