Do not put payRequest in the metadata (#4870)

This commit is contained in:
Nicolas Dorier
2023-04-12 16:30:22 +09:00
committed by GitHub
parent 1aaccb1e6b
commit 48ebaf5c5a
2 changed files with 16 additions and 17 deletions

View File

@@ -467,13 +467,13 @@ namespace BTCPayServer
lnurlRequest ??= new LNURLPayRequest(); lnurlRequest ??= new LNURLPayRequest();
lnUrlMetadata ??= new Dictionary<string, string>(); lnUrlMetadata ??= new Dictionary<string, string>();
var pm = i.GetPaymentMethod(pmi);
var paymentMethodDetails = (LNURLPayPaymentMethodDetails)pm.GetPaymentMethodDetails();
bool updatePaymentMethodDetails = false;
if (lnUrlMetadata?.TryGetValue("text/identifier", out var lnAddress) is true && lnAddress is not null) if (lnUrlMetadata?.TryGetValue("text/identifier", out var lnAddress) is true && lnAddress is not null)
{ {
var pm = i.GetPaymentMethod(pmi);
var paymentMethodDetails = (LNURLPayPaymentMethodDetails)pm.GetPaymentMethodDetails();
paymentMethodDetails.ConsumedLightningAddress = lnAddress; paymentMethodDetails.ConsumedLightningAddress = lnAddress;
pm.SetPaymentMethodDetails(paymentMethodDetails); updatePaymentMethodDetails = true;
await _invoiceRepository.UpdateInvoicePaymentMethod(i.Id, pm);
} }
if (!lnUrlMetadata.ContainsKey("text/plain")) if (!lnUrlMetadata.ContainsKey("text/plain"))
@@ -507,15 +507,16 @@ namespace BTCPayServer
lnurlRequest.MaxSendable = LightMoney.FromUnit(6.12m, LightMoneyUnit.BTC); lnurlRequest.MaxSendable = LightMoney.FromUnit(6.12m, LightMoneyUnit.BTC);
lnurlRequest = await _pluginHookService.ApplyFilter("modify-lnurlp-request", lnurlRequest) as LNURLPayRequest; lnurlRequest = await _pluginHookService.ApplyFilter("modify-lnurlp-request", lnurlRequest) as LNURLPayRequest;
if (paymentMethodDetails.PayRequest is null)
i.Metadata ??= new InvoiceMetadata();
var metadata = i.Metadata.ToJObject();
if (metadata.Property("payRequest") is null)
{ {
metadata.Add("payRequest", JToken.FromObject(lnurlRequest)); paymentMethodDetails.PayRequest = lnurlRequest;
await _invoiceRepository.UpdateInvoiceMetadata(i.Id, i.StoreId, metadata); updatePaymentMethodDetails = true;
}
if (updatePaymentMethodDetails)
{
pm.SetPaymentMethodDetails(paymentMethodDetails);
await _invoiceRepository.UpdateInvoicePaymentMethod(i.Id, pm);
} }
return lnurlRequest; return lnurlRequest;
} }
@@ -572,13 +573,9 @@ namespace BTCPayServer
if (paymentMethodDetails?.LightningSupportedPaymentMethod is null) if (paymentMethodDetails?.LightningSupportedPaymentMethod is null)
return NotFound(); return NotFound();
LNURLPayRequest lnurlPayRequest; LNURLPayRequest lnurlPayRequest = paymentMethodDetails.PayRequest;
var blob = store.GetStoreBlob(); var blob = store.GetStoreBlob();
if (i.Metadata.AdditionalData.TryGetValue("payRequest", out var t) && t is JObject jo) if (paymentMethodDetails.PayRequest is null)
{
lnurlPayRequest = jo.ToObject<LNURLPayRequest>();
}
else
{ {
lnurlPayRequest = await CreateLNUrlRequestFromInvoice(cryptoCode, i, store, blob, allowOverpay: false); lnurlPayRequest = await CreateLNUrlRequestFromInvoice(cryptoCode, i, store, blob, allowOverpay: false);
if (lnurlPayRequest is null) if (lnurlPayRequest is null)

View File

@@ -3,6 +3,7 @@ using BTCPayServer.Client.JsonConverters;
using BTCPayServer.Lightning; using BTCPayServer.Lightning;
using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.Lightning;
using BTCPayServer.Services.Invoices; using BTCPayServer.Services.Invoices;
using LNURL;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@@ -18,6 +19,7 @@ namespace BTCPayServer.Payments
public string ProvidedComment { get; set; } public string ProvidedComment { get; set; }
public string ConsumedLightningAddress { get; set; } public string ConsumedLightningAddress { get; set; }
public LNURLPayRequest PayRequest { get; set; }
public override PaymentType GetPaymentType() public override PaymentType GetPaymentType()
{ {