POS: Fix keypad view without custom amount (#4185)

The custom amount option was disabled by default in #4126. This requires some additional adaptations in the post action as otherwise the invoice won't be generated.

Fixes #4183.
This commit is contained in:
d11n 2022-10-08 05:41:56 +02:00 committed by GitHub
parent 3f19dc55fa
commit ffa2c59df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
[DomainMappingConstraint(AppType.PointOfSale)] [DomainMappingConstraint(AppType.PointOfSale)]
[RateLimitsFilter(ZoneLimits.PublicInvoices, Scope = RateLimitsScope.RemoteAddress)] [RateLimitsFilter(ZoneLimits.PublicInvoices, Scope = RateLimitsScope.RemoteAddress)]
public async Task<IActionResult> ViewPointOfSale(string appId, public async Task<IActionResult> ViewPointOfSale(string appId,
PosViewType viewType, PosViewType? viewType,
[ModelBinder(typeof(InvariantDecimalModelBinder))] decimal? amount, [ModelBinder(typeof(InvariantDecimalModelBinder))] decimal? amount,
string email, string email,
string orderId, string orderId,
@ -129,12 +129,14 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
return NotFound(); return NotFound();
var settings = app.GetSettings<PointOfSaleSettings>(); var settings = app.GetSettings<PointOfSaleSettings>();
settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView; settings.DefaultView = settings.EnableShoppingCart ? PosViewType.Cart : settings.DefaultView;
if (string.IsNullOrEmpty(choiceKey) && !settings.ShowCustomAmount && settings.DefaultView != PosViewType.Cart) var currentView = viewType ?? settings.DefaultView;
if (string.IsNullOrEmpty(choiceKey) && !settings.ShowCustomAmount &&
currentView != PosViewType.Cart && currentView != PosViewType.Light)
{ {
return RedirectToAction(nameof(ViewPointOfSale), new { appId, viewType }); return RedirectToAction(nameof(ViewPointOfSale), new { appId, viewType });
} }
string title = null; string title;
decimal? price = null; decimal? price;
Dictionary<string, InvoiceSupportedTransactionCurrency> paymentMethods = null; Dictionary<string, InvoiceSupportedTransactionCurrency> paymentMethods = null;
ViewPointOfSaleViewModel.Item choice = null; ViewPointOfSaleViewModel.Item choice = null;
if (!string.IsNullOrEmpty(choiceKey)) if (!string.IsNullOrEmpty(choiceKey))
@ -155,12 +157,9 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
price = amount; price = amount;
} }
if (choice.Inventory.HasValue) if (choice.Inventory is <= 0)
{ {
if (choice.Inventory <= 0) return RedirectToAction(nameof(ViewPointOfSale), new { appId });
{
return RedirectToAction(nameof(ViewPointOfSale), new { appId = appId });
}
} }
if (choice?.PaymentMethods?.Any() is true) if (choice?.PaymentMethods?.Any() is true)
@ -171,17 +170,16 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
} }
else else
{ {
if (!settings.ShowCustomAmount && settings.DefaultView != PosViewType.Cart) if (!settings.ShowCustomAmount && currentView != PosViewType.Cart && currentView != PosViewType.Light)
return NotFound(); return NotFound();
price = amount; price = amount;
title = settings.Title; title = settings.Title;
//if cart IS enabled and we detect posdata that matches the cart system's, check inventory for the items //if cart IS enabled and we detect posdata that matches the cart system's, check inventory for the items
if (!string.IsNullOrEmpty(posData) && if (!string.IsNullOrEmpty(posData) && currentView == PosViewType.Cart &&
settings.DefaultView == PosViewType.Cart &&
AppService.TryParsePosCartItems(posData, out var cartItems)) AppService.TryParsePosCartItems(posData, out var cartItems))
{ {
var choices = _appService.GetPOSItems(settings.Template, settings.Currency); var choices = _appService.GetPOSItems(settings.Template, settings.Currency);
foreach (var cartItem in cartItems) foreach (var cartItem in cartItems)
{ {
@ -205,7 +203,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
var store = await _appService.GetStore(app); var store = await _appService.GetStore(app);
try try
{ {
var invoice = await _invoiceController.CreateInvoiceCore(new BitpayCreateInvoiceRequest() var invoice = await _invoiceController.CreateInvoiceCore(new BitpayCreateInvoiceRequest
{ {
ItemCode = choice?.Id, ItemCode = choice?.Id,
ItemDesc = title, ItemDesc = title,
@ -227,7 +225,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
? store.GetStoreBlob().RequiresRefundEmail ? store.GetStoreBlob().RequiresRefundEmail
: requiresRefundEmail == RequiresRefundEmail.On, : requiresRefundEmail == RequiresRefundEmail.On,
}, store, HttpContext.Request.GetAbsoluteRoot(), }, store, HttpContext.Request.GetAbsoluteRoot(),
new List<string>() { AppService.GetAppInternalTag(appId) }, new List<string> { AppService.GetAppInternalTag(appId) },
cancellationToken, (entity) => cancellationToken, (entity) =>
{ {
entity.Metadata.OrderUrl = Request.GetDisplayUrl(); entity.Metadata.OrderUrl = Request.GetDisplayUrl();