Skip to content

Commit

Permalink
release v6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Vela Romera committed Nov 19, 2020
1 parent 46828a2 commit fe29223
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "payvision/payvision-sdk-php",
"description": "Payvision PHP SDK",
"type": "library",
"version": "5.1.2",
"version": "6.0.0",
"license": "MIT",
"require": {
"php": "^7.2.5|^7.3",
"php": "~7.1.3||~7.2.5||~7.3.0||~7.4.0",
"ext-simplexml": "*",
"ext-json": "*",
"ext-curl": "*",
Expand All @@ -23,9 +23,9 @@
}
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^7.5",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"object-calisthenics/phpcs-calisthenics-rules": "^3.8",
"object-calisthenics/phpcs-calisthenics-rules": "^3.0",
"phpcompatibility/php-compatibility": "^9.3",
"slevomat/coding-standard": "^6.3",
"squizlabs/php_codesniffer": "^3.5"
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<!-- PHP compatibility -->
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.2-"/>
<config name="testVersion" value="7.1-"/>

<!-- Extra rules -->
<rule ref="Generic.Arrays.ArrayIndent"/>
Expand Down
38 changes: 25 additions & 13 deletions src/Infrastructure/ApiConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Payvision\SDK\Exception\Api\ErrorResponse;
use Payvision\SDK\Exception\ApiException;
use Payvision\SDK\Exception\BuilderException;
use Psr\Http\Message\ResponseInterface;
use ReflectionException;

class ApiConnection implements Connection
Expand Down Expand Up @@ -107,6 +108,7 @@ public function executeAndReturnArray(Request $request): array
* @param RequestHeaderCollection $requestHeaderCollection
* @return array
* @throws ApiException
* @throws ErrorResponse
*/
private function get(Request $request, RequestHeaderCollection $requestHeaderCollection): array
{
Expand All @@ -116,26 +118,15 @@ private function get(Request $request, RequestHeaderCollection $requestHeaderCol
);

$this->lastJsonRequest = $request->getPathParams();
$this->lastStatusCode = $guzzleResponse->getStatusCode();
$contents = $guzzleResponse->getBody()->getContents();
$json = \json_decode($contents, true);

if (!\is_array($json)) {
$this->logDebugData($this->lastJsonRequest, ['_raw_response' => $contents], $requestHeaderCollection);
throw new ApiException(
\sprintf('Response is not JSON: %1$s', $contents),
ApiException::INVALID_RESPONSE
);
}

return $json;
return $this->parseJSONResponse($guzzleResponse, $requestHeaderCollection);
}

/**
* @param Request $request
* @param RequestHeaderCollection $requestHeaderCollection
* @return array
* @throws ApiException
* @throws ErrorResponse
*/
private function post(Request $request, RequestHeaderCollection $requestHeaderCollection): array
{
Expand All @@ -147,12 +138,32 @@ private function post(Request $request, RequestHeaderCollection $requestHeaderCo
);

$this->lastJsonRequest = $jsonRequest;
return $this->parseJSONResponse($guzzleResponse, $requestHeaderCollection);
}

/**
* @throws ApiException
* @throws ErrorResponse
*/
private function parseJSONResponse(
ResponseInterface $guzzleResponse,
RequestHeaderCollection $requestHeaderCollection
): array {
$this->lastStatusCode = $guzzleResponse->getStatusCode();
$contents = $guzzleResponse->getBody()->getContents();
$json = \json_decode($contents, true);

if (!\is_array($json)) {
$this->logDebugData($this->lastJsonRequest, ['_raw_response' => $contents], $requestHeaderCollection);

if ($this->lastStatusCode >= 400) {
throw new ErrorResponse(
$guzzleResponse,
'Invalid response code received',
ErrorResponse::INVALID_RESPONSE
);
}

throw new ApiException(
\sprintf('Response is not JSON: %1$s', $contents),
ApiException::INVALID_RESPONSE
Expand Down Expand Up @@ -250,6 +261,7 @@ private function handleResponse(
* @param Request $request
* @param array $requestHeaders
* @return array
* @throws ErrorResponse
* @throws ApiException
*/
private function doRequest(Request $request, array $requestHeaders = []): array
Expand Down

0 comments on commit fe29223

Please sign in to comment.