diff --git a/Elwig/Helpers/Billing/BillingData.cs b/Elwig/Helpers/Billing/BillingData.cs index f5ea89b..80c83d5 100644 --- a/Elwig/Helpers/Billing/BillingData.cs +++ b/Elwig/Helpers/Billing/BillingData.cs @@ -145,5 +145,36 @@ namespace Elwig.Helpers.Billing { } return dict; } + + protected static Dictionary GetSelection(JsonObject data, IEnumerable attributeVariants) { + Dictionary dict; + if (data["default"] is JsonValue def) { + dict = attributeVariants.ToDictionary(e => e, _ => def); + } else { + dict = []; + } + + var variants = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length == 2); + var attributes = data.Where(p => p.Key.StartsWith('/')); + var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2 && p.Key != "default"); + foreach (var (idx, v) in variants) { + var curve = v?.AsValue() ?? throw new InvalidOperationException(); + foreach (var i in attributeVariants.Where(e => e.StartsWith(idx[..^1]))) { + dict[i] = curve; + } + } + foreach (var (idx, v) in attributes) { + var curve = v?.AsValue() ?? throw new InvalidOperationException(); + foreach (var i in attributeVariants.Where(e => e[2..] == idx[1..])) { + dict[i] = curve; + } + } + foreach (var (idx, v) in others) { + var curve = v?.AsValue() ?? throw new InvalidOperationException(); + dict[idx.Replace("/", "")] = curve; + } + + return dict; + } } } diff --git a/Elwig/Helpers/Billing/PaymentBillingData.cs b/Elwig/Helpers/Billing/PaymentBillingData.cs index bf45ef1..ec80cbd 100644 --- a/Elwig/Helpers/Billing/PaymentBillingData.cs +++ b/Elwig/Helpers/Billing/PaymentBillingData.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Text.Json.Nodes; @@ -27,35 +26,7 @@ namespace Elwig.Helpers.Billing { } private Dictionary GetData(JsonObject data) { - Dictionary dict; - if (data["default"] is JsonValue def) { - var c = LookupCurve(def); - dict = AttributeVariants.ToDictionary(e => e, _ => c); - } else { - dict = []; - } - - var variants = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length == 2); - var attributes = data.Where(p => p.Key.StartsWith('/')); - var others = data.Where(p => !p.Key.StartsWith('/') && p.Key.Length > 2); - foreach (var (idx, v) in variants) { - var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException()); - foreach (var i in AttributeVariants.Where(e => e.StartsWith(idx[..^1]))) { - dict[i] = curve; - } - } - foreach (var (idx, v) in attributes) { - var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException()); - foreach (var i in AttributeVariants.Where(e => e[2..] == idx[1..])) { - dict[i] = curve; - } - } - foreach (var (idx, v) in others) { - var curve = LookupCurve(v?.AsValue() ?? throw new InvalidOperationException()); - dict[idx.Replace("/", "")] = curve; - } - - return dict; + return GetSelection(data, AttributeVariants).ToDictionary(e => e.Key, e => LookupCurve(e.Value)); } protected Dictionary GetPaymentData() {