Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

443
 
554
 
554
 
payment.php
_> 11 <?php
  22 /*
<> 3 -  $Id: payment.php 443 2006-02-19 23:01:01Z hpdl $
   3+  $Id: payment.php 554 2006-04-29 16:26:53Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1010   Released under the GNU General Public License
  1111 */
  1212 
<>  13+  include(dirname(__FILE__) . '/credit_card.php');
   14+
1315   class osC_Payment {
  1416     var $selected_module;
  1517 
     
 !
5658     }
  5759 
  5860 // class methods
<>  61+    function sendTransactionToGateway($url, $parameters, $header = '', $method = 'post', $certificate = '') {
   62+      if (empty($header) || (is_array($header) === false)) {
   63+        $header = array();
   64+      }
   65+
   66+      $result = '';
   67+
   68+      $server = parse_url($url);
   69+
   70+      if (isset($server['port']) === false) {
   71+        $server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
   72+      }
   73+
   74+      if (isset($server['path']) === false) {
   75+        $server['path'] = '/';
   76+      }
   77+
   78+      if (isset($server['user']) && isset($server['pass'])) {
   79+        $header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
   80+      }
   81+
   82+
   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);
   88+      }
   89+
   90+      if (empty($certificate) === false) {
   91+        curl_setopt($curl, CURLOPT_SSLCERT, $certificate);
   92+      }
   93+
   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);
   103+
   104+
   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");
   118+
   119+        $result = @stream_get_contents($fp);
   120+
   121+        @fclose($fp);
   122+
   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));
   134+
   135+      if (empty($certificate) === false) {
   136+        $options['ssl'] = array('local_cert' => $certificate);
   137+      }
   138+
   139+      $context = stream_context_create($options);
   140+
   141+      if ($fp = fopen($url, 'r', false, $context)) {
   142+        $result = '';
   143+
   144+        while (!feof($fp)) {
   145+          $result .= fgets($fp, 4096);
   146+        }
   147+
   148+        fclose($fp);
   149+      }
   150+*/
   151+
   152+      return $result;
   153+    }
   154+
59155     function getCode() {
  60156       return $this->_code;
  61157     }
     
 !
68164       return $this->_description;
  69165     }
  70166 
<> 71 -    function getStatus() {
   167+    function getMethodTitle() {
   168+      return $this->_method_title;
   169+    }
   170+
   171+    function isEnabled() {
72172       return $this->_status;
  73173     }
  74174 
  75175     function getSortOrder() {
  76176       return $this->_sort_order;
  77177     }
  78178 
<> 79 -/* The following method is needed in the checkout_confirmation.php page
  80 -   due to a chicken and egg problem with the payment class and order class.
  81 -   The payment modules needs the order destination data for the dynamic status
  82 -   feature, and the order class needs the payment module title.
  83 -   The following method is a work-around to implementing the method in all
  84 -   payment modules available which would break the modules in the contributions
  85 -   section. This should be looked into again post 2.2.
  86 -*/
  87 -    function update_status() {
  88 -      if (is_array($this->_modules)) {
  89 -        if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
  90 -          if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
  91 -            $GLOBALS[$this->selected_module]->update_status();
  92 -          }
  93 -        }
  94 -      }
   179+    function getJavascriptBlock() {
95180     }
  96181 
<> 97 -    function javascript_validation() {
   182+    function getJavascriptBlocks() {
98183       global $osC_Language;
  99184 
  100185       $js = '';
     
 !
104189               '  var error = 0;' . "\n" .
  105190               '  var error_message = "' . $osC_Language->get('js_error') . '";' . "\n" .
  106191               '  var payment_value = null;' . "\n" .
<> 107 -              '  if (document.checkout_payment.payment.length) {' . "\n" .
  108 -              '    for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
  109 -              '      if (document.checkout_payment.payment[i].checked) {' . "\n" .
  110 -              '        payment_value = document.checkout_payment.payment[i].value;' . "\n" .
   192+              '  if (document.checkout_payment.payment_method.length) {' . "\n" .
   193+              '    for (var i=0; i<document.checkout_payment.payment_method.length; i++) {' . "\n" .
   194+              '      if (document.checkout_payment.payment_method[i].checked) {' . "\n" .
   195+              '        payment_value = document.checkout_payment.payment_method[i].value;' . "\n" .
111196               '      }' . "\n" .
  112197               '    }' . "\n" .
<> 113 -              '  } else if (document.checkout_payment.payment.checked) {' . "\n" .
  114 -              '    payment_value = document.checkout_payment.payment.value;' . "\n" .
  115 -              '  } else if (document.checkout_payment.payment.value) {' . "\n" .
  116 -              '    payment_value = document.checkout_payment.payment.value;' . "\n" .
   198+              '  } else if (document.checkout_payment.payment_method.checked) {' . "\n" .
   199+              '    payment_value = document.checkout_payment.payment_method.value;' . "\n" .
   200+              '  } else if (document.checkout_payment.payment_method.value) {' . "\n" .
   201+              '    payment_value = document.checkout_payment.payment_method.value;' . "\n" .
117202               '  }' . "\n\n";
  118203 
  119204         foreach ($this->_modules as $module) {
<> 120 -          if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
  121 -            $js .= $GLOBALS['osC_Payment_' . $module]->javascript_validation();
   205+          if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
   206+            $js .= $GLOBALS['osC_Payment_' . $module]->getJavascriptBlock();
122207           }
  123208         }
  124209 
     
 !
143228       $selection_array = array();
  144229 
  145230       foreach ($this->_modules as $module) {
<> 146 -        if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
   231+        if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
147232           $selection = $GLOBALS['osC_Payment_' . $module]->selection();
  148233           if (is_array($selection)) $selection_array[] = $selection;
  149234         }
     
 !
154239 
  155240     function pre_confirmation_check() {
  156241       if (is_array($this->_modules)) {
<> 157 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
   242+        if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
158243           $GLOBALS[$this->selected_module]->pre_confirmation_check();
  159244         }
  160245       }
  161246     }
  162247 
  163248     function confirmation() {
  164249       if (is_array($this->_modules)) {
<> 165 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
   250+        if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
166251           return $GLOBALS[$this->selected_module]->confirmation();
  167252         }
  168253       }
  169254     }
  170255 
  171256     function process_button() {
  172257       if (is_array($this->_modules)) {
<> 173 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
   258+        if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
174259           return $GLOBALS[$this->selected_module]->process_button();
  175260         }
  176261       }
  177262     }
  178263 
