Validate with service
This commit is contained in:
@ -30,7 +30,7 @@ return [
|
|||||||
'externalPaths' => [
|
'externalPaths' => [
|
||||||
'/api/external' => [
|
'/api/external' => [
|
||||||
'/toku/success' => [
|
'/toku/success' => [
|
||||||
'header' => 'x-api-key',
|
'validator' => Incoviba\Service\Venta\MediosPago\Toku::class,
|
||||||
'token' => $_ENV['TOKU_TOKEN']
|
'token' => $_ENV['TOKU_TOKEN']
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -86,6 +86,10 @@ class API
|
|||||||
protected function validateExternalKey(ServerRequestInterface $request, $basePath, $subPath): bool
|
protected function validateExternalKey(ServerRequestInterface $request, $basePath, $subPath): bool
|
||||||
{
|
{
|
||||||
$data = $this->externalPaths[$basePath][$subPath];
|
$data = $this->externalPaths[$basePath][$subPath];
|
||||||
|
if (isset($data['validator'])) {
|
||||||
|
$method = [$data['validator'], 'validateToken'];
|
||||||
|
return $method($request, $data['token']);
|
||||||
|
}
|
||||||
if (isset($data['header']) and $request->hasHeader($data['header'])) {
|
if (isset($data['header']) and $request->hasHeader($data['header'])) {
|
||||||
$token = $request->getHeaderLine($data['header']);
|
$token = $request->getHeaderLine($data['header']);
|
||||||
if ($token === $this->externalPaths[$basePath][$subPath]['token']) {
|
if ($token === $this->externalPaths[$basePath][$subPath]['token']) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Service\Venta\MediosPago;
|
namespace Incoviba\Service\Venta\MediosPago;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Service\Venta\MediosPago\Toku\{Customer,Subscription,Invoice};
|
use Incoviba\Service\Venta\MediosPago\Toku\{Customer,Subscription,Invoice};
|
||||||
use Incoviba\Common\Ideal;
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
use Incoviba\Common\Implement\Exception\EmptyResponse;
|
||||||
@ -393,4 +394,10 @@ class Toku extends Ideal\Service
|
|||||||
$data['date'] = $data['transaction_date'];
|
$data['date'] = $data['transaction_date'];
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function validateToken(ServerRequestInterface $request, string $token): bool
|
||||||
|
{
|
||||||
|
$tokenHeader = json_decode($request->getHeaderLine('token'));
|
||||||
|
return strtolower($tokenHeader->header) === 'x-api-key' and $tokenHeader->token === $token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user