Opcion de enviar update a los servicios externos

This commit is contained in:
Juan Pablo Vial
2025-05-16 19:14:20 -04:00
parent 105179b4ed
commit b7c5e4ebc3
9 changed files with 44 additions and 8 deletions

View File

@ -11,5 +11,6 @@ $app->group('/external', function($app) {
} }
$app->group('/services', function($app) { $app->group('/services', function($app) {
$app->get('/check[/]', [External::class, 'check']); $app->get('/check[/]', [External::class, 'check']);
$app->get('/update[/]', [External::class, 'update']);
}); });
}); });

View File

@ -17,4 +17,11 @@ class External extends Ideal\Controller
} }
return $response->withStatus(409); return $response->withStatus(409);
} }
public function update(ServerRequestInterface $request, ResponseInterface $response, Service\External $externalService): ResponseInterface
{
if ($externalService->check(true)) {
return $response->withStatus(204);
}
return $response->withStatus(409);
}
} }

View File

@ -24,7 +24,7 @@ class External extends Ideal\Service
return $this; return $this;
} }
public function check(): bool public function check(bool $update = false): bool
{ {
$errors = []; $errors = [];
foreach ($this->externalServices as $externalService) { foreach ($this->externalServices as $externalService) {
@ -36,6 +36,9 @@ class External extends Ideal\Service
'service' => get_class($externalService), 'service' => get_class($externalService),
'action' => 'check', 'action' => 'check',
]; ];
if ($update) {
$queueData['args'] = ['update' => true];
}
if (!$this->queueService->enqueue($queueData)) { if (!$this->queueService->enqueue($queueData)) {
$errors []= get_class($externalService); $errors []= get_class($externalService);
} }

View File

@ -214,7 +214,9 @@ class Toku extends Ideal\Service
'telefono' => $propietario->datos?->telefono ?? '' 'telefono' => $propietario->datos?->telefono ?? ''
]; ];
$this->customer->edit($customer['toku_id'], $editData); $this->customer->edit($customer['toku_id'], $editData);
} catch (EmptyResponse) {} } catch (EmptyResponse $exception) {
$this->logger->warning($exception);
}
foreach ($cuotas as $cuota) { foreach ($cuotas as $cuota) {
try { try {
$invoice = $this->invoice->getById($cuota->id); $invoice = $this->invoice->getById($cuota->id);
@ -222,7 +224,8 @@ class Toku extends Ideal\Service
'customer' => $customer['toku_id'], 'customer' => $customer['toku_id'],
'product_id' => $subscription->venta->id, 'product_id' => $subscription->venta->id,
'subscription' => $subscription->toku_id, 'subscription' => $subscription->toku_id,
'cuota' => $cuota 'cuota' => $cuota,
'venta' => $subscription->venta
]; ];
try { try {
$this->invoice->edit($invoice['toku_id'], $editData); $this->invoice->edit($invoice['toku_id'], $editData);
@ -232,7 +235,8 @@ class Toku extends Ideal\Service
'customer' => $customer['toku_id'], 'customer' => $customer['toku_id'],
'product_id' => $subscription->venta->id, 'product_id' => $subscription->venta->id,
'subscription' => $subscription->toku_id, 'subscription' => $subscription->toku_id,
'cuota' => $cuota 'cuota' => $cuota,
'venta' => $subscription->venta
]; ];
try { try {
$this->invoice->add($invoiceData); $this->invoice->add($invoiceData);

View File

@ -17,7 +17,8 @@ class Invoice extends AbstractEndPoint
{ {
public function __construct(ClientInterface $client, public function __construct(ClientInterface $client,
protected Repository\Venta\MediosPago\Toku\Invoice $invoiceRepository, protected Repository\Venta\MediosPago\Toku\Invoice $invoiceRepository,
protected Pago $pagoService, protected UF $ufService) protected Pago $pagoService,
protected UF $ufService)
{ {
parent::__construct($client); parent::__construct($client);
} }

View File

@ -59,6 +59,9 @@ class Subscription extends AbstractEndPoint
$existingSubscriptions = []; $existingSubscriptions = [];
try { try {
$existingSubscriptions = $this->subscriptionRepsitory->fetchByVentas($ids); $existingSubscriptions = $this->subscriptionRepsitory->fetchByVentas($ids);
array_walk($existingSubscriptions, function(&$subscription) {
$subscription->venta = $this->ventaService->getById($subscription->venta->id);
});
} catch (EmptyResult) {} } catch (EmptyResult) {}
if (count($existingSubscriptions) === 0) { if (count($existingSubscriptions) === 0) {
$missingVentas = $ventas; $missingVentas = $ventas;

View File

@ -37,7 +37,12 @@ class CheckExternal extends Ideal\Service implements Service\Worker
if (!isset($this->queueService)) { if (!isset($this->queueService)) {
$this->queueService = $this->container->get(Service\Queue::class); $this->queueService = $this->container->get(Service\Queue::class);
} }
$queues = $service->{$method}(); if (isset($configuration['args'])) {
$args = $configuration['args'];
$queues = call_user_func_array([$service, $method], $args);
} else {
$queues = call_user_func([$service, $method]);
}
foreach ($queues as $queue) { foreach ($queues as $queue) {
$this->queueService->enqueue($queue); $this->queueService->enqueue($queue);
} }

View File

@ -2,6 +2,7 @@
return [ return [
'commands' => function() { 'commands' => function() {
return [ return [
'loop' => Incoviba\Command\BaseLoop::class,
'comunas' => Incoviba\Command\Comunas::class, 'comunas' => Incoviba\Command\Comunas::class,
'contabilidad:cartolas:update' => Incoviba\Command\Contabilidad\Cartolas\Update::class, 'contabilidad:cartolas:update' => Incoviba\Command\Contabilidad\Cartolas\Update::class,
'money:ipc' => Incoviba\Command\Money\IPC::class, 'money:ipc' => Incoviba\Command\Money\IPC::class,
@ -14,8 +15,7 @@ return [
'ventas:cuotas:pendientes' => Incoviba\Command\Ventas\Cuotas\Pendientes::class, 'ventas:cuotas:pendientes' => Incoviba\Command\Ventas\Cuotas\Pendientes::class,
'ventas:cuotas:vencer' => Incoviba\Command\Ventas\Cuotas\PorVencer::class, 'ventas:cuotas:vencer' => Incoviba\Command\Ventas\Cuotas\PorVencer::class,
'queue' => Incoviba\Command\Queue::class, 'queue' => Incoviba\Command\Queue::class,
'loop' => Incoviba\Command\BaseLoop::class, 'external:services' => Incoviba\Command\ExternalServices::class,
'external:services' => Incoviba\Command\ExternalServices::class
]; ];
} }
]; ];

View File

@ -10,9 +10,21 @@ use Incoviba\Common\Alias;
)] )]
class ExternalServices extends Alias\Command class ExternalServices extends Alias\Command
{ {
protected function configure()
{
$this->addOption('update', 'u', Console\Input\InputOption::VALUE_NONE, 'Update');
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
{ {
$update = $input->getOption('update');
$url = '/api/external/services/check'; $url = '/api/external/services/check';
if ($update) {
$url = '/api/external/services/update';
}
$output->writeln("GET {$url}"); $output->writeln("GET {$url}");
$response = $this->client->get($url); $response = $this->client->get($url);
$output->writeln("Response Code: {$response->getStatusCode()}"); $output->writeln("Response Code: {$response->getStatusCode()}");