From 3c6992e9106fe6280125647e8f706e798cf69e7f Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 9 Nov 2020 00:23:09 -0600 Subject: [PATCH] Adding lightning invoice fallback to onchain bitcoin url if enabled --- BTCPayServer/Data/StoreBlob.cs | 2 ++ .../Bitcoin/BitcoinLikePaymentHandler.cs | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/Data/StoreBlob.cs b/BTCPayServer/Data/StoreBlob.cs index e86d767c8..f10b0fa3a 100644 --- a/BTCPayServer/Data/StoreBlob.cs +++ b/BTCPayServer/Data/StoreBlob.cs @@ -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; } diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index e1c582752..2ac3f26bd 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -46,8 +46,7 @@ namespace BTCPayServer.Payments.Bitcoin public Task 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(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)