mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-03-12 02:08:32 +01:00
Revert "Redirect instead of show 404 on 0 amount invoices"
This reverts commit 7f617df4e8
.
This commit is contained in:
parent
7f617df4e8
commit
1322fd97f6
1 changed files with 22 additions and 33 deletions
|
@ -601,14 +601,12 @@ namespace BTCPayServer.Controllers
|
||||||
if (invoiceId is null)
|
if (invoiceId is null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
|
var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
|
||||||
if (model.Item2 != null)
|
if (model == null)
|
||||||
return Redirect(model.Item2);
|
|
||||||
else if(model.Item1 == null)
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (view == "modal")
|
if (view == "modal")
|
||||||
model.Item1.IsModal = true;
|
model.IsModal = true;
|
||||||
return View(nameof(Checkout), model.Item1);
|
return View(nameof(Checkout), model);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("invoice-noscript")]
|
[HttpGet("invoice-noscript")]
|
||||||
|
@ -620,39 +618,21 @@ namespace BTCPayServer.Controllers
|
||||||
if (invoiceId is null)
|
if (invoiceId is null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
var model = await GetInvoiceModel(invoiceId, paymentMethodId is null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
|
var model = await GetInvoiceModel(invoiceId, paymentMethodId is null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
|
||||||
if (model.Item2 != null)
|
if (model == null)
|
||||||
return Redirect(model.Item2);
|
|
||||||
else if(model.Item1 == null)
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
return View(model.Item1);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<(PaymentModel?, string?)> GetInvoiceModel(string invoiceId, PaymentMethodId? paymentMethodId, string? lang)
|
private async Task<PaymentModel?> GetInvoiceModel(string invoiceId, PaymentMethodId? paymentMethodId, string? lang)
|
||||||
{
|
{
|
||||||
var invoice = await _InvoiceRepository.GetInvoice(invoiceId);
|
var invoice = await _InvoiceRepository.GetInvoice(invoiceId);
|
||||||
if (invoice == null)
|
if (invoice == null)
|
||||||
return (null, null);
|
return null;
|
||||||
|
|
||||||
var store = await _StoreRepository.FindStore(invoice.StoreId);
|
var store = await _StoreRepository.FindStore(invoice.StoreId);
|
||||||
if (store == null)
|
if (store == null)
|
||||||
return (null, null);
|
return 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 ?? "/");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool isDefaultPaymentId = false;
|
bool isDefaultPaymentId = false;
|
||||||
if (paymentMethodId is null)
|
if (paymentMethodId is null)
|
||||||
|
@ -687,19 +667,19 @@ namespace BTCPayServer.Controllers
|
||||||
isDefaultPaymentId = true;
|
isDefaultPaymentId = true;
|
||||||
}
|
}
|
||||||
if (paymentMethodId is null)
|
if (paymentMethodId is null)
|
||||||
return (null, null);
|
return null;
|
||||||
BTCPayNetworkBase network = _NetworkProvider.GetNetwork<BTCPayNetworkBase>(paymentMethodId.CryptoCode);
|
BTCPayNetworkBase network = _NetworkProvider.GetNetwork<BTCPayNetworkBase>(paymentMethodId.CryptoCode);
|
||||||
if (network is null || !invoice.Support(paymentMethodId))
|
if (network is null || !invoice.Support(paymentMethodId))
|
||||||
{
|
{
|
||||||
if (!isDefaultPaymentId)
|
if (!isDefaultPaymentId)
|
||||||
return (null, null);
|
return null;
|
||||||
var paymentMethodTemp = invoice
|
var paymentMethodTemp = invoice
|
||||||
.GetPaymentMethods()
|
.GetPaymentMethods()
|
||||||
.FirstOrDefault(c => paymentMethodId.CryptoCode == c.GetId().CryptoCode);
|
.FirstOrDefault(c => paymentMethodId.CryptoCode == c.GetId().CryptoCode);
|
||||||
if (paymentMethodTemp == null)
|
if (paymentMethodTemp == null)
|
||||||
paymentMethodTemp = invoice.GetPaymentMethods().FirstOrDefault();
|
paymentMethodTemp = invoice.GetPaymentMethods().FirstOrDefault();
|
||||||
if (paymentMethodTemp is null)
|
if (paymentMethodTemp is null)
|
||||||
return (null, null);
|
return null;
|
||||||
network = paymentMethodTemp.Network;
|
network = paymentMethodTemp.Network;
|
||||||
paymentMethodId = paymentMethodTemp.GetId();
|
paymentMethodId = paymentMethodTemp.GetId();
|
||||||
}
|
}
|
||||||
|
@ -715,6 +695,7 @@ namespace BTCPayServer.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var dto = invoice.EntityToDTO();
|
var dto = invoice.EntityToDTO();
|
||||||
|
var storeBlob = store.GetStoreBlob();
|
||||||
var accounting = paymentMethod.Calculate();
|
var accounting = paymentMethod.Calculate();
|
||||||
|
|
||||||
var paymentMethodHandler = _paymentMethodHandlerDictionary[paymentMethodId];
|
var paymentMethodHandler = _paymentMethodHandlerDictionary[paymentMethodId];
|
||||||
|
@ -735,6 +716,14 @@ namespace BTCPayServer.Controllers
|
||||||
}
|
}
|
||||||
lang ??= storeBlob.DefaultLang;
|
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
|
var model = new PaymentModel
|
||||||
{
|
{
|
||||||
|
@ -810,7 +799,7 @@ namespace BTCPayServer.Controllers
|
||||||
model.PaymentMethodId = paymentMethodId.ToString();
|
model.PaymentMethodId = paymentMethodId.ToString();
|
||||||
var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds);
|
var expiration = TimeSpan.FromSeconds(model.ExpirationSeconds);
|
||||||
model.TimeLeft = expiration.PrettyPrint();
|
model.TimeLeft = expiration.PrettyPrint();
|
||||||
return (model, null);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity)
|
private string? OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity)
|
||||||
|
@ -837,7 +826,7 @@ namespace BTCPayServer.Controllers
|
||||||
if (string.IsNullOrEmpty(paymentMethodId))
|
if (string.IsNullOrEmpty(paymentMethodId))
|
||||||
paymentMethodId = implicitPaymentMethodId;
|
paymentMethodId = implicitPaymentMethodId;
|
||||||
var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
|
var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
|
||||||
if (model.Item1 == null)
|
if (model == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
return Json(model);
|
return Json(model);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue