Manejo de contenido
This commit is contained in:
@ -2,14 +2,14 @@
|
||||
namespace Incoviba\Service\Venta\MediosPago;
|
||||
|
||||
use HttpException;
|
||||
use Incoviba\Common\Define\Repository;
|
||||
use Incoviba\Common\Ideal\LoggerEnabled;
|
||||
use Incoviba\Common\Implement\Exception\{EmptyResponse, EmptyResult};
|
||||
use Incoviba\Exception\InvalidResult;
|
||||
use PDOException;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Incoviba\Common\Define\Repository;
|
||||
use Incoviba\Common\Ideal\LoggerEnabled;
|
||||
use Incoviba\Common\Implement\Exception\{EmptyResponse, EmptyResult};
|
||||
use Incoviba\Exception\InvalidResult;
|
||||
|
||||
abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
{
|
||||
@ -27,13 +27,14 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
{
|
||||
$status = $response->getStatusCode();
|
||||
$reason = $response->getReasonPhrase();
|
||||
$contents = $response->getBody()->getContents();
|
||||
|
||||
if (in_array($status, $invalidStatus)) {
|
||||
$contents = $response->getBody()->getContents();
|
||||
$exception = new HttpException("{$reason}\n{$contents}", $status);
|
||||
throw new EmptyResponse($request_uri, $exception);
|
||||
}
|
||||
if (!in_array($status, $validStatus)) {
|
||||
$contents = $response->getBody()->getContents();
|
||||
$exception = new HttpException("{$reason}\n{$contents}", $status);
|
||||
throw new EmptyResponse($request_uri, $exception);
|
||||
}
|
||||
@ -43,7 +44,7 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
* @param string $request_uri
|
||||
* @param array $validStatus
|
||||
* @param array $invalidStatus
|
||||
* @return string
|
||||
* @return array
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function sendGet(string $request_uri, array $validStatus, array $invalidStatus): array
|
||||
@ -64,7 +65,7 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
* @param array $data
|
||||
* @param array $validStatus
|
||||
* @param array $invalidStatus
|
||||
* @return string
|
||||
* @return bool
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function sendAdd(string $request_uri, array $data, array $validStatus, array $invalidStatus): bool
|
||||
@ -75,10 +76,12 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
} catch (ClientExceptionInterface $exception) {
|
||||
throw new EmptyResponse($request_uri, $exception);
|
||||
}
|
||||
|
||||
$this->validateResponse($response, $request_uri, $validStatus, $invalidStatus);
|
||||
|
||||
$contents = $response->getBody()->getContents();
|
||||
if (trim($contents) === '') {
|
||||
throw new EmptyResponse($request_uri);
|
||||
}
|
||||
$json = json_decode($contents, true);
|
||||
return $this->save($json);
|
||||
}
|
||||
@ -88,7 +91,7 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
* @param array $data
|
||||
* @param array $validStatus
|
||||
* @param array $invalidStatus
|
||||
* @return string
|
||||
* @return bool
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function sendEdit(string $request_uri, array $data, array $validStatus, array $invalidStatus): bool
|
||||
@ -127,7 +130,7 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
protected function doSave(Repository $repository, array $data): bool
|
||||
{
|
||||
try {
|
||||
$repository->fetchById($data['id']);
|
||||
$repository->fetchByTokuId($data['id']);
|
||||
return true;
|
||||
} catch (EmptyResult) {
|
||||
$mappedData = $this->mapSave($data);
|
||||
|
Reference in New Issue
Block a user