Esempio n. 1
0
 /**
  * Handle any errors in the API response
  *
  * If the response doesn't contain JSON, we will fail to decode and throw a
  * MalFormedResponseException.
  *
  * If the response is JSON, but the status code is >= 400, then we return
  * the appropriate error depending on the code
  *
  * @param GuzzleHttp\Psr7\Response $response The raw API response
  */
 private function handleErrors($response)
 {
     $json = json_decode($response->getBody());
     if ($json === null) {
         $msg = "Malformed response received from server";
         throw new Exception\MalformedResponseException($msg, $response);
     }
     if ($response->getStatusCode() < 400) {
         return null;
     }
     $error = $json->error;
     $exception_class = (string) ApiException::getErrorForType($error->type);
     $exception_class = 'GoCardlessPro\\Core\\Exception\\' . $exception_class;
     throw new $exception_class($error);
 }
 /**
  * Get all papertrail events
  * @return array
  */
 public function getEvents()
 {
     return json_decode((string) $this->response->getBody())->events;
 }
 /**
  * @param  GuzzleHttp\Psr7\Response $response
  * @return array
  */
 private function convertResponse($response)
 {
     $responseHeader = $response->getHeaderLine('content-type');
     if (false == preg_match('/application\\/json/', $responseHeader)) {
         throw new ResponseFormatException();
     }
     return json_decode($response->getBody(), true);
 }