From 0053cdc97afbdd7ba98a6cf286895f130792708d Mon Sep 17 00:00:00 2001 From: Jean Rumeau Date: Thu, 7 Jul 2016 12:29:09 -0400 Subject: [PATCH 1/4] Validates non empty response before decoding json, as an empty body is not a valid JSON string --- src/Message/AbstractRestRequest.php | 4 +++- src/Message/RestTokenRequest.php | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php index a739fad..34241ac 100644 --- a/src/Message/AbstractRestRequest.php +++ b/src/Message/AbstractRestRequest.php @@ -165,7 +165,9 @@ function ($event) { try { $httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35 $httpResponse = $httpRequest->send(); - return $this->response = $this->createResponse($httpResponse->json(), $httpResponse->getStatusCode()); + // Empty response body should be parsed also + $jsonToArrayResponse = !empty($httpResponse->getBody(true)) ? $httpResponse->json() : array(); + return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); } catch (\Exception $e) { throw new InvalidResponseException( 'Error communicating with payment gateway: ' . $e->getMessage(), diff --git a/src/Message/RestTokenRequest.php b/src/Message/RestTokenRequest.php index c3cf5d5..a73fcbf 100644 --- a/src/Message/RestTokenRequest.php +++ b/src/Message/RestTokenRequest.php @@ -48,7 +48,8 @@ function ($event) { ); $httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send(); - - return $this->response = new RestResponse($this, $httpResponse->json(), $httpResponse->getStatusCode()); + // Empty body response should be parsed also + $jsonToArrayResponse = !empty($httpResponse->getBody(true)) ? $httpResponse->json() : array(); + return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode()); } } From f12c18210a0e049112c6b5d92dff01877fe89e35 Mon Sep 17 00:00:00 2001 From: Jean Rumeau Date: Thu, 7 Jul 2016 12:31:52 -0400 Subject: [PATCH 2/4] Update .travis.yml Add php7 to builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 67753ce..68bf51a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm before_script: From 8e54345e5623ee938758baa3e0c5aa7b51d9ba8b Mon Sep 17 00:00:00 2001 From: Jean Rumeau Date: Thu, 7 Jul 2016 12:36:15 -0400 Subject: [PATCH 3/4] trigger tests --- src/Message/AbstractRestRequest.php | 2 +- src/Message/RestTokenRequest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php index 34241ac..e4defdd 100644 --- a/src/Message/AbstractRestRequest.php +++ b/src/Message/AbstractRestRequest.php @@ -165,7 +165,7 @@ function ($event) { try { $httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35 $httpResponse = $httpRequest->send(); - // Empty response body should be parsed also + // Empty response body should be parsed also as and empty array $jsonToArrayResponse = !empty($httpResponse->getBody(true)) ? $httpResponse->json() : array(); return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); } catch (\Exception $e) { diff --git a/src/Message/RestTokenRequest.php b/src/Message/RestTokenRequest.php index a73fcbf..985a28d 100644 --- a/src/Message/RestTokenRequest.php +++ b/src/Message/RestTokenRequest.php @@ -48,7 +48,7 @@ function ($event) { ); $httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send(); - // Empty body response should be parsed also + // Empty response body should be parsed also as and empty array $jsonToArrayResponse = !empty($httpResponse->getBody(true)) ? $httpResponse->json() : array(); return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode()); } From ce4c0b2f859d2e374b6b0c324a2176a8472ae5a3 Mon Sep 17 00:00:00 2001 From: Jean Rumeau Date: Thu, 7 Jul 2016 12:47:15 -0400 Subject: [PATCH 4/4] Fix return value on write context --- src/Message/AbstractRestRequest.php | 3 ++- src/Message/RestTokenRequest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php index e4defdd..19ef31e 100644 --- a/src/Message/AbstractRestRequest.php +++ b/src/Message/AbstractRestRequest.php @@ -166,7 +166,8 @@ function ($event) { $httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35 $httpResponse = $httpRequest->send(); // Empty response body should be parsed also as and empty array - $jsonToArrayResponse = !empty($httpResponse->getBody(true)) ? $httpResponse->json() : array(); + $body = $httpResponse->getBody(true); + $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array(); return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode()); } catch (\Exception $e) { throw new InvalidResponseException( diff --git a/src/Message/RestTokenRequest.php b/src/Message/RestTokenRequest.php index 985a28d..635cf3e 100644 --- a/src/Message/RestTokenRequest.php +++ b/src/Message/RestTokenRequest.php @@ -49,7 +49,8 @@ function ($event) { $httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send(); // Empty response body should be parsed also as and empty array - $jsonToArrayResponse = !empty($httpResponse->getBody(true)) ? $httpResponse->json() : array(); + $body = $httpResponse->getBody(true); + $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array(); return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode()); } }