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