From 105179b4edbab8bda268948e03aced7d41f2a645 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Fri, 16 May 2025 16:35:17 -0400 Subject: [PATCH] Fixes de telefono y apellido de persona --- app/src/Controller/API/Ventas/MediosPago/Toku.php | 4 +++- app/src/Repository/Persona.php | 4 ++-- app/src/Service/Job.php | 12 +++++++----- app/src/Service/Persona.php | 2 +- app/src/Service/Venta/MediosPago/Toku.php | 8 +++++--- app/src/Service/Venta/MediosPago/Toku/Customer.php | 11 +++++++++++ 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/Controller/API/Ventas/MediosPago/Toku.php b/app/src/Controller/API/Ventas/MediosPago/Toku.php index 1119776..aea8228 100644 --- a/app/src/Controller/API/Ventas/MediosPago/Toku.php +++ b/app/src/Controller/API/Ventas/MediosPago/Toku.php @@ -38,7 +38,9 @@ class Toku extends Controller } else { $output['success'] = true; } - } catch (Read | InvalidResult) {} + } catch (Read | InvalidResult $exception) { + $this->logger->debug($exception); + } return $this->withJson($response, $output); } public function success(ServerRequestInterface $request, ResponseInterface $response, diff --git a/app/src/Repository/Persona.php b/app/src/Repository/Persona.php index ee70138..6ce69fc 100644 --- a/app/src/Repository/Persona.php +++ b/app/src/Repository/Persona.php @@ -19,8 +19,8 @@ class Persona extends Ideal\Repository public function create(?array $data = null): Model\Persona { $map = (new Implement\Repository\MapperParser(['rut', 'digito', 'nombres'])) - ->register('apellido_paterno', (new Implement\Repository\Mapper())->setProperty('apellidoPaterno')) - ->register('apellido_materno', (new Implement\Repository\Mapper())->setProperty('apellidoMaterno')) + ->register('apellido_paterno', (new Implement\Repository\Mapper())->setProperty('apellidoPaterno')->setDefault('')) + ->register('apellido_materno', (new Implement\Repository\Mapper())->setProperty('apellidoMaterno')->setDefault('')) ; return $this->parseData(new Model\Persona(), $data, $map); } diff --git a/app/src/Service/Job.php b/app/src/Service/Job.php index 7d74947..a02db33 100644 --- a/app/src/Service/Job.php +++ b/app/src/Service/Job.php @@ -2,9 +2,9 @@ namespace Incoviba\Service; use DateTimeImmutable; +use DateTimeZone; use InvalidArgumentException; use OutOfRangeException; -use PDOException; use Psr\Log\LoggerInterface; use Incoviba\Common\Ideal; use Incoviba\Common\Implement\Exception\EmptyRedis; @@ -65,9 +65,9 @@ class Job extends Ideal\Service */ public function add(array $configuration): Model\Job { - $now = (new DateTimeImmutable()); + $now = (new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'))); $data = [ - 'id' => $now->getTimestamp(), + 'id' => $now->format('Uu'), 'configuration' => $configuration, 'executed' => false, 'created_at' => $now->format('Y-m-d H:i:s'), @@ -129,8 +129,10 @@ class Job extends Ideal\Service */ protected function findJob(array $jobs, int $id): int { - $idx = array_find_key($jobs, fn($job) => $job['id'] === $id); - if ($idx === false) { + $idx = array_find_key($jobs, function($job) use ($id) { + return (int) $job['id'] === $id; + }); + if ($idx === null) { throw new EmptyResult("SELECT * FROM jobs WHERE id = ?"); } return $idx; diff --git a/app/src/Service/Persona.php b/app/src/Service/Persona.php index 3e285ce..d24034e 100644 --- a/app/src/Service/Persona.php +++ b/app/src/Service/Persona.php @@ -70,7 +70,7 @@ class Persona extends Ideal\Service $data['digito'] = $propietario->dv; $data['nombres'] = $propietario->nombres; $data['apellido_paterno'] = $propietario->apellidos['paterno']; - $data['apellido_materno'] = $propietario->apellidos['materno']; + $data['apellido_materno'] = $propietario->apellidos['materno'] ?? ''; $persona = $this->personaRepository->create($data); try { $persona = $this->personaRepository->save($persona); diff --git a/app/src/Service/Venta/MediosPago/Toku.php b/app/src/Service/Venta/MediosPago/Toku.php index d41c207..b1cb3bc 100644 --- a/app/src/Service/Venta/MediosPago/Toku.php +++ b/app/src/Service/Venta/MediosPago/Toku.php @@ -113,9 +113,11 @@ class Toku extends Ideal\Service $invoice = array_find($customerInvoices, function($invoiceRow) use ($cuota) { return $invoiceRow['invoice_external_id'] === $cuota->id; }); - $invoices []= $invoice; - $this->invoice->save($invoice); - continue; + if ($invoice !== null) { + $invoices []= $invoice; + $this->invoice->save($invoice); + continue; + } } try { $invoices []= $this->invoice->getById($cuota->id); diff --git a/app/src/Service/Venta/MediosPago/Toku/Customer.php b/app/src/Service/Venta/MediosPago/Toku/Customer.php index 82731f7..8d17133 100644 --- a/app/src/Service/Venta/MediosPago/Toku/Customer.php +++ b/app/src/Service/Venta/MediosPago/Toku/Customer.php @@ -72,6 +72,17 @@ class Customer extends AbstractEndPoint if ($ref === null) { continue; } + if ($ref === 'telefono') { + $value = $data[$ref]; + if ($value === '' or $value === null or $value === '0') { + continue; + } + if (!str_starts_with($value, '+')) { + $value = "+56{$value}"; + } + $params[$key] = $value; + continue; + } if (array_key_exists($ref, $data) and $data[$ref] !== '' and $data[$ref] !== null) { $params[$key] = $data[$ref]; }