Re: Re: Re: Re: Hey--Great module, thanks

Posts: 80
Joined: 12/28/2007
Bug FinderGetting busy with the Ubercode.

Better yet, here is a function with better error handling. This one should write any curl errors to your Drupal "recent log entries" watchdog.

function uc_cim_curl_send($content) {
  //Build the path to post to, depending on whether we're in test mode or not
  if (variable_get('cim_transaction_mode', 'test') == 'test') {
    $posturl = 'https://apitest.authorize.net/xml/v1/request.api';
  }
  else {
    $posturl = 'https://api.authorize.net/xml/v1/request.api';
  }

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $posturl);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
  curl_setopt($ch, CURLOPT_HEADER, 0);  //Set to true to return the header in the output - good for debugging, but messes with xml parsing
  curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
  $authorize = curl_exec($ch);
  if ($error = curl_error($ch)) {
    watchdog('uc_cim', $error, WATCHDOG_ERROR);
  }
  else {
    $response = uc_cim_parse_return($authorize);
  }
 
  curl_close($ch); 
  return $response;
}

NEW Authorize.net Customer Information Manager By: xerbutter (78 replies) Wed, 11/21/2007 - 12:50