Refactoring: Move AppItem to Client lib and use the class for item list (#6258)

* Refactoring: Move AppItem to Client lib and use the class for item list

This makes it available for the app, which would otherwise have to replicate the model. Also uses the proper class for the item/perk list of the app models.

* Remove unused app item payment methods property

* Do not ignore nullable values in JSON

* Revert to use Newtonsoft types
This commit is contained in:
d11n
2024-11-05 03:49:30 +01:00
committed by GitHub
parent 225264a283
commit ff79a31066
22 changed files with 219 additions and 245 deletions

View File

@@ -176,9 +176,9 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
string title;
decimal? price;
Dictionary<string, InvoiceSupportedTransactionCurrency> paymentMethods = null;
ViewPointOfSaleViewModel.Item choice = null;
AppItem choice = null;
List<PosCartItem> cartItems = null;
ViewPointOfSaleViewModel.Item[] choices = null;
AppItem[] choices = null;
if (!string.IsNullOrEmpty(choiceKey))
{
choices = AppService.Parse(settings.Template, false);
@@ -186,7 +186,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
if (choice == null)
return NotFound();
title = choice.Title;
if (choice.PriceType == ViewPointOfSaleViewModel.ItemPriceType.Topup)
if (choice.PriceType == AppItemPriceType.Topup)
{
price = null;
}
@@ -201,12 +201,6 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
{
return RedirectToAction(nameof(ViewPointOfSale), new { appId });
}
if (choice?.PaymentMethods?.Any() is true)
{
paymentMethods = choice?.PaymentMethods.ToDictionary(s => s,
s => new InvoiceSupportedTransactionCurrency() { Enabled = true });
}
}
else
{
@@ -239,7 +233,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
}
}
var expectedCartItemPrice = itemChoice.PriceType != ViewPointOfSaleViewModel.ItemPriceType.Topup
var expectedCartItemPrice = itemChoice.PriceType != AppItemPriceType.Topup
? itemChoice.Price ?? 0
: 0;
@@ -373,7 +367,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
var singlePrice = _displayFormatter.Currency(cartItem.Price, settings.Currency, DisplayFormatter.CurrencyFormat.Symbol);
var totalPrice = _displayFormatter.Currency(cartItem.Price * cartItem.Count, settings.Currency, DisplayFormatter.CurrencyFormat.Symbol);
var ident = selectedChoice.Title ?? selectedChoice.Id;
var key = selectedChoice.PriceType == ViewPointOfSaleViewModel.ItemPriceType.Fixed ? ident : $"{ident} ({singlePrice})";
var key = selectedChoice.PriceType == AppItemPriceType.Fixed ? ident : $"{ident} ({singlePrice})";
cartData.Add(key, $"{cartItem.Count} x {singlePrice} = {totalPrice}");
}