Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

554
 
610
 
610
 
payment.php
_> 11 <?php
  22 /*
<> 3 -  $Id: payment.php 554 2006-04-29 16:26:53Z hpdl $
   3+  $Id: payment.php 610 2006-07-05 11:04:24Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
5959 
  6060 // class methods
  6161     function sendTransactionToGateway($url, $parameters, $header = '', $method = 'post', $certificate = '') {
<> 62 -      if (empty($header) || (is_array($header) === false)) {
   62+      if (empty($header) || !is_array($header)) {
6363         $header = array();
  6464       }
  6565 
<> 66 -      $result = '';
  67 -
6866       $server = parse_url($url);
  6967 
  7068       if (isset($server['port']) === false) {
     
 !
7977         $header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
  8078       }
  8179 
<>  80+      $connection_method = 0;
8281 
<> 83 -      $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
  84 -      curl_setopt($curl, CURLOPT_PORT, $server['port']);
  85 -
  86 -      if (empty($header) === false) {
  87 -        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
   82+      if (function_exists('curl_init')) {
   83+        $connection_method = 1;
   84+      } elseif ( ($server['scheme'] == 'http') || (($server['scheme'] == 'https') && extension_loaded('openssl')) ) {
   85+        if (function_exists('stream_context_create')) {
   86+          $connection_method = 3;
   87+        } else {
   88+          $connection_method = 2;
   89+        }
8890       }
  8991 
<> 90 -      if (empty($certificate) === false) {
  91 -        curl_setopt($curl, CURLOPT_SSLCERT, $certificate);
  92 -      }
   92+      $result = '';
9393 
<> 94 -      curl_setopt($curl, CURLOPT_HEADER, 0);
  95 -      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  96 -      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  97 -      curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
  98 -      curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
  99 -      curl_setopt($curl, CURLOPT_POST, 1);
  100 -      curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
  101 -      $result = curl_exec($curl);
  102 -      curl_close($curl);
   94+      switch ($connection_method) {
   95+        case 1:
   96+          $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
   97+          curl_setopt($curl, CURLOPT_PORT, $server['port']);
10398 
<>  99+          if (!empty($header)) {
   100+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
   101+          }
104102 
<> 105 -/*
  106 -      exec('/usr/bin/curl -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k' . (empty($header) === false ? ' -H ' . escapeshellarg(implode("\r\n", $header)) : '') . (empty($certificate) === false ? ' -E ' . escapeshellarg($certificate) : ''), $result);
  107 -      $result = implode("\n", $result);
  108 -*/
  109 -/*
  110 -      if ($fp = @fsockopen(($server['scheme'] == 'https' ? 'ssl' : $server['scheme']) . '://' . $server['host'], $server['port'])) {
  111 -        @fputs($fp, 'POST ' . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . ' HTTP/1.1' . "\r\n" .
  112 -                    'Host: ' . $server['host'] . "\r\n" .
  113 -                    'Content-type: application/x-www-form-urlencoded' . "\r\n" .
  114 -                    'Content-length: ' . strlen($parameters) . "\r\n" .
  115 -                    (empty($header) === false ? implode("\r\n", $header) . "\r\n" : '') .
  116 -                    'Connection: close' . "\r\n\r\n" .
  117 -                    $parameters . "\r\n\r\n");
   103+          if (!empty($certificate)) {
   104+            curl_setopt($curl, CURLOPT_SSLCERT, $certificate);
   105+          }
118106 
<> 119 -        $result = @stream_get_contents($fp);
   107+          curl_setopt($curl, CURLOPT_HEADER, 0);
   108+          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
   109+          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   110+          curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
   111+          curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
   112+          curl_setopt($curl, CURLOPT_POST, 1);
   113+          curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
120114 
<> 121 -        @fclose($fp);
   115+          $result = curl_exec($curl);
122116 
<> 123 -        $result = trim(substr($result, strpos($result, "\r\n\r\n", strpos(strtolower($result), 'content-length:'))));
  124 -      }
  125 -*/
  126 -/*
  127 -      $options = array('http' => array('method' => 'POST',
  128 -                                       'header' => 'Host: ' . $server['host'] . "\r\n" .
  129 -                                                   'Content-type: application/x-www-form-urlencoded' . "\r\n" .
  130 -                                                   'Content-length: ' . strlen($parameters) . "\r\n" .
  131 -                                                   (empty($header) === false ? implode("\r\n", $header) . "\r\n" : '') .
  132 -                                                   'Connection: close',
  133 -                                       'content' => $parameters));
   117+          curl_close($curl);
134118 
<> 135 -      if (empty($certificate) === false) {
  136 -        $options['ssl'] = array('local_cert' => $certificate);
  137 -      }
   119+          break;
138120 
<> 139 -      $context = stream_context_create($options);
   121+        case 2:
   122+          if ($fp = @fsockopen(($server['scheme'] == 'https' ? 'ssl' : $server['scheme']) . '://' . $server['host'], $server['port'])) {
   123+            @fputs($fp, 'POST ' . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . ' HTTP/1.1' . "\r\n" .
   124+                        'Host: ' . $server['host'] . "\r\n" .
   125+                        'Content-type: application/x-www-form-urlencoded' . "\r\n" .
   126+                        'Content-length: ' . strlen($parameters) . "\r\n" .
   127+                        (!empty($header) ? implode("\r\n", $header) . "\r\n" : '') .
   128+                        'Connection: close' . "\r\n\r\n" .
   129+                        $parameters . "\r\n\r\n");
140130 
<> 141 -      if ($fp = fopen($url, 'r', false, $context)) {
  142 -        $result = '';
   131+            $result = @stream_get_contents($fp);
143132 
<> 144 -        while (!feof($fp)) {
  145 -          $result .= fgets($fp, 4096);
  146 -        }
   133+            @fclose($fp);
147134 
<> 148 -        fclose($fp);
   135+            $result = trim(substr($result, strpos($result, "\r\n\r\n", strpos(strtolower($result), 'content-length:'))));
   136+          }
   137+
   138+          break;
   139+
   140+        case 3:
   141+          $options = array('http' => array('method' => 'POST',
   142+                                           'header' => 'Host: ' . $server['host'] . "\r\n" .
   143+                                                       'Content-type: application/x-www-form-urlencoded' . "\r\n" .
   144+                                                       'Content-length: ' . strlen($parameters) . "\r\n" .
   145+                                                       (!empty($header) ? implode("\r\n", $header) . "\r\n" : '') .
   146+                                                       'Connection: close',
   147+                                           'content' => $parameters));
   148+
   149+          if (!empty($certificate)) {
   150+            $options['ssl'] = array('local_cert' => $certificate);
   151+          }
   152+
   153+          $context = stream_context_create($options);
   154+
   155+          if ($fp = fopen($url, 'r', false, $context)) {
   156+            $result = '';
   157+
   158+            while (!feof($fp)) {
   159+              $result .= fgets($fp, 4096);
   160+            }
   161+
   162+            fclose($fp);
   163+          }
   164+
   165+          break;
   166+
   167+        default:
   168+          exec(escapeshellarg(CFG_APP_CURL) . ' -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k' . (!empty($header) ? ' -H ' . escapeshellarg(implode("\r\n", $header)) : '') . (!empty($certificate) ? ' -E ' . escapeshellarg($certificate) : ''), $result);
   169+          $result = implode("\n", $result);
149170       }
<> 150 -*/
<_ 151171 
  152172       return $result;
  153173     }