Comando para resetear Toku
This commit is contained in:
@ -102,4 +102,13 @@ class Toku extends Controller
|
|||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,4 +47,11 @@ interface EndPoint
|
|||||||
* @throws EmptyResponse
|
* @throws EmptyResponse
|
||||||
*/
|
*/
|
||||||
public function delete(string $id): void;
|
public function delete(string $id): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $skip
|
||||||
|
* @return array
|
||||||
|
* @throws InvalidResult
|
||||||
|
*/
|
||||||
|
public function reset(array $skip = []): array;
|
||||||
}
|
}
|
||||||
|
@ -248,6 +248,19 @@ class Toku extends Ideal\Service
|
|||||||
}
|
}
|
||||||
return $queues;
|
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
|
* @param array $request
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
namespace Incoviba\Service\Venta\MediosPago\Toku;
|
namespace Incoviba\Service\Venta\MediosPago\Toku;
|
||||||
|
|
||||||
use Psr\Http\Client\ClientInterface;
|
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\Repository;
|
||||||
use Incoviba\Service\Venta\MediosPago\AbstractEndPoint;
|
use Incoviba\Service\Venta\MediosPago\AbstractEndPoint;
|
||||||
|
|
||||||
@ -41,6 +44,26 @@ class Customer extends AbstractEndPoint
|
|||||||
$request_uri = "/customer/{$id}";
|
$request_uri = "/customer/{$id}";
|
||||||
$this->sendDelete($request_uri, [204], [404, 409]);
|
$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
|
public function save(array $data): bool
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,26 @@ class Invoice extends AbstractEndPoint
|
|||||||
$request_uri = "/invoices/{$id}";
|
$request_uri = "/invoices/{$id}";
|
||||||
$this->sendDelete($request_uri, [204], [404, 409]);
|
$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
|
* @param string $customer_id
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Service\Venta\MediosPago\Toku;
|
namespace Incoviba\Service\Venta\MediosPago\Toku;
|
||||||
|
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
|
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Exception\ServiceAction\Read;
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Incoviba\Model\Venta;
|
use Incoviba\Model\Venta;
|
||||||
@ -47,6 +48,26 @@ class Subscription extends AbstractEndPoint
|
|||||||
$request_uri = "/subscriptions/{$id}";
|
$request_uri = "/subscriptions/{$id}";
|
||||||
$this->sendDelete($request_uri, [204], [404, 409]);
|
$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
|
* @return array
|
||||||
|
@ -16,6 +16,7 @@ return [
|
|||||||
'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,
|
||||||
'external:services' => Incoviba\Command\ExternalServices::class,
|
'external:services' => Incoviba\Command\ExternalServices::class,
|
||||||
|
'external:toku:reset' => Incoviba\Command\Ventas\MedioPagos\Toku\Reset::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
20
cli/src/Command/Ventas/MedioPagos/Toku/Reset.php
Normal file
20
cli/src/Command/Ventas/MedioPagos/Toku/Reset.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user