<> 179 -    function before_process() {
   264+    function process() {
180265       if (is_array($this->_modules)) {
<> 181 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
  182 -          return $GLOBALS[$this->selected_module]->before_process();
   266+        if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
   267+          return $GLOBALS[$this->selected_module]->process();
183268         }
  184269       }
  185270     }
  186271 
<> 187 -    function after_process() {
  188 -      if (is_array($this->_modules)) {
  189 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
  190 -          return $GLOBALS[$this->selected_module]->after_process();
  191 -        }
  192 -      }
  193 -    }
  194 -
195272     function get_error() {
  196273       if (is_array($this->_modules)) {
<> 197 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
   274+        if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
198275           return $GLOBALS[$this->selected_module]->get_error();
  199276         }
  200277       }
  201278     }
  202279 
  203280     function hasActionURL() {
  204281       if (is_array($this->_modules)) {
<> 205 -        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) {
   282+        if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
206283           if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) {
  207284             return true;
  208285           }
     
 !
223300         $has_active = false;
  224301 
  225302         foreach ($this->_modules as $module) {
<> 226 -          if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
   303+          if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
227304             $has_active = true;
  228305             break;
  229306           }
     
 !
240317         $active = 0;
  241318 
  242319         foreach ($this->_modules as $module) {
<> 243 -          if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) {
   320+          if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
244321             $active++;
  245322           }
  246323         }
     
 !
249326       return $active;
  250327     }
  251328 
<> 252 -    function hasKeys() {
  253 -      static $has_keys;
  254 -
  255 -      if (isset($has_keys) === false) {
  256 -        $has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
  257 -      }
  258 -
  259 -      return $has_keys;
  260 -    }
  261 -
  262 -    function install() {
  263 -      global $osC_Database, $osC_Language;
  264 -
  265 -      $Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
  266 -      $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
  267 -      $Qinstall->bindValue(':title', $this->_title);
  268 -      $Qinstall->bindValue(':code', $this->_code);
  269 -      $Qinstall->bindValue(':author_name', $this->_author_name);
  270 -      $Qinstall->bindValue(':author_www', $this->_author_www);
  271 -      $Qinstall->bindValue(':modules_group', $this->_group);
  272 -      $Qinstall->execute();
  273 -
  274 -      foreach ($osC_Language->getAll() as $key => $value) {
  275 -        if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
  276 -          foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
  277 -            $Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
  278 -            $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
  279 -            $Qcheck->bindValue(':definition_key', $def['key']);
  280 -            $Qcheck->bindValue(':content_group', $def['group']);
  281 -            $Qcheck->bindInt(':languages_id', $value['id']);
  282 -            $Qcheck->execute();
  283 -
  284 -            if ($Qcheck->numberOfRows() === 1) {
  285 -              $Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
  286 -            } else {
  287 -              $Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
  288 -            }
  289 -            $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
  290 -            $Qdef->bindInt(':languages_id', $value['id']);
  291 -            $Qdef->bindValue(':content_group', $def['group']);
  292 -            $Qdef->bindValue(':definition_key', $def['key']);
  293 -            $Qdef->bindValue(':definition_value', $def['value']);
  294 -            $Qdef->execute();
  295 -          }
  296 -        }
  297 -      }
  298 -
  299 -      osC_Cache::clear('languages');
  300 -    }
  301 -
  302 -    function remove() {
  303 -      global $osC_Database, $osC_Language;
  304 -
  305 -      $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
  306 -      $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
  307 -      $Qdel->bindValue(':code', $this->_code);
  308 -      $Qdel->bindValue(':modules_group', $this->_group);
  309 -      $Qdel->execute();
  310 -
  311 -      if ($this->hasKeys()) {
  312 -        $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
  313 -        $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
  314 -        $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
  315 -        $Qdel->execute();
  316 -      }
  317 -
  318 -      if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
  319 -        foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
  320 -          $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
  321 -          $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
  322 -          $Qdel->bindValue(':definition_key', $def['key']);
  323 -          $Qdel->bindValue(':content_group', $def['group']);
  324 -          $Qdel->execute();
  325 -        }
  326 -
  327 -        osC_Cache::clear('languages');
  328 -      }
  329 -    }
  330 -
<_ 331329     function _usortModules($a, $b) {
  332330       if ($GLOBALS['osC_Payment_' . $a]->getSortOrder() == $GLOBALS['osC_Payment_' . $b]->getSortOrder()) {
  333331         return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->getTitle(), $GLOBALS['osC_Payment_' . $a]->getTitle());