mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
@@ -601,12 +601,14 @@ 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 == null)
|
if (model.Item2 != null)
|
||||||
|
return Redirect(model.Item2);
|
||||||
|
else if(model.Item1 == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (view == "modal")
|
if (view == "modal")
|
||||||
model.IsModal = true;
|
model.Item1.IsModal = true;
|
||||||
return View(nameof(Checkout), model);
|
return View(nameof(Checkout), model.Item1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("invoice-noscript")]
|
[HttpGet("invoice-noscript")]
|
||||||
@@ -618,21 +620,39 @@ 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 == null)
|
if (model.Item2 != null)
|
||||||
|
return Redirect(model.Item2);
|
||||||
|
else if(model.Item1 == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
return View(model);
|
return View(model.Item1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<PaymentModel?> GetInvoiceModel(string invoiceId, PaymentMethodId? paymentMethodId, string? lang)
|
private async Task<(PaymentModel?, string?)> 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;
|
return (null, null);
|
||||||
|
|
||||||
var store = await _StoreRepository.FindStore(invoice.StoreId);
|
var store = await _StoreRepository.FindStore(invoice.StoreId);
|
||||||
if (store == null)
|
if (store == null)
|
||||||
return 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 ?? "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isDefaultPaymentId = false;
|
bool isDefaultPaymentId = false;
|
||||||
if (paymentMethodId is null)
|
if (paymentMethodId is null)
|
||||||
@@ -667,19 +687,19 @@ namespace BTCPayServer.Controllers
|
|||||||
isDefaultPaymentId = true;
|
isDefaultPaymentId = true;
|
||||||
}
|
}
|
||||||
if (paymentMethodId is null)
|
if (paymentMethodId is null)
|
||||||
return null;
|
return (null, 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;
|
return (null, 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;
|
return (null, null);
|
||||||
network = paymentMethodTemp.Network;
|
network = paymentMethodTemp.Network;
|
||||||
paymentMethodId = paymentMethodTemp.GetId();
|
paymentMethodId = paymentMethodTemp.GetId();
|
||||||
}
|
}
|
||||||
@@ -695,7 +715,6 @@ 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];
|
||||||
@@ -716,14 +735,6 @@ 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
|
||||||
{
|
{
|
||||||
@@ -799,7 +810,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;
|
return (model, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string? OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity)
|
private string? OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity)
|
||||||
@@ -826,7 +837,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 == null)
|
if (model.Item1 == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
return Json(model);
|
return Json(model);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user