Fix: Free items in the PoS were generating top-up invoices rather than settled invoices

This commit is contained in:
nicolas.dorier
2025-06-10 23:37:53 +09:00
committed by Andrew Camilleri (Kukks)
parent 886df54469
commit f52cb053fe
2 changed files with 13 additions and 2 deletions

View File

@@ -172,6 +172,8 @@ orange:
donation: donation:
price: 1.02 price: 1.02
custom: true custom: true
goodies:
price: 0
"; ";
vmpos.Currency = "EUR"; vmpos.Currency = "EUR";
vmpos.Template = AppService.SerializeTemplate(MigrationStartupTask.ParsePOSYML(vmpos.Template)); vmpos.Template = AppService.SerializeTemplate(MigrationStartupTask.ParsePOSYML(vmpos.Template));
@@ -182,7 +184,7 @@ donation:
Assert.Equal("EUR", vmview.CurrencyCode); Assert.Equal("EUR", vmview.CurrencyCode);
// apple shouldn't be available since we it's set to "disabled: true" above // apple shouldn't be available since we it's set to "disabled: true" above
Assert.Equal(2, vmview.Items.Length); Assert.Equal(3, vmview.Items.Length);
Assert.Equal("orange", vmview.Items[0].Title); Assert.Equal("orange", vmview.Items[0].Title);
Assert.Equal("donation", vmview.Items[1].Title); Assert.Equal("donation", vmview.Items[1].Title);
// orange is available // orange is available
@@ -192,6 +194,14 @@ donation:
Assert.IsType<NotFoundResult>(publicApps Assert.IsType<NotFoundResult>(publicApps
.ViewPointOfSale(app.Id, PosViewType.Cart, 0, choiceKey: "apple").Result); .ViewPointOfSale(app.Id, PosViewType.Cart, 0, choiceKey: "apple").Result);
var redirectToCheckout = Assert.IsType<RedirectToActionResult>(publicApps.ViewPointOfSale(app.Id, PosViewType.Cart, 0, choiceKey: "goodies").Result);
Assert.Equal("InvoiceReceipt", redirectToCheckout.ActionName);
var invoiceId = redirectToCheckout.RouteValues!["invoiceId"]!.ToString();
var client = await user.CreateClient();
var inv = await client.GetInvoice(user.StoreId, invoiceId);
Assert.Equal(0, inv.Amount);
Assert.NotEqual(InvoiceType.TopUp, inv.Type);
// List // List
appList = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps.ListApps(user.StoreId).Result).Model); appList = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps.ListApps(user.StoreId).Result).Model);
app = appList.Apps[0]; app = appList.Apps[0];

View File

@@ -232,6 +232,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
{ {
order.AddLine(new($"Custom Amount {i + 1}", 1, jposData.Amounts[i], settings.DefaultTaxRate)); order.AddLine(new($"Custom Amount {i + 1}", 1, jposData.Amounts[i], settings.DefaultTaxRate));
} }
foreach (var cartItem in jposData.Cart) foreach (var cartItem in jposData.Cart)
{ {
var itemChoice = choices.FirstOrDefault(item => item.Id == cartItem.Id); var itemChoice = choices.FirstOrDefault(item => item.Id == cartItem.Id);
@@ -322,7 +323,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
var receiptData = new PosReceiptData(); var receiptData = new PosReceiptData();
var summary = order.Calculate(); var summary = order.Calculate();
bool isTopup = summary.PriceTaxIncludedWithTips == 0 && currentView == PosViewType.Static; var isTopup = selectedChoices.FirstOrDefault().Price is null && currentView == PosViewType.Static;
if (!isTopup) if (!isTopup)
{ {
jposData.ItemsTotal = summary.ItemsTotal; jposData.ItemsTotal = summary.ItemsTotal;