private function request($httpVerb, $resource, array $data = null, $authenticated = true)
    {
        if (self::$REQUEST_HANDLER === null) {
            $request = new CurlRequest();
        }
        else {
            $request = self::$REQUEST_HANDLER;
        }

        $userAgent = self::getUserAgent();
        $headers = array(
            'Accept: application/json',
            'Content-Type: application/json',
            'User-Agent: ' . $userAgent
        );
        if ($authenticated) {
            $headers[] = 'Authorization: Bearer ' . $this->_configuration->getToken();
        }

        $request->setopt(CURLOPT_FAILONERROR, false);
        $request->setopt(CURLOPT_RETURNTRANSFER, true);
        $request->setopt(CURLOPT_CUSTOMREQUEST, $httpVerb);
        $request->setopt(CURLOPT_URL, $resource);
        $request->setopt(CURLOPT_HTTPHEADER, $headers);
        $request->setopt(CURLOPT_SSL_VERIFYPEER, true);
        $request->setopt(CURLOPT_SSL_VERIFYHOST, 2);
        $request->setopt(CURLOPT_CAINFO, self::$CACERT_PATH);
        if (!empty($data)) {
            $request->setopt(CURLOPT_POSTFIELDS, json_encode($data));
        }

        $result = array(
            'httpResponse'  => $request->exec(),
            'httpStatus'    => $request->getInfo(CURLINFO_HTTP_CODE)
        );

        // We must do this before closing curl
        $errorCode = $request->errno();
        $errorMessage = $request->error();

        $request->close();

        // We want manage errors from HTTP in standards cases
        $curlStatusNotManage = array(
            0, // CURLE_OK
            22 // CURLE_HTTP_NOT_FOUND or CURLE_HTTP_RETURNED_ERROR
        );

        // If there was an HTTP error
        if (in_array($errorCode, $curlStatusNotManage) && substr($result['httpStatus'], 0, 1) !== '2') {
            $this->throwRequestException($result['httpResponse'], $result['httpStatus']);
        // Unreachable bracket marked as executable by old versions of XDebug
        } // If there was an error with curl
        elseif ($result['httpResponse'] === false || $errorCode) {
            $this->throwConnectionException($result['httpStatus'], $errorMessage);
        // Unreachable bracket marked as executable by old versions of XDebug
        }

        $result['httpResponse'] = json_decode($result['httpResponse'], true);

        if ($result['httpResponse'] === null) {
            throw new Payplug\Exception\UnexpectedAPIResponseException('API response is not valid JSON.', $result['httpResponse']);
        }

        return $result;
    }
private function request($httpVerb, $resource, array $data = null, $authenticated = true)
    {
        if (self::$REQUEST_HANDLER === null) {
            $request = new CurlRequest();
        }
        else {
            $request = self::$REQUEST_HANDLER;
        }

        $userAgent = self::getUserAgent();
        $headers = array(
            'Accept: application/json',
            'Content-Type: application/json',
            'User-Agent: ' . $userAgent
        );
        if ($authenticated) {
            $headers[] = 'Authorization: Bearer ' . $this->_configuration->getToken();
        }

        $request->setopt(CURLOPT_FAILONERROR, false);
        $request->setopt(CURLOPT_RETURNTRANSFER, true);
        $request->setopt(CURLOPT_CUSTOMREQUEST, $httpVerb);
        $request->setopt(CURLOPT_URL, $resource);
        $request->setopt(CURLOPT_HTTPHEADER, $headers);
        $request->setopt(CURLOPT_SSL_VERIFYPEER, true);
        $request->setopt(CURLOPT_SSL_VERIFYHOST, 2);
        $request->setopt(CURLOPT_CAINFO, self::$CACERT_PATH);
        if (!empty($data)) {
            $request->setopt(CURLOPT_POSTFIELDS, json_encode($data));
        }

        $result = array(
            'httpResponse'  => $request->exec(),
            'httpStatus'    => $request->getInfo(CURLINFO_HTTP_CODE)
        );

        // We must do this before closing curl
        $errorCode = $request->errno();
        $errorMessage = $request->error();

        $request->close();

        // We want manage errors from HTTP in standards cases
        $curlStatusNotManage = array(
            0, // CURLE_OK
            22 // CURLE_HTTP_NOT_FOUND or CURLE_HTTP_RETURNED_ERROR
        );

        // If there was an HTTP error
        if (in_array($errorCode, $curlStatusNotManage) && substr($result['httpStatus'], 0, 1) !== '2') {
            $this->throwRequestException($result['httpResponse'], $result['httpStatus']);
        // Unreachable bracket marked as executable by old versions of XDebug
        } // If there was an error with curl
        elseif ($result['httpResponse'] === false || $errorCode) {
            $this->throwConnectionException($result['httpStatus'], $errorMessage);
        // Unreachable bracket marked as executable by old versions of XDebug
        }

        $result['httpResponse'] = json_decode($result['httpResponse'], true);

        if ($result['httpResponse'] === null) {
            throw new Payplug\Exception\UnexpectedAPIResponseException('API response is not valid JSON.', $result['httpResponse']);
        }

        return $result;
    }
