Cambios de usos de env vars
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'urls' => function() {
|
'urls' => function(ContainerInterface $container) {
|
||||||
$urls = [
|
$urls = [
|
||||||
'base' => $_ENV['APP_URL'] ?? '',
|
'base' => $container->get('APP_URL') ?? '',
|
||||||
];
|
];
|
||||||
$urls['api'] = implode('/', [
|
$urls['api'] = implode('/', [
|
||||||
$urls['base'],
|
$urls['base'],
|
||||||
@ -18,21 +20,35 @@ return [
|
|||||||
]);
|
]);
|
||||||
return (object) $urls;
|
return (object) $urls;
|
||||||
},
|
},
|
||||||
'permittedPaths' => [
|
'apiUrls' => function(ContainerInterface $container) {
|
||||||
'/api',
|
$permittedPaths = [
|
||||||
'/api/',
|
'/api'
|
||||||
],
|
];
|
||||||
'simplePaths' => [
|
$simplePaths = [
|
||||||
'/api/login',
|
'/api/login',
|
||||||
'/api/login/',
|
'/api/logout'
|
||||||
'/api/logout'
|
];
|
||||||
],
|
function addTrailingSlash(array &$paths): array {
|
||||||
'externalPaths' => [
|
foreach ($paths as $path) {
|
||||||
'/api/external' => [
|
if (!in_array(rtrim($path, '/') . '/', $paths)) {
|
||||||
'/toku/success' => [
|
$paths[] = rtrim($path, '/') . '/';
|
||||||
'validator' => Incoviba\Service\Venta\MediosPago\Toku::class,
|
}
|
||||||
'token' => $_ENV['TOKU_TOKEN']
|
}
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
addTrailingSlash($permittedPaths);
|
||||||
|
addTrailingSlash($simplePaths);
|
||||||
|
return [
|
||||||
|
'permittedPaths' => $permittedPaths,
|
||||||
|
'simplePaths' => $simplePaths,
|
||||||
|
'externalPaths' => [
|
||||||
|
'/api/external' => [
|
||||||
|
'/toku/success' => [
|
||||||
|
'validator' => Incoviba\Service\Venta\MediosPago\Toku::class,
|
||||||
|
'token' => $container->get('TOKU_TOKEN')
|
||||||
|
]
|
||||||
|
],
|
||||||
]
|
]
|
||||||
],
|
];
|
||||||
]
|
}
|
||||||
];
|
];
|
||||||
|
@ -18,9 +18,7 @@ return [
|
|||||||
$container->get(Incoviba\Service\API::class),
|
$container->get(Incoviba\Service\API::class),
|
||||||
$container->get(Incoviba\Service\Login::class),
|
$container->get(Incoviba\Service\Login::class),
|
||||||
$container->get('API_KEY'),
|
$container->get('API_KEY'),
|
||||||
$container->get('permittedPaths'),
|
$container->get('apiUrls'),
|
||||||
$container->get('simplePaths'),
|
|
||||||
$container->get('externalPaths'),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Incoviba\Middleware\NotFound::class => function(ContainerInterface $container) {
|
Incoviba\Middleware\NotFound::class => function(ContainerInterface $container) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Controller\API\Ventas\MediosPago;
|
namespace Incoviba\Controller\API\Ventas\MediosPago;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Http\Message\ResponseFactoryInterface;
|
use Psr\Http\Message\ResponseFactoryInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@ -105,9 +106,9 @@ class Toku extends Controller
|
|||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
public function reset(ServerRequestInterface $request, ResponseInterface $response,
|
public function reset(ServerRequestInterface $request, ResponseInterface $response,
|
||||||
Service\Venta\MediosPago\Toku $tokuService): ResponseInterface
|
Service\Venta\MediosPago\Toku $tokuService, ContainerInterface $container): ResponseInterface
|
||||||
{
|
{
|
||||||
if (!isset($_ENV['TOKU_ENV']) or strtolower($_ENV['TOKU_ENV']) !== 'sandbox') {
|
if (!$container->has('TOKU_ENV') or strtolower($container->get('TOKU_ENV')) !== 'sandbox') {
|
||||||
return $this->withJson($response);
|
return $this->withJson($response);
|
||||||
}
|
}
|
||||||
$input = $request->getParsedBody();
|
$input = $request->getParsedBody();
|
||||||
|
@ -16,9 +16,16 @@ class API
|
|||||||
protected Service\API $apiService,
|
protected Service\API $apiService,
|
||||||
protected Service\Login $loginService,
|
protected Service\Login $loginService,
|
||||||
protected string $key,
|
protected string $key,
|
||||||
protected array $permittedPaths,
|
array $apiUrls)
|
||||||
protected array $simplePaths,
|
{
|
||||||
protected array $externalPaths) {}
|
$this->permittedPaths = $apiUrls['permittedPaths'];
|
||||||
|
$this->simplePaths = $apiUrls['simplePaths'];
|
||||||
|
$this->externalPaths = $apiUrls['externalPaths'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected array $permittedPaths;
|
||||||
|
protected array $simplePaths;
|
||||||
|
protected array $externalPaths;
|
||||||
|
|
||||||
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||||
{
|
{
|
||||||
@ -27,7 +34,10 @@ class API
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$key = $this->apiService->getKey($request);
|
$key = $this->apiService->getKey($request);
|
||||||
} catch (MissingAuthorizationHeader) {
|
} catch (MissingAuthorizationHeader $exception) {
|
||||||
|
$this->logger->warning($exception, [
|
||||||
|
'headers' => $request->getHeaders()
|
||||||
|
]);
|
||||||
return $this->responseFactory->createResponse(401);
|
return $this->responseFactory->createResponse(401);
|
||||||
}
|
}
|
||||||
if ($this->validateSimpleKey($request, $key)) {
|
if ($this->validateSimpleKey($request, $key)) {
|
||||||
|
Reference in New Issue
Block a user