2018-02-20 04:45:04 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-04-07 09:27:46 +02:00
|
|
|
|
using BTCPayServer.Data;
|
2020-03-29 17:28:22 +02:00
|
|
|
|
using BTCPayServer.Logging;
|
2019-05-29 16:33:31 +02:00
|
|
|
|
using BTCPayServer.Models.InvoicingModels;
|
|
|
|
|
using BTCPayServer.Rating;
|
2018-02-20 04:45:04 +01:00
|
|
|
|
using BTCPayServer.Services.Invoices;
|
2019-05-29 16:33:31 +02:00
|
|
|
|
using BTCPayServer.Services.Rates;
|
|
|
|
|
using NBitcoin;
|
|
|
|
|
using InvoiceResponse = BTCPayServer.Models.InvoiceResponse;
|
2018-02-20 04:45:04 +01:00
|
|
|
|
|
|
|
|
|
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>
|
2019-05-29 11:43:50 +02:00
|
|
|
|
/// <param name="preparePaymentObject"></param>
|
2018-02-20 04:45:04 +01:00
|
|
|
|
/// <returns></returns>
|
2020-03-29 17:28:22 +02:00
|
|
|
|
Task<IPaymentMethodDetails> CreatePaymentMethodDetails(InvoiceLogs logs, ISupportedPaymentMethod supportedPaymentMethod,
|
2019-05-29 16:33:31 +02:00
|
|
|
|
PaymentMethod paymentMethod, StoreData store, BTCPayNetworkBase network, object preparePaymentObject);
|
2018-08-21 06:54:52 +02:00
|
|
|
|
|
|
|
|
|
/// <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>
|
2019-05-29 11:43:50 +02:00
|
|
|
|
object PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store, BTCPayNetworkBase network);
|
2019-05-29 16:33:31 +02:00
|
|
|
|
|
2019-09-11 07:49:06 +02:00
|
|
|
|
void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob);
|
2019-05-29 16:33:31 +02:00
|
|
|
|
string GetCryptoImage(PaymentMethodId paymentMethodId);
|
|
|
|
|
string GetPaymentMethodName(PaymentMethodId paymentMethodId);
|
|
|
|
|
|
|
|
|
|
Task<string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
|
|
|
|
|
Dictionary<CurrencyPair, Task<RateResult>> rate,
|
|
|
|
|
Money amount, PaymentMethodId paymentMethodId);
|
|
|
|
|
|
|
|
|
|
IEnumerable<PaymentMethodId> GetSupportedPaymentMethods();
|
2019-08-25 15:50:11 +02:00
|
|
|
|
CheckoutUIPaymentMethodSettings GetCheckoutUISettings();
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-29 16:33:31 +02:00
|
|
|
|
public interface IPaymentMethodHandler<TSupportedPaymentMethod, TBTCPayNetwork> : IPaymentMethodHandler
|
|
|
|
|
where TSupportedPaymentMethod : ISupportedPaymentMethod
|
|
|
|
|
where TBTCPayNetwork : BTCPayNetworkBase
|
2018-02-20 04:45:04 +01:00
|
|
|
|
{
|
2020-03-29 17:28:22 +02:00
|
|
|
|
Task<IPaymentMethodDetails> CreatePaymentMethodDetails(InvoiceLogs logs, TSupportedPaymentMethod supportedPaymentMethod,
|
2019-05-29 16:33:31 +02:00
|
|
|
|
PaymentMethod paymentMethod, StoreData store, TBTCPayNetwork network, object preparePaymentObject);
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-30 09:02:52 +02:00
|
|
|
|
public abstract class PaymentMethodHandlerBase<TSupportedPaymentMethod, TBTCPayNetwork> : IPaymentMethodHandler<
|
2019-05-29 16:33:31 +02:00
|
|
|
|
TSupportedPaymentMethod, TBTCPayNetwork>
|
|
|
|
|
where TSupportedPaymentMethod : ISupportedPaymentMethod
|
|
|
|
|
where TBTCPayNetwork : BTCPayNetworkBase
|
2018-02-20 04:45:04 +01:00
|
|
|
|
{
|
2019-06-04 01:59:01 +02:00
|
|
|
|
public abstract PaymentType PaymentType { get; }
|
2019-05-29 16:33:31 +02:00
|
|
|
|
|
|
|
|
|
public abstract Task<IPaymentMethodDetails> CreatePaymentMethodDetails(
|
2020-03-29 17:28:22 +02:00
|
|
|
|
InvoiceLogs logs,
|
2019-05-29 16:33:31 +02:00
|
|
|
|
TSupportedPaymentMethod supportedPaymentMethod,
|
|
|
|
|
PaymentMethod paymentMethod, StoreData store, TBTCPayNetwork network, object preparePaymentObject);
|
|
|
|
|
|
2019-09-11 07:49:06 +02:00
|
|
|
|
public abstract void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
|
|
|
|
|
StoreBlob storeBlob);
|
2019-05-29 16:33:31 +02:00
|
|
|
|
public abstract string GetCryptoImage(PaymentMethodId paymentMethodId);
|
|
|
|
|
public abstract string GetPaymentMethodName(PaymentMethodId paymentMethodId);
|
|
|
|
|
|
|
|
|
|
public abstract Task<string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
|
|
|
|
|
Dictionary<CurrencyPair, Task<RateResult>> rate, Money amount, PaymentMethodId paymentMethodId);
|
|
|
|
|
|
|
|
|
|
public abstract IEnumerable<PaymentMethodId> GetSupportedPaymentMethods();
|
2019-08-27 04:31:15 +02:00
|
|
|
|
public virtual CheckoutUIPaymentMethodSettings GetCheckoutUISettings()
|
|
|
|
|
{
|
|
|
|
|
return new CheckoutUIPaymentMethodSettings()
|
|
|
|
|
{
|
|
|
|
|
ExtensionPartial = "Bitcoin_Lightning_LikeMethodCheckout",
|
|
|
|
|
CheckoutBodyVueComponentName = "BitcoinLightningLikeMethodCheckout",
|
|
|
|
|
CheckoutHeaderVueComponentName = "BitcoinLightningLikeMethodCheckoutHeader",
|
|
|
|
|
NoScriptPartialName = "Bitcoin_Lightning_LikeMethodCheckoutNoScript"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PaymentMethod GetPaymentMethodInInvoice(InvoiceEntity invoice, PaymentMethodId paymentMethodId)
|
|
|
|
|
{
|
|
|
|
|
return invoice.GetPaymentMethod(paymentMethodId);
|
|
|
|
|
}
|
2019-05-29 16:33:31 +02:00
|
|
|
|
|
|
|
|
|
public virtual object PreparePayment(TSupportedPaymentMethod supportedPaymentMethod, StoreData store,
|
|
|
|
|
BTCPayNetworkBase network)
|
2018-08-21 06:54:52 +02:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 17:28:22 +02:00
|
|
|
|
public Task<IPaymentMethodDetails> CreatePaymentMethodDetails(InvoiceLogs logs, ISupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod,
|
2019-05-29 16:33:31 +02:00
|
|
|
|
StoreData store, BTCPayNetworkBase network, object preparePaymentObject)
|
2018-08-21 06:54:52 +02:00
|
|
|
|
{
|
2019-05-29 16:33:31 +02:00
|
|
|
|
if (supportedPaymentMethod is TSupportedPaymentMethod method && network is TBTCPayNetwork correctNetwork)
|
2018-08-21 06:54:52 +02:00
|
|
|
|
{
|
2020-03-29 17:28:22 +02:00
|
|
|
|
return CreatePaymentMethodDetails(logs, method, paymentMethod, store, correctNetwork, preparePaymentObject);
|
2018-08-21 06:54:52 +02:00
|
|
|
|
}
|
2019-05-29 16:33:31 +02:00
|
|
|
|
|
2018-08-21 06:54:52 +02:00
|
|
|
|
throw new NotSupportedException("Invalid supportedPaymentMethod");
|
|
|
|
|
}
|
2018-02-20 04:45:04 +01:00
|
|
|
|
|
2019-05-29 16:33:31 +02:00
|
|
|
|
object IPaymentMethodHandler.PreparePayment(ISupportedPaymentMethod supportedPaymentMethod, StoreData store,
|
|
|
|
|
BTCPayNetworkBase network)
|
2019-05-24 08:38:47 +02:00
|
|
|
|
{
|
2019-05-29 16:33:31 +02:00
|
|
|
|
if (supportedPaymentMethod is TSupportedPaymentMethod method)
|
|
|
|
|
{
|
|
|
|
|
return PreparePayment(method, store, network);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException("Invalid supportedPaymentMethod");
|
2019-05-24 08:38:47 +02:00
|
|
|
|
}
|
2018-02-20 04:45:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|