Adding lightning invoice fallback to onchain bitcoin url if enabled

This commit is contained in:
rockstardev 2020-11-09 00:23:09 -06:00
parent 7f79d16f02
commit 3c6992e910
2 changed files with 16 additions and 4 deletions

View file

@ -62,6 +62,7 @@ namespace BTCPayServer.Data
_DefaultCurrencyPairs = value;
}
}
public bool OnChainWithLnInvoiceFallback { get; set; } = true;
public string GetDefaultCurrencyPairString()
{
@ -189,6 +190,7 @@ namespace BTCPayServer.Data
public bool PayJoinEnabled { get; set; }
public StoreHints Hints { get; set; }
public class StoreHints
{
public bool Wallet { get; set; }

View file

@ -46,8 +46,7 @@ namespace BTCPayServer.Payments.Bitcoin
public Task<KeyPathInformation> ReserveAddress;
}
public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse,
StoreBlob storeBlob)
public override void PreparePaymentModel(PaymentModel model, InvoiceResponse invoiceResponse, StoreBlob storeBlob)
{
var paymentMethodId = new PaymentMethodId(model.CryptoCode, PaymentTypes.BTCLike);
@ -55,8 +54,19 @@ namespace BTCPayServer.Payments.Bitcoin
var network = _networkProvider.GetNetwork<BTCPayNetwork>(model.CryptoCode);
model.IsLightning = false;
model.PaymentMethodName = GetPaymentMethodName(network);
model.InvoiceBitcoinUrl = cryptoInfo.PaymentUrls.BIP21;
model.InvoiceBitcoinUrlQR = cryptoInfo.PaymentUrls.BIP21;
var invoiceBitcoinUrl = cryptoInfo.PaymentUrls.BIP21;
if (storeBlob.OnChainWithLnInvoiceFallback)
{
var lightningInfo = invoiceResponse.CryptoInfo.FirstOrDefault(a =>
a.GetpaymentMethodId() == new PaymentMethodId(model.CryptoCode, PaymentTypes.LightningLike));
if (!String.IsNullOrEmpty(lightningInfo?.PaymentUrls?.BOLT11))
invoiceBitcoinUrl += "&" + lightningInfo.PaymentUrls.BOLT11.Replace("lightning:", "lightning=", StringComparison.OrdinalIgnoreCase);
}
model.InvoiceBitcoinUrl = invoiceBitcoinUrl;
model.InvoiceBitcoinUrlQR = invoiceBitcoinUrl;
}
public override string GetCryptoImage(PaymentMethodId paymentMethodId)