mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Fix: Applying a discount in PoS with cart wasn't working (#5079)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user