Parse body correctly and test fill
This commit is contained in:
@ -9,6 +9,7 @@ use Incoviba\Controller\API\withJson;
|
|||||||
use Incoviba\Exception\InvalidResult;
|
use Incoviba\Exception\InvalidResult;
|
||||||
use Incoviba\Exception\ServiceAction\Read;
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Incoviba\Model;
|
||||||
|
|
||||||
class Toku extends Controller
|
class Toku extends Controller
|
||||||
{
|
{
|
||||||
@ -18,6 +19,9 @@ class Toku extends Controller
|
|||||||
Service\Venta\MediosPago\Toku $tokuService, Service\Venta $ventaService, int $venta_id): ResponseInterface
|
Service\Venta\MediosPago\Toku $tokuService, Service\Venta $ventaService, int $venta_id): ResponseInterface
|
||||||
{
|
{
|
||||||
$input = $request->getParsedBody();
|
$input = $request->getParsedBody();
|
||||||
|
if ($input === null) {
|
||||||
|
$input = json_decode($request->getBody()->getContents(), true);
|
||||||
|
}
|
||||||
$output = [
|
$output = [
|
||||||
'input' => $input,
|
'input' => $input,
|
||||||
'venta_id' => $venta_id,
|
'venta_id' => $venta_id,
|
||||||
@ -60,4 +64,35 @@ class Toku extends Controller
|
|||||||
return $responseFactory->createResponse($exception->getCode(), $message);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user