mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
Merge pull request #2301 from btcpayserver/gf/paymenttypeparse
Make payment type parsing more dynamic
This commit is contained in:
commit
6843b0eaab
@ -79,5 +79,9 @@ namespace BTCPayServer.Payments
|
||||
}
|
||||
|
||||
public override string InvoiceViewPaymentPartialName { get; } = "Bitcoin/ViewBitcoinLikePaymentData";
|
||||
public override bool IsPaymentType(string paymentType)
|
||||
{
|
||||
return string.IsNullOrEmpty(paymentType) || base.IsPaymentType(paymentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,5 +59,9 @@ namespace BTCPayServer.Payments
|
||||
}
|
||||
|
||||
public override string InvoiceViewPaymentPartialName { get; } = "Lightning/ViewLightningLikePaymentData";
|
||||
public override bool IsPaymentType(string paymentType)
|
||||
{
|
||||
return paymentType?.Equals("offchain", StringComparison.InvariantCultureIgnoreCase) is true || base.IsPaymentType(paymentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
#if ALTCOINS
|
||||
using BTCPayServer.Services.Altcoins.Ethereum.Payments;
|
||||
using BTCPayServer.Services.Altcoins.Monero.Payments;
|
||||
@ -14,6 +15,14 @@ namespace BTCPayServer.Payments
|
||||
/// </summary>
|
||||
public static class PaymentTypes
|
||||
{
|
||||
private static PaymentType[] _paymentTypes =
|
||||
{
|
||||
BTCLike, LightningLike,
|
||||
#if ALTCOINS
|
||||
MoneroLike,
|
||||
EthereumPaymentType.Instance
|
||||
#endif
|
||||
};
|
||||
/// <summary>
|
||||
/// On-Chain UTXO based, bitcoin compatible
|
||||
/// </summary>
|
||||
@ -32,29 +41,8 @@ namespace BTCPayServer.Payments
|
||||
|
||||
public static bool TryParse(string paymentType, out PaymentType type)
|
||||
{
|
||||
switch (paymentType.ToLowerInvariant())
|
||||
{
|
||||
case "btclike":
|
||||
case "onchain":
|
||||
type = PaymentTypes.BTCLike;
|
||||
break;
|
||||
case "lightninglike":
|
||||
case "offchain":
|
||||
type = PaymentTypes.LightningLike;
|
||||
break;
|
||||
#if ALTCOINS
|
||||
case "monerolike":
|
||||
type = PaymentTypes.MoneroLike;
|
||||
break;
|
||||
case "ethereumlike":
|
||||
type = EthereumPaymentType.Instance;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
type = null;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
type = _paymentTypes.FirstOrDefault(type1 => type1.IsPaymentType(paymentType));
|
||||
return type != null;
|
||||
}
|
||||
public static PaymentType Parse(string paymentType)
|
||||
{
|
||||
@ -92,5 +80,17 @@ namespace BTCPayServer.Payments
|
||||
public abstract string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails,
|
||||
Money cryptoInfoDue, string serverUri);
|
||||
public abstract string InvoiceViewPaymentPartialName { get; }
|
||||
|
||||
public virtual bool IsPaymentType(string paymentType)
|
||||
{
|
||||
paymentType = paymentType?.ToLowerInvariant();
|
||||
return new[]
|
||||
{
|
||||
GetId().Replace("-", "", StringComparison.InvariantCulture),
|
||||
ToStringNormalized()
|
||||
}.Contains(
|
||||
paymentType,
|
||||
StringComparer.InvariantCultureIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user