5using System.Threading.Tasks;
6using System.Globalization;
39 private static readonly Dictionary<string, IKycTransform> transforms =
new(StringComparer.OrdinalIgnoreCase);
40 private static bool initialized;
42 private static void EnsureInit()
49 Register(
new TrimTransform());
50 Register(
new UppercaseTransform());
51 Register(
new LowercaseTransform());
52 Register(
new YearTransform());
53 Register(
new MonthTransform());
54 Register(
new DayTransform());
55 Register(
new PersonalNumberNormalizeTransform());
60 transforms[transform.
Name] = transform;
63 public static bool TryGet(
string name, out
IKycTransform transform)
66 return transforms.TryGetValue(name, out transform!);
70 #region Built-in transforms
74 protected SimpleFuncTransform(
string name) => this.Name = name;
75 public string Name {
get; }
79 internal sealed
class TrimTransform : SimpleFuncTransform
81 public TrimTransform() : base(
"trim") { }
82 public override Task<string> ApplyAsync(
ObservableKycField field,
KycProcess process,
string currentValue, CancellationToken ct) => Task.FromResult(currentValue.Trim());
85 internal sealed
class UppercaseTransform : SimpleFuncTransform
87 public UppercaseTransform() : base(
"uppercase") { }
88 public override Task<string> ApplyAsync(
ObservableKycField field,
KycProcess process,
string currentValue, CancellationToken ct) => Task.FromResult(currentValue.ToUpperInvariant());
91 internal sealed
class LowercaseTransform : SimpleFuncTransform
93 public LowercaseTransform() : base(
"lowercase") { }
94 public override Task<string> ApplyAsync(
ObservableKycField field,
KycProcess process,
string currentValue, CancellationToken ct) => Task.FromResult(currentValue.ToLowerInvariant());
97 internal sealed
class YearTransform : SimpleFuncTransform
99 public YearTransform() : base(
"year") { }
102 return Task.FromResult(DateTime.TryParse(currentValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt) ? dt.Year.ToString(CultureInfo.InvariantCulture) :
string.Empty);
106 internal sealed
class MonthTransform : SimpleFuncTransform
108 public MonthTransform() : base(
"month") { }
111 return Task.FromResult(DateTime.TryParse(currentValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt) ? dt.Month.ToString(CultureInfo.InvariantCulture) :
string.Empty);
115 internal sealed
class DayTransform : SimpleFuncTransform
117 public DayTransform() : base(
"day") { }
120 return Task.FromResult(DateTime.TryParse(currentValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt) ? dt.Day.ToString(CultureInfo.InvariantCulture) :
string.Empty);
124 internal sealed
class PersonalNumberNormalizeTransform : SimpleFuncTransform
126 public PersonalNumberNormalizeTransform() : base(
"personalNumberNormalize") { }
129 if (
string.IsNullOrWhiteSpace(currentValue))
132 string countryCode =
string.Empty;
136 string? fromValues = process.
Values.Where(kv => kv.Key.Contains(
"country", StringComparison.OrdinalIgnoreCase))
137 .Select(kv => kv.Value)
138 .FirstOrDefault(v => !
string.IsNullOrEmpty(v));
139 if (!
string.IsNullOrEmpty(fromValues))
140 countryCode = fromValues!;
141 if (
string.IsNullOrEmpty(countryCode))
142 countryCode = ServiceRef.TagProfile.SelectedCountry ??
ServiceRef.
TagProfile.LegalIdentity?.GetPersonalInformation().Country ??
string.Empty;
146 countryCode =
string.Empty;
149 if (
string.IsNullOrEmpty(countryCode))
Personal Number Schemes available in different countries.
static async Task< NumberInformation > Validate(string CountryCode, string PersonalNumber)
Checks if a personal number is valid, in accordance with registered personal number schemes.
Represents a parsed KYC process with pages, fields, and current values.
IDictionary< string, string?> Values
Gets a modifiable dictionary of field values keyed by field identifier.
The base KYC field model. Use as-is for generic fields, or subclass for custom logic.
Base class that references services in the app.
static ILogService LogService
Log service.
static ITagProfile TagProfile
TAG Profile service.