diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 1ae143b39..3e96638af 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Globalization; @@ -433,8 +434,8 @@ namespace BTCPayServer.Controllers [AcceptMediaTypeConstraint("application/bitcoin-paymentrequest", false)] [XFrameOptionsAttribute(null)] [ReferrerPolicyAttribute("origin")] - public async Task Checkout(string invoiceId, string id = null, string paymentMethodId = null, - [FromQuery] string view = null, [FromQuery] string lang = null) + public async Task Checkout(string? invoiceId, string? id = null, string? paymentMethodId = null, + [FromQuery] string? view = null, [FromQuery] string? lang = null) { //Keep compatibility with Bitpay invoiceId = invoiceId ?? id; @@ -466,7 +467,7 @@ namespace BTCPayServer.Controllers [HttpGet] [Route("invoice-noscript")] - public async Task CheckoutNoScript(string invoiceId, string id = null, string paymentMethodId = null, [FromQuery] string lang = null) + public async Task CheckoutNoScript(string? invoiceId, string? id = null, string? paymentMethodId = null, [FromQuery] string? lang = null) { //Keep compatibility with Bitpay invoiceId = invoiceId ?? id; @@ -480,7 +481,7 @@ namespace BTCPayServer.Controllers return View(model); } - private async Task 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) @@ -604,7 +605,7 @@ namespace BTCPayServer.Controllers return model; } - private string OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity) + private string? OrderAmountFromInvoice(string cryptoCode, InvoiceEntity invoiceEntity) { // if invoice source currency is the same as currently display currency, no need for "order amount from invoice" if (cryptoCode == invoiceEntity.Currency) @@ -624,7 +625,7 @@ namespace BTCPayServer.Controllers [Route("invoice/{invoiceId}/status")] [Route("invoice/{invoiceId}/{paymentMethodId}/status")] [Route("invoice/status")] - public async Task GetStatus(string invoiceId, string paymentMethodId = null, [FromQuery] string lang = null) + public async Task GetStatus(string invoiceId, string? paymentMethodId = null, [FromQuery] string? lang = null) { var model = await GetInvoiceModel(invoiceId, paymentMethodId == null ? null : PaymentMethodId.Parse(paymentMethodId), lang); if (model == null) @@ -699,7 +700,7 @@ namespace BTCPayServer.Controllers [Route("invoices")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [BitpayAPIConstraint(false)] - public async Task ListInvoices(InvoicesModel model = null) + public async Task ListInvoices(InvoicesModel? model = null) { model = this.ParseListQuery(model ?? new InvoicesModel()); @@ -735,7 +736,7 @@ namespace BTCPayServer.Controllers return View(model); } - private InvoiceQuery GetInvoiceQuery(string searchTerm = null, int timezoneOffset = 0) + private InvoiceQuery GetInvoiceQuery(string? searchTerm = null, int timezoneOffset = 0) { var fs = new SearchString(searchTerm); var invoiceQuery = new InvoiceQuery() @@ -758,7 +759,7 @@ namespace BTCPayServer.Controllers [HttpGet] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [BitpayAPIConstraint(false)] - public async Task Export(string format, string searchTerm = null, int timezoneOffset = 0) + public async Task Export(string format, string? searchTerm = null, int timezoneOffset = 0) { var model = new InvoiceExport(_CurrencyNameTable); @@ -792,9 +793,14 @@ namespace BTCPayServer.Controllers [Route("invoices/create")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)] [BitpayAPIConstraint(false)] - public async Task CreateInvoice() + public async Task CreateInvoice(InvoicesModel? model = null) { - var stores = new SelectList(await _StoreRepository.GetStoresByUserId(GetUserId()), nameof(StoreData.Id), nameof(StoreData.StoreName), null); + var stores = new SelectList( + await _StoreRepository.GetStoresByUserId(GetUserId()), + nameof(StoreData.Id), + nameof(StoreData.StoreName), + new SearchString(model?.SearchTerm).GetFilterArray("storeid")?.ToArray().FirstOrDefault() + ); if (!stores.Any()) { TempData[WellKnownTempData.ErrorMessage] = "You need to create at least one store before creating a transaction"; diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index d7a8cfdfd..feab085bc 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -184,7 +184,7 @@ - + Create an invoice