Comando para resetear Toku

This commit is contained in:
Juan Pablo Vial
2025-05-27 18:17:56 -04:00
parent a9a10e012d
commit 892cdf324f
8 changed files with 114 additions and 0 deletions

View File

@ -102,4 +102,13 @@ class Toku extends Controller
}
return $this->withJson($response, $output);
}
public function reset(ServerRequestInterface $request, ResponseInterface $response,
Service\Venta\MediosPago\Toku $tokuService): ResponseInterface
{
if (!isset($_ENV['TOKU_ENV']) or strtolower($_ENV['TOKU_ENV']) !== 'sandbox') {
return $this->withJson($response);
}
$output = $tokuService->reset();
return $this->withJson($response, $output);
}
}

View File

@ -47,4 +47,11 @@ interface EndPoint
* @throws EmptyResponse
*/
public function delete(string $id): void;
/**
* @param array $skip
* @return array
* @throws InvalidResult
*/
public function reset(array $skip = []): array;
}

View File

@ -248,6 +248,19 @@ class Toku extends Ideal\Service
}
return $queues;
}
public function reset(array $skips = []): array
{
$output = [];
try {
$output['invoice'] = $this->invoice->reset($skips['invoice'] ?? []);
$output['subscription'] = $this->subscription->reset($skips['subscription'] ?? []);
$output['customer'] = $this->customer->reset($skips['customer'] ?? []);
} catch (InvalidResult $exception) {
$this->logger->warning($exception);
return [];
}
return $output;
}
/**
* @param array $request

View File

@ -2,6 +2,9 @@
namespace Incoviba\Service\Venta\MediosPago\Toku;
use Psr\Http\Client\ClientInterface;
use Incoviba\Common\Implement\Exception\EmptyResponse;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Model;
use Incoviba\Repository;
use Incoviba\Service\Venta\MediosPago\AbstractEndPoint;
@ -41,6 +44,26 @@ class Customer extends AbstractEndPoint
$request_uri = "/customer/{$id}";
$this->sendDelete($request_uri, [204], [404, 409]);
}
public function reset(array $skip = []): array
{
try {
$customers = $this->customerRepository->fetchAll();
$customers = array_filter($customers, function (Model\Venta\MediosPago\Toku\Customer $customer) use ($skip) {
return !in_array($customer->toku_id, $skip);
});
} catch (EmptyResult $exception) {
$this->logger->warning($exception);
return [];
}
foreach ($customers as $customer) {
try {
$this->delete($customer->toku_id);
} catch (EmptyResponse $exception) {
$this->logger->warning($exception, ['customer' => $customer]);
}
}
return $customers;
}
public function save(array $data): bool
{

View File

@ -51,6 +51,26 @@ class Invoice extends AbstractEndPoint
$request_uri = "/invoices/{$id}";
$this->sendDelete($request_uri, [204], [404, 409]);
}
public function reset(array $skip = []): array
{
try {
$invoices = $this->invoiceRepository->fetchAll();
$invoices = array_filter($invoices, function (Model\Venta\MediosPago\Toku\Invoice $invoice) use ($skip) {
return !in_array($invoice->toku_id, $skip);
});
} catch (EmptyResult $exception) {
$this->logger->warning($exception);
return [];
}
foreach ($invoices as $invoice) {
try {
$this->delete($invoice->toku_id);
} catch (EmptyResponse $exception) {
$this->logger->warning($exception, ['invoice' => $invoice]);
}
}
return $invoices;
}
/**
* @param string $customer_id

View File

@ -2,6 +2,7 @@
namespace Incoviba\Service\Venta\MediosPago\Toku;
use Psr\Http\Client\ClientInterface;
use Incoviba\Common\Implement\Exception\EmptyResponse;
use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Model\Venta;
@ -47,6 +48,26 @@ class Subscription extends AbstractEndPoint
$request_uri = "/subscriptions/{$id}";
$this->sendDelete($request_uri, [204], [404, 409]);
}
public function reset(array $skip = []): array
{
try {
$subscriptions = $this->subscriptionRepsitory->fetchAll();
$subscriptions = array_filter($subscriptions, function (Venta\MediosPago\Toku\Subscription $subscription) use ($skip) {
return !in_array($subscription->toku_id, $skip);
});
} catch (EmptyResult $exception) {
$this->logger->warning($exception);
return [];
}
foreach ($subscriptions as $subscription) {
try {
$this->delete($subscription->toku_id);
} catch (EmptyResponse $exception) {
$this->logger->warning($exception, ['subscription' => $subscription]);
}
}
return $subscriptions;
}
/**
* @return array

View File

@ -16,6 +16,7 @@ return [
'ventas:cuotas:vencer' => Incoviba\Command\Ventas\Cuotas\PorVencer::class,
'queue' => Incoviba\Command\Queue::class,
'external:services' => Incoviba\Command\ExternalServices::class,
'external:toku:reset' => Incoviba\Command\Ventas\MedioPagos\Toku\Reset::class,
];
}
];

View File

@ -0,0 +1,20 @@
<?php
namespace Incoviba\Command\Ventas\MedioPagos\Toku;
use Symfony\Component\Console;
use Incoviba\Common\Alias\Command;
#[Console\Attribute\AsCommand(name: 'external:toku:reset')]
class Reset extends Command
{
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
{
$this->logger->debug("Running {$this->getName()}");
$uri = '/api/external/toku/reset';
$output->writeln("GET {$uri}");
$response = $this->client->get($uri);
$output->writeln("Response Code: {$response->getStatusCode()}");
return self::SUCCESS;
}
}