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>
101 lines
4.0 KiB
C#
101 lines
4.0 KiB
C#
using System;
|
|
using BTCPayServer.Client.Models;
|
|
using BTCPayServer.Controllers.GreenField;
|
|
using BTCPayServer.Payments.Lightning;
|
|
using BTCPayServer.Services.Invoices;
|
|
using NBitcoin;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace BTCPayServer.Payments
|
|
{
|
|
public class LightningPaymentType : PaymentType
|
|
{
|
|
public static LightningPaymentType Instance { get; } = new LightningPaymentType();
|
|
|
|
private protected LightningPaymentType() { }
|
|
|
|
public override string ToPrettyString() => "Off-Chain";
|
|
public override string GetId() => "LightningLike";
|
|
public override string GetBadge() => "⚡";
|
|
public override string ToStringNormalized() => "LightningNetwork";
|
|
|
|
public override CryptoPaymentData DeserializePaymentData(BTCPayNetworkBase network, string str)
|
|
{
|
|
return ((BTCPayNetwork)network)?.ToObject<LightningLikePaymentData>(str);
|
|
}
|
|
|
|
public override string SerializePaymentData(BTCPayNetworkBase network, CryptoPaymentData paymentData)
|
|
{
|
|
return ((BTCPayNetwork)network).ToString(paymentData);
|
|
}
|
|
|
|
public override IPaymentMethodDetails DeserializePaymentMethodDetails(BTCPayNetworkBase network, string str)
|
|
{
|
|
return JsonConvert.DeserializeObject<LightningLikePaymentMethodDetails>(str);
|
|
}
|
|
|
|
public override string SerializePaymentMethodDetails(BTCPayNetworkBase network, IPaymentMethodDetails details)
|
|
{
|
|
return JsonConvert.SerializeObject(details);
|
|
}
|
|
|
|
public override ISupportedPaymentMethod DeserializeSupportedPaymentMethod(BTCPayNetworkBase network,
|
|
JToken value)
|
|
{
|
|
return JsonConvert.DeserializeObject<LightningSupportedPaymentMethod>(value.ToString());
|
|
}
|
|
|
|
public override string GetTransactionLink(BTCPayNetworkBase network, string txId)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public override string GetPaymentLink(BTCPayNetworkBase network, IPaymentMethodDetails paymentMethodDetails,
|
|
Money cryptoInfoDue, string serverUri)
|
|
{
|
|
if (!paymentMethodDetails.Activated)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
var lnInvoiceTrimmedOfScheme = paymentMethodDetails.GetPaymentDestination().ToLowerInvariant()
|
|
.Replace("lightning:", "", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
return $"lightning:{lnInvoiceTrimmedOfScheme}";
|
|
}
|
|
|
|
public override string InvoiceViewPaymentPartialName { get; } = "Lightning/ViewLightningLikePaymentData";
|
|
|
|
public override object GetGreenfieldData(ISupportedPaymentMethod supportedPaymentMethod, bool canModifyStore)
|
|
{
|
|
if (supportedPaymentMethod is LightningSupportedPaymentMethod lightningSupportedPaymentMethod)
|
|
return new LightningNetworkPaymentMethodBaseData()
|
|
{
|
|
ConnectionString = lightningSupportedPaymentMethod.IsInternalNode
|
|
?
|
|
lightningSupportedPaymentMethod.GetDisplayableConnectionString()
|
|
:
|
|
canModifyStore
|
|
? lightningSupportedPaymentMethod.GetDisplayableConnectionString()
|
|
:
|
|
"*NEED CanModifyStoreSettings PERMISSION TO VIEW*"
|
|
};
|
|
return null;
|
|
}
|
|
|
|
public override bool IsPaymentType(string paymentType)
|
|
{
|
|
return paymentType?.Equals("offchain", StringComparison.InvariantCultureIgnoreCase) is true || base.IsPaymentType(paymentType);
|
|
}
|
|
|
|
public override void PopulateCryptoInfo(PaymentMethod details, InvoiceCryptoInfo invoiceCryptoInfo, string serverUrl)
|
|
{
|
|
invoiceCryptoInfo.PaymentUrls = new InvoiceCryptoInfo.InvoicePaymentUrls()
|
|
{
|
|
BOLT11 = GetPaymentLink(details.Network, details.GetPaymentMethodDetails(), invoiceCryptoInfo.Due,
|
|
serverUrl)
|
|
};
|
|
}
|
|
}
|
|
}
|