You are here

private static function Braintree_Http::_doRequest in Commerce Braintree 7

4 calls to Braintree_Http::_doRequest()
Braintree_Http::delete in braintree_php/lib/Braintree/Http.php
Braintree_Http::get in braintree_php/lib/Braintree/Http.php
Braintree_Http::post in braintree_php/lib/Braintree/Http.php
Braintree_Http::put in braintree_php/lib/Braintree/Http.php

File

braintree_php/lib/Braintree/Http.php, line 62

Class

Braintree_Http
processes Http requests using curl

Code

private static function _doRequest($httpVerb, $path, $requestBody = null) {
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_TIMEOUT, 60);
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb);
  curl_setopt($curl, CURLOPT_URL, Braintree_Configuration::merchantUrl() . $path);
  curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
  curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Accept: application/xml',
    'Content-Type: application/xml',
    'User-Agent: Braintree PHP Library ' . Braintree_Version::get(),
    'X-ApiVersion: ' . Braintree_Configuration::API_VERSION,
  ));
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($curl, CURLOPT_USERPWD, Braintree_Configuration::publicKey() . ':' . Braintree_Configuration::privateKey());

  // curl_setopt($curl, CURLOPT_VERBOSE, true);
  if (Braintree_Configuration::sslOn()) {
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($curl, CURLOPT_CAINFO, Braintree_Configuration::caFile());
  }
  if (!empty($requestBody)) {
    curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
  }
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  $response = curl_exec($curl);
  $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  curl_close($curl);
  if (Braintree_Configuration::sslOn()) {
    if ($httpStatus == 0) {
      throw new Braintree_Exception_SSLCertificate();
    }
  }
  return array(
    'status' => $httpStatus,
    'body' => $response,
  );
}