mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
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:
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Fido2;
|
||||
@@ -12,11 +13,9 @@ using BTCPayServer.Fido2.Models;
|
||||
using BTCPayServer.Payments;
|
||||
using BTCPayServer.Payments.Bitcoin;
|
||||
using BTCPayServer.Payments.Lightning;
|
||||
using BTCPayServer.PayoutProcessors;
|
||||
using BTCPayServer.Payouts;
|
||||
using BTCPayServer.Plugins.Crowdfund;
|
||||
using BTCPayServer.Plugins.PointOfSale;
|
||||
using BTCPayServer.Plugins.PointOfSale.Models;
|
||||
using BTCPayServer.Services;
|
||||
using BTCPayServer.Services.Apps;
|
||||
using BTCPayServer.Services.Invoices;
|
||||
@@ -398,9 +397,10 @@ namespace BTCPayServer.Hosting
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
}
|
||||
public static ViewPointOfSaleViewModel.Item[] ParsePOSYML(string yaml)
|
||||
|
||||
public static AppItem[] ParsePOSYML(string yaml)
|
||||
{
|
||||
var items = new List<ViewPointOfSaleViewModel.Item>();
|
||||
var items = new List<AppItem>();
|
||||
var stream = new YamlStream();
|
||||
if (string.IsNullOrEmpty(yaml))
|
||||
return items.ToArray();
|
||||
@@ -417,11 +417,11 @@ namespace BTCPayServer.Hosting
|
||||
continue;
|
||||
}
|
||||
|
||||
var currentItem = new ViewPointOfSaleViewModel.Item
|
||||
var currentItem = new AppItem
|
||||
{
|
||||
Id = trimmedKey,
|
||||
Title = trimmedKey,
|
||||
PriceType = ViewPointOfSaleViewModel.ItemPriceType.Fixed
|
||||
PriceType = AppItemPriceType.Fixed
|
||||
};
|
||||
var itemSpecs = (YamlMappingNode)posItem.Value;
|
||||
foreach (var spec in itemSpecs)
|
||||
@@ -446,12 +446,6 @@ namespace BTCPayServer.Hosting
|
||||
case "image":
|
||||
currentItem.Image = scalarValue?.Value;
|
||||
break;
|
||||
case "payment_methods" when spec.Value is YamlSequenceNode pmSequenceNode:
|
||||
|
||||
currentItem.PaymentMethods = pmSequenceNode.Children
|
||||
.Select(node => (node as YamlScalarNode)?.Value?.Trim())
|
||||
.Where(node => !string.IsNullOrEmpty(node)).ToArray();
|
||||
break;
|
||||
case "price_type":
|
||||
case "custom":
|
||||
if (bool.TryParse(scalarValue?.Value, out var customBoolValue))
|
||||
@@ -459,15 +453,15 @@ namespace BTCPayServer.Hosting
|
||||
if (customBoolValue)
|
||||
{
|
||||
currentItem.PriceType = currentItem.Price is null or 0
|
||||
? ViewPointOfSaleViewModel.ItemPriceType.Topup
|
||||
: ViewPointOfSaleViewModel.ItemPriceType.Minimum;
|
||||
? AppItemPriceType.Topup
|
||||
: AppItemPriceType.Minimum;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentItem.PriceType = ViewPointOfSaleViewModel.ItemPriceType.Fixed;
|
||||
currentItem.PriceType = AppItemPriceType.Fixed;
|
||||
}
|
||||
}
|
||||
else if (Enum.TryParse<ViewPointOfSaleViewModel.ItemPriceType>(scalarValue?.Value, true,
|
||||
else if (Enum.TryParse<AppItemPriceType>(scalarValue?.Value, true,
|
||||
out var customPriceType))
|
||||
{
|
||||
currentItem.PriceType = customPriceType;
|
||||
|
||||
Reference in New Issue
Block a user