Fix: Applying a discount in PoS with cart wasn't working (#5079)

This commit is contained in:
Nicolas Dorier
2023-06-16 23:02:14 +09:00
committed by GitHub
parent f11424f73a
commit e81403ec3f
5 changed files with 24 additions and 21 deletions

View File

@@ -131,6 +131,8 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
public async Task<IActionResult> ViewPointOfSale(string appId,
PosViewType? viewType = null,
[ModelBinder(typeof(InvariantDecimalModelBinder))] decimal? amount = null,
[ModelBinder(typeof(InvariantDecimalModelBinder))] decimal? tip = null,
[ModelBinder(typeof(InvariantDecimalModelBinder))] decimal? discount = null,
string email = null,
string orderId = null,
string notificationUrl = null,
@@ -197,7 +199,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
if (!settings.ShowCustomAmount && currentView != PosViewType.Cart && currentView != PosViewType.Light)
return NotFound();
price = amount;
price = 0.0m;
title = settings.Title;
//if cart IS enabled and we detect posdata that matches the cart system's, check inventory for the items
@@ -205,7 +207,6 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
AppService.TryParsePosCartItems(jposData, out cartItems))
{
choices = AppService.Parse(settings.Template, false);
var expectedMinimumAmount = 0m;
foreach (var cartItem in cartItems)
{
var itemChoice = choices.FirstOrDefault(c => c.Id == cartItem.Key);
@@ -229,13 +230,12 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
expectedCartItemPrice = itemChoice.Price ?? 0;
}
expectedMinimumAmount += expectedCartItemPrice * cartItem.Value;
}
if (expectedMinimumAmount > amount)
{
return RedirectToAction(nameof(ViewPointOfSale), new { appId });
price += expectedCartItemPrice * cartItem.Value;
}
if (discount is decimal d)
price -= price * d/100.0m;
if (tip is decimal t)
price += t;
}
}