mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
* LNURL Payment Method Support * Merge recent Lightning controller related changes * Fix build * Create separate payment settings section for stores * Improve LNURL configuration * Prevent duplicate array entries when merging Swagger JSON * Fix CanSetPaymentMethodLimitsLightning * Fix CanUsePayjoinViaUI * Adapt test for new cancel bolt invoice feature * rebase fixes * Fixes after rebase * Test fixes * Do not turn LNURL on by default, Off-Chain payment criteria should affects both BOLT11 and LNURL, Payment criteria of unset payment method shouldn't be shown * Send better error if payment method not found * Revert "Prevent duplicate array entries when merging Swagger JSON" This reverts commit 5783db9eda17c29908a60fdef2c3ebe130a8b059. * Fix LNUrl doc * Fix some warnings Co-authored-by: Dennis Reimann <mail@dennisreimann.de> Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
#if ALTCOINS
|
|
using BTCPayServer.Services.Altcoins.Ethereum.Payments;
|
|
using BTCPayServer.Services.Altcoins.Monero.Payments;
|
|
#endif
|
|
using BTCPayServer.Services.Invoices;
|
|
using NBitcoin;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace BTCPayServer.Payments
|
|
{
|
|
/// <summary>
|
|
/// The different ways to pay an invoice
|
|
/// </summary>
|
|
public static class PaymentTypes
|
|
{
|
|
private static PaymentType[] _paymentTypes =
|
|
{
|
|
BTCLike, LightningLike, LNURLPay,
|
|
#if ALTCOINS
|
|
MoneroLike,
|
|
EthereumPaymentType.Instance
|
|
#endif
|
|
};
|
|
/// <summary>
|
|
/// On-Chain UTXO based, bitcoin compatible
|
|
/// </summary>
|
|
public static BitcoinPaymentType BTCLike => BitcoinPaymentType.Instance;
|
|
/// <summary>
|
|
/// Lightning payment
|
|
/// </summary>
|
|
public static LightningPaymentType LightningLike => LightningPaymentType.Instance;
|
|
/// <summary>
|
|
/// Lightning payment
|
|
/// </summary>
|
|
public static LNURLPayPaymentType LNURLPay => LNURLPayPaymentType.Instance;
|
|
|
|
#if ALTCOINS
|
|
/// <summary>
|
|
/// Monero payment
|
|
/// </summary>
|
|
public static MoneroPaymentType MoneroLike => MoneroPaymentType.Instance;
|
|
#endif
|
|
|
|
public static bool TryParse(string paymentType, out PaymentType type)
|
|
{
|
|
type = _paymentTypes.FirstOrDefault(type1 => type1.IsPaymentType(paymentType));
|
|
return type != null;
|
|
}
|
|
public static PaymentType Parse(string paymentType)
|
|
{
|
|
if (!TryParse(paymentType, out var result))
|
|
throw new FormatException("Invalid payment type");
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public abstract class PaymentType
|
|
{
|
|
public abstract string ToPrettyString();
|
|
public override string ToString()
|
|
{
|
|
return GetId();
|
|
}
|
|
|
|
/// <summary>
|
|
/// A string we can expose to Greenfield API, not subjected to internal legacy
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public virtual string ToStringNormalized()
|
|
{
|
|
return ToString();
|
|
}
|
|
|
|
public abstract string GetId();
|
|
public virtual string GetBadge() => null;
|
|
public abstract CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str);
|
|
public abstract string SerializePaymentData(BTCPayNetworkBase network, CryptoPaymentData paymentData);
|
|
public abstract IPaymentMethodDetails DeserializePaymentMethodDetails(BTCPayNetworkBase network, string str);
|
|
public abstract string SerializePaymentMethodDetails(BTCPayNetworkBase network, IPaymentMethodDetails details);
|
|
public abstract ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network, JToken value);
|
|
public abstract string GetTransactionLink(BTCPayNetworkBase network, string txId);
|
|
public abstract string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails,
|
|
Money cryptoInfoDue, string serverUri);
|
|
public abstract string InvoiceViewPaymentPartialName { get; }
|
|
|
|
public abstract object GetGreenfieldData(ISupportedPaymentMethod supportedPaymentMethod, bool canModifyStore);
|
|
|
|
public virtual bool IsPaymentType(string paymentType)
|
|
{
|
|
return IsPaymentTypeBase(paymentType);
|
|
}
|
|
|
|
protected bool IsPaymentTypeBase(string paymentType)
|
|
{
|
|
paymentType = paymentType?.ToLowerInvariant();
|
|
return new[]
|
|
{
|
|
GetId().Replace("-", "", StringComparison.InvariantCulture),
|
|
ToStringNormalized()
|
|
}.Contains(
|
|
paymentType,
|
|
StringComparer.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public abstract void PopulateCryptoInfo(PaymentMethod details, Services.Invoices.InvoiceCryptoInfo invoiceCryptoInfo,
|
|
string serverUrl);
|
|
}
|
|
}
|