Enqueue ventas para enviar a Toku
This commit is contained in:
@ -31,9 +31,9 @@ class Toku extends Controller
|
|||||||
];
|
];
|
||||||
try {
|
try {
|
||||||
$venta = $ventaService->getById($venta_id);
|
$venta = $ventaService->getById($venta_id);
|
||||||
$cuotas = $tokuService->sendCuotas($venta, $input['cuotas']);
|
$cuotas = $tokuService->sendCuotas($venta, $input['cuotas'] ?? []);
|
||||||
$output['cuotas'] = array_map(function($row) { return $row['cuota_id']; }, $cuotas);
|
$output['cuotas'] = array_map(function($row) { return $row['cuota_id']; }, $cuotas);
|
||||||
if (count($cuotas) < count($input['cuotas'])) {
|
if (count($cuotas) < count($input['cuotas'] ?? [])) {
|
||||||
$output['partial'] = true;
|
$output['partial'] = true;
|
||||||
} else {
|
} else {
|
||||||
$output['success'] = true;
|
$output['success'] = true;
|
||||||
@ -111,4 +111,21 @@ class Toku extends Controller
|
|||||||
$output = $tokuService->reset();
|
$output = $tokuService->reset();
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
public function enqueue(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
|
Service\Queue $queueService, Service\Venta\MediosPago\Toku $tokuService): ResponseInterface
|
||||||
|
{
|
||||||
|
$input = $request->getParsedBody();
|
||||||
|
$output = [
|
||||||
|
'input' => $input,
|
||||||
|
'success' => false
|
||||||
|
];
|
||||||
|
$queue = $tokuService->queue($input['venta_ids'] ?? []);
|
||||||
|
if (count($queue) > 0) {
|
||||||
|
foreach ($queue as $job) {
|
||||||
|
$queueService->enqueue($job);
|
||||||
|
}
|
||||||
|
$output['success'] = true;
|
||||||
|
}
|
||||||
|
return $this->withJson($response, $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,6 +261,21 @@ class Toku extends Ideal\Service
|
|||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
public function queue(array $venta_ids): array
|
||||||
|
{
|
||||||
|
$queues = [];
|
||||||
|
foreach ($venta_ids as $venta_id) {
|
||||||
|
if ($this->subscription->queue($venta_id)) {
|
||||||
|
$queues []= [
|
||||||
|
'type' => 'request',
|
||||||
|
'url' => "/api/external/toku/cuotas/{$venta_id}",
|
||||||
|
'method' => 'post',
|
||||||
|
'body' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $queues;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $request
|
* @param array $request
|
||||||
|
@ -94,6 +94,21 @@ class Subscription extends AbstractEndPoint
|
|||||||
}
|
}
|
||||||
return compact('existingSubscriptions', 'missingVentas');
|
return compact('existingSubscriptions', 'missingVentas');
|
||||||
}
|
}
|
||||||
|
public function queue(int $venta_id): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$venta = $this->ventaService->getById($venta_id);
|
||||||
|
} catch (Read $exception) {
|
||||||
|
$this->logger->warning($exception);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$subscription = $this->subscriptionRepsitory->fetchByVenta($venta_id);
|
||||||
|
return false;
|
||||||
|
} catch (EmptyResult) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function save(array $data): bool
|
public function save(array $data): bool
|
||||||
{
|
{
|
||||||
|
@ -17,6 +17,7 @@ return [
|
|||||||
'queue' => Incoviba\Command\Queue::class,
|
'queue' => Incoviba\Command\Queue::class,
|
||||||
'external:services' => Incoviba\Command\ExternalServices::class,
|
'external:services' => Incoviba\Command\ExternalServices::class,
|
||||||
'external:toku:reset' => Incoviba\Command\Ventas\MedioPagos\Toku\Reset::class,
|
'external:toku:reset' => Incoviba\Command\Ventas\MedioPagos\Toku\Reset::class,
|
||||||
|
'external:toku:enqueue' => Incoviba\Command\Ventas\MedioPagos\Toku\Enqueue::class
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
24
cli/src/Command/Ventas/MedioPagos/Toku/Enqueue.php
Normal file
24
cli/src/Command/Ventas/MedioPagos/Toku/Enqueue.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Command\Ventas\MedioPagos\Toku;
|
||||||
|
|
||||||
|
use Symfony\Component\Console;
|
||||||
|
use Incoviba\Common\Alias\Command;
|
||||||
|
|
||||||
|
#[Console\Attribute\AsCommand(name: 'external:toku:enqueue')]
|
||||||
|
class Enqueue extends Command
|
||||||
|
{
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this->addArgument('venta_ids', Console\Input\InputArgument::REQUIRED, 'Venta IDs separated by |');
|
||||||
|
}
|
||||||
|
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$this->logger->debug("Running {$this->getName()}");
|
||||||
|
$uri = '/api/external/toku/enqueue';
|
||||||
|
$output->writeln("POST {$uri}");
|
||||||
|
$body = ['venta_ids' => explode('|', $input->getArgument('venta_ids'))];
|
||||||
|
$response = $this->client->post($uri, ['json' => $body]);
|
||||||
|
$output->writeln("Response Code: {$response->getStatusCode()}");
|
||||||
|
return Console\Command\Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user