|
|
@@ -270,6 +270,9 @@ class TshieldService
|
|
|
}
|
|
|
|
|
|
$defaultAdditional = [];
|
|
|
+ if (isset($analysisPayload['birthdate'])) {
|
|
|
+ $analysisPayload['birthdate'] = $this->normalizeBirthdate($analysisPayload['birthdate']);
|
|
|
+ }
|
|
|
$fieldValues = [
|
|
|
'name' => $analysisPayload['name'] ?? null,
|
|
|
'document' => $analysisPayload['document'] ?? null,
|
|
|
@@ -311,6 +314,60 @@ class TshieldService
|
|
|
return $payload;
|
|
|
}
|
|
|
|
|
|
+ private function normalizeBirthdate($value): ?string
|
|
|
+ {
|
|
|
+ if ($value === null || $value === '') {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_numeric($value)) {
|
|
|
+ $numeric = (string)$value;
|
|
|
+ $timestamp = (int)$value;
|
|
|
+
|
|
|
+ if ($timestamp > 0) {
|
|
|
+ if (strlen($numeric) === 8) {
|
|
|
+ $formatted = \DateTimeImmutable::createFromFormat('Ymd', $numeric);
|
|
|
+ if ($formatted) {
|
|
|
+ return $formatted->format('Y-m-d');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strlen($numeric) >= 13) {
|
|
|
+ $timestamp = (int) floor($timestamp / 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($timestamp >= 1000000000) {
|
|
|
+ $dt = (new \DateTimeImmutable())->setTimestamp($timestamp);
|
|
|
+ return $dt->format('Y-m-d');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_string($value)) {
|
|
|
+ $value = trim($value);
|
|
|
+
|
|
|
+ if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (preg_match('/^\d{8}$/', $value)) {
|
|
|
+ $formatted = \DateTimeImmutable::createFromFormat('Ymd', $value);
|
|
|
+ if ($formatted) {
|
|
|
+ return $formatted->format('Y-m-d');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (['d/m/Y', 'd-m-Y', 'Y/m/d', 'Y.m.d'] as $fmt) {
|
|
|
+ $formatted = \DateTimeImmutable::createFromFormat($fmt, $value);
|
|
|
+ if ($formatted) {
|
|
|
+ return $formatted->format('Y-m-d');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private function injectDefaults(array $payload, string $validationId): array
|
|
|
{
|
|
|
if (empty($payload['client_validation_id'])) {
|