Fix crash if impossible to get the network of a payment

This commit is contained in:
nicolas.dorier
2020-08-13 16:29:04 +09:00
parent f323d06f5c
commit d05f914841
3 changed files with 5 additions and 1 deletions

View File

@@ -144,6 +144,7 @@ namespace BTCPayServer.Controllers
.Select(o => new PaymentMethodId(o, PaymentTypes.BTCLike))
.ToList();
var defaultRefund = invoice.Payments.Select(p => p.GetBlob(_NetworkProvider))
.Where(p => p != null)
.Select(p => p.GetPaymentMethodId().CryptoCode)
.FirstOrDefault();
// TODO: What if no option?

View File

@@ -15,7 +15,7 @@ namespace BTCPayServer.Data
PaymentEntity paymentEntity = null;
if (network == null)
{
paymentEntity = NBitcoin.JsonConverters.Serializer.ToObject<PaymentEntity>(unziped, null);
return null;
}
else
{

View File

@@ -484,6 +484,8 @@ retry:
entity.Payments = invoice.Payments.Select(p =>
{
var paymentEntity = p.GetBlob(_Networks);
if (paymentEntity is null)
return null;
// PaymentEntity on version 0 does not have their own fee, because it was assumed that the payment method have fixed fee.
// We want to hide this legacy detail in InvoiceRepository, so we fetch the fee from the PaymentMethod and assign it to the PaymentEntity.
if (paymentEntity.Version == 0)
@@ -497,6 +499,7 @@ retry:
return paymentEntity;
})
.Where(p => p != null)
.OrderBy(a => a.ReceivedTime).ToList();
#pragma warning restore CS0618
var state = invoice.GetInvoiceState();