/**
  * Signs request - adds Authorization header with generated value
  *
  * @param Paysera_WalletApi_Http_Request $request
  * @param array                          $parameters
  */
 public function signRequest(Paysera_WalletApi_Http_Request $request, array $parameters = array())
 {
     $request->setClientCertificate(clone $this->clientCertificate);
     foreach ($parameters as $name => $value) {
         $name = implode('-', array_map('ucfirst', explode('-', str_replace('_', '-', $name))));
         $request->setHeader(self::HEADER_PREFIX . $name, $value);
     }
 }
 /**
  * Generates ext field for this request to be used in MAC authorization header
  *
  * @param Paysera_WalletApi_Http_Request $request
  * @param array                          $parameters
  *
  * @return string
  */
 protected function generateExt(Paysera_WalletApi_Http_Request $request, array $parameters)
 {
     $content = $request->getContent();
     $extParts = array();
     if ($content != '') {
         $extParts['body_hash'] = base64_encode(hash('sha256', $content, true));
     }
     $extParts = $extParts + $parameters;
     if (count($extParts) > 0) {
         return http_build_query($extParts);
     } else {
         return '';
     }
 }
 /**
  * Makes request to remote server using cURL
  *
  * @param Paysera_WalletApi_Http_Request $request
  *
  * @return Paysera_WalletApi_Http_Response
  *
  * @throws Paysera_WalletApi_Exception_HttpException
  * @throws Paysera_WalletApi_Exception_ConfigurationException
  */
 public function makeRequest(Paysera_WalletApi_Http_Request $request)
 {
     $curl = $this->getCurl();
     curl_setopt($curl, CURLOPT_URL, $request->getFullUri());
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
     curl_setopt($curl, CURLOPT_HTTPHEADER, array_merge($request->getFormattedHeaders(), array('Expect:')));
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getContent());
     $clientCertificate = $request->getClientCertificate();
     if ($clientCertificate !== null) {
         if ($clientCertificate->getCertificatePath() === null || $clientCertificate->getPrivateKeyPath() === null) {
             throw new Paysera_WalletApi_Exception_ConfigurationException('If client certificate is provided, both certificate path and private key path must be set');
         }
         curl_setopt($curl, CURLOPT_SSLCERT, $clientCertificate->getCertificatePath());
         curl_setopt($curl, CURLOPT_SSLCERTTYPE, $clientCertificate->getCertificateType());
         curl_setopt($curl, CURLOPT_SSLKEY, $clientCertificate->getPrivateKeyPath());
         curl_setopt($curl, CURLOPT_SSLKEYTYPE, $clientCertificate->getPrivateKeyType());
         if ($clientCertificate->getCertificatePassword() !== null) {
             curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $clientCertificate->getCertificatePassword());
         }
         if ($clientCertificate->getPrivateKeyPassword() !== null) {
             curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $clientCertificate->getPrivateKeyPassword());
         }
     }
     $result = curl_exec($curl);
     if ($result === false) {
         $exception = new Paysera_WalletApi_Exception_HttpException(curl_error($curl), curl_errno($curl));
         curl_close($curl);
         throw $exception;
     }
     $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $parts = explode("\r\n\r\n", $result, 2);
     $headers = explode("\r\n", $parts[0]);
     unset($headers[0]);
     // remove status code
     $content = isset($parts[1]) ? $parts[1] : '';
     curl_close($curl);
     return new Paysera_WalletApi_Http_Response($statusCode, $headers, $content);
 }