mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Auto-select store when creating a new invoice (#2680)
* Auto-select store when creating a new invoice * Set types as nullable in InvoiceController.UI.cs
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@@ -433,8 +434,8 @@ namespace BTCPayServer.Controllers
|
|||||||
[AcceptMediaTypeConstraint("application/bitcoin-paymentrequest", false)]
|
[AcceptMediaTypeConstraint("application/bitcoin-paymentrequest", false)]
|
||||||
[XFrameOptionsAttribute(null)]
|
[XFrameOptionsAttribute(null)]
|
||||||
[ReferrerPolicyAttribute("origin")]
|
[ReferrerPolicyAttribute("origin")]
|
||||||
public async Task<IActionResult> Checkout(string invoiceId, string id = null, string paymentMethodId = null,
|
public async Task<IActionResult> Checkout(string? invoiceId, string? id = null, string? paymentMethodId = null,
|
||||||
[FromQuery] string view = null, [FromQuery] string lang = null)
|
[FromQuery] string? view = null, [FromQuery] string? lang = null)
|
||||||
{
|
{
|
||||||
//Keep compatibility with Bitpay
|
//Keep compatibility with Bitpay
|
||||||
invoiceId = invoiceId ?? id;
|
invoiceId = invoiceId ?? id;
|
||||||
@@ -466,7 +467,7 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("invoice-noscript")]
|
[Route("invoice-noscript")]
|
||||||
public async Task<IActionResult> CheckoutNoScript(string invoiceId, string id = null, string paymentMethodId = null, [FromQuery] string lang = null)
|
public async Task<IActionResult> CheckoutNoScript(string? invoiceId, string? id = null, string? paymentMethodId = null, [FromQuery] string? lang = null)
|
||||||
{
|
{
|
||||||
//Keep compatibility with Bitpay
|
//Keep compatibility with Bitpay
|
||||||
invoiceId = invoiceId ?? id;
|
invoiceId = invoiceId ?? id;
|
||||||
@@ -480,7 +481,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<PaymentModel> 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)
|
||||||
@@ -604,7 +605,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return model;
|
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 invoice source currency is the same as currently display currency, no need for "order amount from invoice"
|
||||||
if (cryptoCode == invoiceEntity.Currency)
|
if (cryptoCode == invoiceEntity.Currency)
|
||||||
@@ -624,7 +625,7 @@ namespace BTCPayServer.Controllers
|
|||||||
[Route("invoice/{invoiceId}/status")]
|
[Route("invoice/{invoiceId}/status")]
|
||||||
[Route("invoice/{invoiceId}/{paymentMethodId}/status")]
|
[Route("invoice/{invoiceId}/{paymentMethodId}/status")]
|
||||||
[Route("invoice/status")]
|
[Route("invoice/status")]
|
||||||
public async Task<IActionResult> GetStatus(string invoiceId, string paymentMethodId = null, [FromQuery] string lang = null)
|
public async Task<IActionResult> GetStatus(string invoiceId, string? paymentMethodId = null, [FromQuery] string? lang = null)
|
||||||
{
|
{
|
||||||
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 == null)
|
||||||
@@ -699,7 +700,7 @@ namespace BTCPayServer.Controllers
|
|||||||
[Route("invoices")]
|
[Route("invoices")]
|
||||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
public async Task<IActionResult> ListInvoices(InvoicesModel model = null)
|
public async Task<IActionResult> ListInvoices(InvoicesModel? model = null)
|
||||||
{
|
{
|
||||||
model = this.ParseListQuery(model ?? new InvoicesModel());
|
model = this.ParseListQuery(model ?? new InvoicesModel());
|
||||||
|
|
||||||
@@ -735,7 +736,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(model);
|
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 fs = new SearchString(searchTerm);
|
||||||
var invoiceQuery = new InvoiceQuery()
|
var invoiceQuery = new InvoiceQuery()
|
||||||
@@ -758,7 +759,7 @@ namespace BTCPayServer.Controllers
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
public async Task<IActionResult> Export(string format, string searchTerm = null, int timezoneOffset = 0)
|
public async Task<IActionResult> Export(string format, string? searchTerm = null, int timezoneOffset = 0)
|
||||||
{
|
{
|
||||||
var model = new InvoiceExport(_CurrencyNameTable);
|
var model = new InvoiceExport(_CurrencyNameTable);
|
||||||
|
|
||||||
@@ -792,9 +793,14 @@ namespace BTCPayServer.Controllers
|
|||||||
[Route("invoices/create")]
|
[Route("invoices/create")]
|
||||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
public async Task<IActionResult> CreateInvoice()
|
public async Task<IActionResult> 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())
|
if (!stores.Any())
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.ErrorMessage] = "You need to create at least one store before creating a transaction";
|
TempData[WellKnownTempData.ErrorMessage] = "You need to create at least one store before creating a transaction";
|
||||||
|
|||||||
@@ -184,7 +184,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</small>
|
</small>
|
||||||
</h2>
|
</h2>
|
||||||
<a id="CreateNewInvoice" asp-action="CreateInvoice" class="btn btn-primary mt-3 mt-sm-0">
|
<a id="CreateNewInvoice" asp-action="CreateInvoice" asp-route-searchTerm="@Model.SearchTerm" class="btn btn-primary mt-3 mt-sm-0">
|
||||||
<span class="fa fa-plus"></span>
|
<span class="fa fa-plus"></span>
|
||||||
Create an invoice
|
Create an invoice
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user