diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 6657617a3..4bfae0b3c 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -601,14 +601,12 @@ namespace BTCPayServer.Controllers if (invoiceId is null) return NotFound(); var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang); - if (model.Item2 != null) - return Redirect(model.Item2); - else if(model.Item1 == null) + if (model == null) return NotFound(); if (view == "modal") - model.Item1.IsModal = true; - return View(nameof(Checkout), model.Item1); + model.IsModal = true; + return View(nameof(Checkout), model); } [HttpGet("invoice-noscript")] @@ -620,39 +618,21 @@ namespace BTCPayServer.Controllers if (invoiceId is null) return NotFound(); var model = await GetInvoiceModel(invoiceId, paymentMethodId is null ? null : PaymentMethodId.Parse(paymentMethodId), lang); - if (model.Item2 != null) - return Redirect(model.Item2); - else if(model.Item1 == null) + if (model == null) return NotFound(); - return View(model.Item1); + return View(model); } - private async Task<(PaymentModel?, string?)> GetInvoiceModel(string invoiceId, PaymentMethodId? paymentMethodId, string? lang) + private async Task GetInvoiceModel(string invoiceId, PaymentMethodId? paymentMethodId, string? lang) { var invoice = await _InvoiceRepository.GetInvoice(invoiceId); if (invoice == null) - return (null, null); + return null; var store = await _StoreRepository.FindStore(invoice.StoreId); if (store == null) - return (null, null); - - var storeBlob = store.GetStoreBlob(); - var receiptEnabled = InvoiceDataBase.ReceiptOptions.Merge(storeBlob.ReceiptOptions, invoice.ReceiptOptions).Enabled is true; - var receiptUrl = receiptEnabled? _linkGenerator.GetUriByAction( - nameof(UIInvoiceController.InvoiceReceipt), - "UIInvoice", - new {invoiceId}, - Request.Scheme, - Request.Host, - Request.PathBase) : null; - if (invoice.Status == InvoiceStatusLegacy.Complete && invoice.Price == 0 && - !invoice.GetPaymentMethods().Any()) - { - return (null, invoice.RedirectURL?.AbsoluteUri ?? receiptUrl ?? "/"); - } - + return null; bool isDefaultPaymentId = false; if (paymentMethodId is null) @@ -687,19 +667,19 @@ namespace BTCPayServer.Controllers isDefaultPaymentId = true; } if (paymentMethodId is null) - return (null, null); + return null; BTCPayNetworkBase network = _NetworkProvider.GetNetwork(paymentMethodId.CryptoCode); if (network is null || !invoice.Support(paymentMethodId)) { if (!isDefaultPaymentId) - return (null, null); + return null; var paymentMethodTemp = invoice .GetPaymentMethods() .FirstOrDefault(c => paymentMethodId.CryptoCode == c.GetId().CryptoCode); if (paymentMethodTemp == null) paymentMethodTemp = invoice.GetPaymentMethods().FirstOrDefault(); if (paymentMethodTemp is null) - return (null, null); + return null; network = paymentMethodTemp.Network; paymentMethodId = paymentMethodTemp.GetId(); } @@ -715,6 +695,7 @@ namespace BTCPayServer.Controllers } } var dto = invoice.EntityToDTO(); + var storeBlob = store.GetStoreBlob(); var accounting = paymentMethod.Calculate(); var paymentMethodHandler = _paymentMethodHandlerDictionary[paymentMethodId]; @@ -735,6 +716,14 @@ namespace BTCPayServer.Controllers } lang ??= storeBlob.DefaultLang; + var receiptEnabled = InvoiceDataBase.ReceiptOptions.Merge(storeBlob.ReceiptOptions, invoice.ReceiptOptions).Enabled is true; + var receiptUrl = receiptEnabled? _linkGenerator.GetUriByAction( + nameof(UIInvoiceController.InvoiceReceipt), + "UIInvoice", + new {invoiceId}, + Request.Scheme, + Request.Host, + Request.PathBase) : null; var model = new PaymentModel { @@ -810,7 +799,7 @@ namespace BTCPayServer.Controllers model.PaymentMethodId = paymentMethodId.ToString(); var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds); model.TimeLeft = expiration.PrettyPrint(); - return (model, null); + return model; } private string? OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity) @@ -837,7 +826,7 @@ namespace BTCPayServer.Controllers if (string.IsNullOrEmpty(paymentMethodId)) paymentMethodId = implicitPaymentMethodId; var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang); - if (model.Item1 == null) + if (model == null) return NotFound(); return Json(model); }