private function request ( $ httpVerb , $ resource , array $ data = null , $ authenticated = true ) { if ( self :: $ REQUEST_HANDLER === null ) { $ request = new CurlRequest ( ) ; } else { $ request = self :: $ REQUEST_HANDLER ; } $ userAgent = self :: getUserAgent ( ) ; $ headers = array ( 'Accept: application/json' , 'Content-Type: application/json' , 'User-Agent: ' . $ userAgent ) ; if ( $ authenticated ) { $ headers [ ] = 'Authorization: Bearer ' . $ this -> _configuration -> getToken ( ) ; } $ request -> setopt ( CURLOPT_FAILONERROR , false ) ; $ request -> setopt ( CURLOPT_RETURNTRANSFER , true ) ; $ request -> setopt ( CURLOPT_CUSTOMREQUEST , $ httpVerb ) ; $ request -> setopt ( CURLOPT_URL , $ resource ) ; $ request -> setopt ( CURLOPT_HTTPHEADER , $ headers ) ; $ request -> setopt ( CURLOPT_SSL_VERIFYPEER , true ) ; $ request -> setopt ( CURLOPT_SSL_VERIFYHOST , 2 ) ; $ request -> setopt ( CURLOPT_CAINFO , self :: $ CACERT_PATH ) ; if ( ! empty ( $ data ) ) { $ request -> setopt ( CURLOPT_POSTFIELDS , json_encode ( $ data ) ) ; } $ result = array ( 'httpResponse' => $ request -> exec ( ) , 'httpStatus' => $ request -> getInfo ( CURLINFO_HTTP_CODE ) ) ; // We must do this before closing curl $ errorCode = $ request -> errno ( ) ; $ errorMessage = $ request -> error ( ) ; $ request -> close ( ) ; // We want manage errors from HTTP in standards cases $ curlStatusNotManage = array ( 0 , // CURLE_OK 22 // CURLE_HTTP_NOT_FOUND or CURLE_HTTP_RETURNED_ERROR ) ; // If there was an HTTP error if ( in_array ( $ errorCode , $ curlStatusNotManage ) && substr ( $ result [ 'httpStatus' ] , 0 , 1 ) !== '2' ) { $ this -> throwRequestException ( $ result [ 'httpResponse' ] , $ result [ 'httpStatus' ] ) ; // Unreachable bracket marked as executable by old versions of XDebug } // If there was an error with curl elseif ( $ result [ 'httpResponse' ] === false || $ errorCode ) { $ this -> throwConnectionException ( $ result [ 'httpStatus' ] , $ errorMessage ) ; // Unreachable bracket marked as executable by old versions of XDebug } $ result [ 'httpResponse' ] = json_decode ( $ result [ 'httpResponse' ] , true ) ; if ( $ result [ 'httpResponse' ] === null ) { throw new Payplug \ Exception \ UnexpectedAPIResponseException ( 'API response is not valid JSON.' , $ result [ 'httpResponse' ] ) ; } return $ result ; }
Performs a request.

@param   string  $httpVerb       the HTTP verb (PUT, POST, GET, …)
@param   string  $resource       the path to the resource queried
@param   array   $data           the request content
@param   bool    $authenticated  the request should be authenticated

@return array the response in a dictionary with following keys:
<pre>
'httpStatus'    => The 2xx HTTP status code {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2}
'httpResponse'  => The HTTP response
</pre>

@throws  Payplug\Exception\UnexpectedAPIResponseException  When the API response is not parsable in JSON.
@throws  Payplug\Exception\HttpException                   When status code is not 2xx.
@throws  Payplug\Exception\ConnectionException             When an error was encountered while connecting to the resource.
Performs a request .