public function requestApi($action = '', $params = array(), $method = 'POST')
    {
        $curlOpts = array(
            CURLOPT_URL => $this->_apiUrl . $action,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_USERAGENT => 'Paymill-php/0.0.2',
            CURLOPT_SSL_VERIFYPEER => true
        );

        // Add extra options to cURL if defined.
        if (!empty($this->_extraOptions)) {
            $curlOpts = $this->_extraOptions + $curlOpts;
        }

        if ('GET' === $method || 'DELETE' === $method) {
            if (0 !== count($params)) {
                $curlOpts[CURLOPT_URL] .= false === strpos($curlOpts[CURLOPT_URL], '?') ? '?' : '&';
                $curlOpts[CURLOPT_URL] .= http_build_query($params, null, '&');
            }
        } else {
            $curlOpts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
        }

        if ($this->_apiKey) {
            $curlOpts[CURLOPT_USERPWD] = $this->_apiKey . ':';
        }
        $curl = curl_init();
        $this->_curlOpts($curl, $curlOpts);
        $responseBody = $this->_curlExec($curl);
        $responseInfo = $this->_curlInfo($curl);

        if ($responseBody === false) {
            $responseBody = array('error' => $this->_curlError($curl));
        }
        curl_close($curl);

        if ('application/json' === $responseInfo['content_type']) {
            $responseBody = json_decode($responseBody, true);
        } elseif (strpos(strtolower($responseInfo['content_type']), 'text/csv') !== false
            && !isset($responseBody['error'])
        ) {
            return $responseBody;
        }

        $result = array(
            'header' => array(
                'status' => $responseInfo['http_code'],
                'reason' => null,
            ),
            'body' => $responseBody
        );

        return $result;
    }
public function requestApi($action = '', $params = array(), $method = 'POST')
    {
        $curlOpts = array(
            CURLOPT_URL => $this->_apiUrl . $action,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_USERAGENT => 'Paymill-php/0.0.2',
            CURLOPT_SSL_VERIFYPEER => true
        );

        // Add extra options to cURL if defined.
        if (!empty($this->_extraOptions)) {
            $curlOpts = $this->_extraOptions + $curlOpts;
        }

        if ('GET' === $method || 'DELETE' === $method) {
            if (0 !== count($params)) {
                $curlOpts[CURLOPT_URL] .= false === strpos($curlOpts[CURLOPT_URL], '?') ? '?' : '&';
                $curlOpts[CURLOPT_URL] .= http_build_query($params, null, '&');
            }
        } else {
            $curlOpts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
        }

        if ($this->_apiKey) {
            $curlOpts[CURLOPT_USERPWD] = $this->_apiKey . ':';
        }
        $curl = curl_init();
        $this->_curlOpts($curl, $curlOpts);
        $responseBody = $this->_curlExec($curl);
        $responseInfo = $this->_curlInfo($curl);

        if ($responseBody === false) {
            $responseBody = array('error' => $this->_curlError($curl));
        }
        curl_close($curl);

        if ('application/json' === $responseInfo['content_type']) {
            $responseBody = json_decode($responseBody, true);
        } elseif (strpos(strtolower($responseInfo['content_type']), 'text/csv') !== false
            && !isset($responseBody['error'])
        ) {
            return $responseBody;
        }

        $result = array(
            'header' => array(
                'status' => $responseInfo['http_code'],
                'reason' => null,
            ),
            'body' => $responseBody
        );

        return $result;
    }
public function requestApi ( $ action = '' , $ params = array ( ) , $ method = 'POST' ) { $ curlOpts = array ( CURLOPT_URL => $ this -> _apiUrl . $ action , CURLOPT_RETURNTRANSFER => true , CURLOPT_CUSTOMREQUEST => $ method , CURLOPT_USERAGENT => 'Paymill-php/0.0.2' , CURLOPT_SSL_VERIFYPEER => true ) ; // Add extra options to cURL if defined. if ( ! empty ( $ this -> _extraOptions ) ) { $ curlOpts = $ this -> _extraOptions + $ curlOpts ; } if ( 'GET' === $ method || 'DELETE' === $ method ) { if ( 0 !== count ( $ params ) ) { $ curlOpts [ CURLOPT_URL ] .= false === strpos ( $ curlOpts [ CURLOPT_URL ] , '?' ) ? '?' : '&' ; $ curlOpts [ CURLOPT_URL ] .= http_build_query ( $ params , null , '&' ) ; } } else { $ curlOpts [ CURLOPT_POSTFIELDS ] = http_build_query ( $ params , null , '&' ) ; } if ( $ this -> _apiKey ) { $ curlOpts [ CURLOPT_USERPWD ] = $ this -> _apiKey . ':' ; } $ curl = curl_init ( ) ; $ this -> _curlOpts ( $ curl , $ curlOpts ) ; $ responseBody = $ this -> _curlExec ( $ curl ) ; $ responseInfo = $ this -> _curlInfo ( $ curl ) ; if ( $ responseBody === false ) { $ responseBody = array ( 'error' => $ this -> _curlError ( $ curl ) ) ; } curl_close ( $ curl ) ; if ( 'application/json' === $ responseInfo [ 'content_type' ] ) { $ responseBody = json_decode ( $ responseBody , true ) ; } elseif ( strpos ( strtolower ( $ responseInfo [ 'content_type' ] ) , 'text/csv' ) !== false && ! isset ( $ responseBody [ 'error' ] ) ) { return $ responseBody ; } $ result = array ( 'header' => array ( 'status' => $ responseInfo [ 'http_code' ] , 'reason' => null , ) , 'body' => $ responseBody ) ; return $ result ; }
Perform HTTP request to REST endpoint

@param string $action
@param array $params
@param string $method
@return array
Perform HTTP request to REST endpoint