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: diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php index a739fad..19ef31e 100644 --- a/src/Message/AbstractRestRequest.php +++ b/src/Message/AbstractRestRequest.php @@ -165,7 +165,10 @@ 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 as and empty 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( 'Error communicating with payment gateway: ' . $e->getMessage(), diff --git a/src/Message/RestTokenRequest.php b/src/Message/RestTokenRequest.php index c3cf5d5..635cf3e 100644 --- a/src/Message/RestTokenRequest.php +++ b/src/Message/RestTokenRequest.php @@ -48,7 +48,9 @@ function ($event) { ); $httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send(); - - return $this->response = new RestResponse($this, $httpResponse->json(), $httpResponse->getStatusCode()); + // Empty response body should be parsed also as and empty array + $body = $httpResponse->getBody(true); + $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array(); + return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode()); } }