From c0024a4a63e9680fb306acf19a7e89fac9252d21 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Tue, 13 May 2025 20:03:20 -0400 Subject: [PATCH] Parse body correctly and test fill --- .../Controller/API/Ventas/MediosPago/Toku.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/src/Controller/API/Ventas/MediosPago/Toku.php b/app/src/Controller/API/Ventas/MediosPago/Toku.php index 8e1ee17..046b1a2 100644 --- a/app/src/Controller/API/Ventas/MediosPago/Toku.php +++ b/app/src/Controller/API/Ventas/MediosPago/Toku.php @@ -9,6 +9,7 @@ use Incoviba\Controller\API\withJson; use Incoviba\Exception\InvalidResult; use Incoviba\Exception\ServiceAction\Read; use Incoviba\Service; +use Incoviba\Model; class Toku extends Controller { @@ -18,6 +19,9 @@ class Toku extends Controller Service\Venta\MediosPago\Toku $tokuService, Service\Venta $ventaService, int $venta_id): ResponseInterface { $input = $request->getParsedBody(); + if ($input === null) { + $input = json_decode($request->getBody()->getContents(), true); + } $output = [ 'input' => $input, 'venta_id' => $venta_id, @@ -60,4 +64,35 @@ class Toku extends Controller return $responseFactory->createResponse($exception->getCode(), $message); } } + + public function test(ServerRequestInterface $request, ResponseInterface $response, + Service\Venta $ventaService, Service\Queue $queueService): ResponseInterface + { + $output = [ + 'success' => false, + 'queue' => [] + ]; + try { + $ventas = $ventaService->getAllWithCuotaPending(); + foreach ($ventas as $venta) { + $cuotas = $venta->formaPago()->pie->cuotas(); + if (count($cuotas) === 0) { + continue; + } + $queueData = [ + 'type' => 'request', + 'url' => "/api/external/toku/cuotas/{$venta->id}", + 'method' => 'post', + 'body' => ['cuotas' => array_map(function(Model\Venta\Cuota $cuota) {return $cuota->id;}, $cuotas)] + ]; + $output['queue'] []= $queueData; + $queueService->enqueue($queueData); + } + $output['success'] = true; + } catch (Read) { + $response->withStatus(404); + return $response; + } + return $this->withJson($response, $output); + } }