Invoice: Improve zero amount invoice handling (#6199)

This is for the checkout page to properly redirect paid invoices with no payment methods (e.g. free invoices with zero amount) to either the receipt page or redirect URL. Only fall back to 404 if there is neither.

Fixes #6123.
This commit is contained in:
d11n
2024-09-09 04:05:03 +02:00
committed by GitHub
parent 73dcde7780
commit 841f41da2f
4 changed files with 24 additions and 9 deletions

View File

@@ -199,16 +199,13 @@ namespace BTCPayServer.Controllers
return NotFound();
var receipt = InvoiceDataBase.ReceiptOptions.Merge(store.GetStoreBlob().ReceiptOptions, i.ReceiptOptions);
if (receipt.Enabled is not true)
{
if (i.RedirectURL is not null)
{
return Redirect(i.RedirectURL.ToString());
}
return NotFound();
return i.RedirectURL is not null
? Redirect(i.RedirectURL.ToString())
: NotFound();
}
var storeBlob = store.GetStoreBlob();
var vm = new InvoiceReceiptViewModel
{
@@ -699,7 +696,16 @@ namespace BTCPayServer.Controllers
var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang);
if (model == null)
return NotFound();
{
// see if the invoice actually exists and is in a state for which we do not display the checkout
var invoice = await _InvoiceRepository.GetInvoice(invoiceId);
var store = invoice != null ? await _StoreRepository.GetStoreByInvoiceId(invoice.Id) : null;
var receipt = invoice != null && store != null ? InvoiceDataBase.ReceiptOptions.Merge(store.GetStoreBlob().ReceiptOptions, invoice.ReceiptOptions) : null;
var redirectUrl = invoice?.RedirectURL?.ToString();
return receipt?.Enabled is true
? RedirectToAction(nameof(InvoiceReceipt), new { invoiceId })
: !string.IsNullOrEmpty(redirectUrl) ? Redirect(redirectUrl) : NotFound();
}
if (view == "modal")
model.IsModal = true;