[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 payment.php

Zen Cart 源代码 payment.php




下载文件

文件名: payment.php
文件类型: PHP文件
文件大小: 10.86 KiB
MD5: 5afc8ddb705df154c64996b8a708d045

payment.php - 关闭高亮
  1. <?php
  2. /**
  3.  * Payment Class.
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2012 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version GIT: $Id: Author: DrByte  Tue Aug 28 17:40:54 2012 -0400 Modified in v1.5.1 $
  10.  */
  11. if (!defined('IS_ADMIN_FLAG')) {
  12.   die('Illegal Access');
  13. }
  14. /**
  15.  * Payment Class.
  16.  * This class interfaces with various payment modules
  17.  *
  18.  * @package classes
  19.  */
  20. class payment extends base {
  21.   var $modules, $selected_module;
  22.  
  23.   // class constructor
  24.   function payment($module = '') {
  25.     global $PHP_SELF, $language, $credit_covers, $messageStack;
  26.  
  27.     if (defined('MODULE_PAYMENT_INSTALLED') && zen_not_null(MODULE_PAYMENT_INSTALLED)) {
  28.       $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);
  29.  
  30.       $include_modules = array();
  31.  
  32.       if ( (zen_not_null($module)) && (in_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
  33.         $this->selected_module = $module;
  34.  
  35.         $include_modules[] = array('class' => $module, 'file' => $module . '.php');
  36.       } else {
  37.         reset($this->modules);
  38.  
  39.         // Free Payment Only shows
  40.         if (zen_get_configuration_key_value('MODULE_PAYMENT_FREECHARGER_STATUS') and ($_SESSION['cart']->show_total()==0 and $_SESSION['shipping']['cost']== 0)) {
  41.           $this->selected_module = $module;
  42.           if (file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . '/payment/' . 'freecharger.php')) {
  43.             $include_modules[] = array('class'=> 'freecharger', 'file' => 'freecharger.php');
  44.           }
  45.         } else {
  46.           // All Other Payment Modules show
  47.           while (list(, $value) = each($this->modules)) {
  48.             // double check that the module really exists before adding to the array
  49.             if (file_exists(DIR_FS_CATALOG . DIR_WS_MODULES . '/payment/' . $value)) {
  50.               $class = substr($value, 0, strrpos($value, '.'));
  51.               // Don't show Free Payment Module
  52.               if ($class !='freecharger') {
  53.                 $include_modules[] = array('class' => $class, 'file' => $value);
  54.               }
  55.             }
  56.           }
  57.         }
  58.       }
  59.  
  60.       for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  61.         //          include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/' . $include_modules[$i]['file']);
  62.         $lang_file = zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', $include_modules[$i]['file'], 'false');
  63.         if (@file_exists($lang_file)) {
  64.           include_once($lang_file);
  65.         } else {
  66.           if (IS_ADMIN_FLAG === false && is_object($messageStack)) {
  67.             $messageStack->add('checkout_payment', WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
  68.           } else {
  69.             $messageStack->add_session(WARNING_COULD_NOT_LOCATE_LANG_FILE . $lang_file, 'caution');
  70.           }
  71.         }
  72.         include_once(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']);
  73.  
  74.         $this->paymentClass = new $include_modules[$i]['class'];
  75.         $this->notify('NOTIFY_PAYMENT_MODULE_ENABLE');
  76.         if ($this->paymentClass->enabled)
  77.         {
  78.           $GLOBALS[$include_modules[$i]['class']] = $this->paymentClass;
  79.         } else {
  80.           unset($include_modules[$i]);
  81.         }
  82.       }
  83.       $include_modules = array_values($include_modules);
  84.       // if there is only one payment method, select it as default because in
  85.       // checkout_confirmation.php the $payment variable is being assigned the
  86.       // $_POST['payment'] value which will be empty (no radio button selection possible)
  87.       if ( (zen_count_payment_modules() == 1) && (!isset($_SESSION['payment']) || (isset($_SESSION['payment']) && !is_object($_SESSION['payment']))) ) {
  88.         if (!isset($credit_covers) || $credit_covers == FALSE) $_SESSION['payment'] = $include_modules[0]['class'];
  89.       }
  90.  
  91.       if ( (zen_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) {
  92.         $this->form_action_url = $GLOBALS[$module]->form_action_url;
  93.       }
  94.     }
  95.   }
  96.  
  97.   // class methods
  98.   /* The following method is needed in the checkout_confirmation.php page
  99.   due to a chicken and egg problem with the payment class and order class.
  100.   The payment modules needs the order destination data for the dynamic status
  101.   feature, and the order class needs the payment module title.
  102.   The following method is a work-around to implementing the method in all
  103.   payment modules available which would break the modules in the contributions
  104.   section. This should be looked into again post 2.2.
  105.   */
  106.   function update_status() {
  107.     if (is_array($this->modules)) {
  108.       if (is_object($GLOBALS[$this->selected_module])) {
  109.         if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
  110.           $GLOBALS[$this->selected_module]->update_status();
  111.         }
  112.       }
  113.     }
  114.   }
  115.  
  116.   function javascript_validation() {
  117.     $js = '';
  118.     if (is_array($this->modules) && sizeof($this->selection()) > 0) {
  119.       $js = '<script language="javascript"  type="text/javascript"><!-- ' . "\n" .
  120.       'function check_form() {' . "\n" .
  121.       '  var error = 0;' . "\n" .
  122.       '  var error_message = "' . JS_ERROR . '";' . "\n" .
  123.       '  var payment_value = null;' . "\n" .
  124.       '  if (document.checkout_payment.payment) {' . "\n" .
  125.       '    if (document.checkout_payment.payment.length) {' . "\n" .
  126.       '      for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
  127.       '        if (document.checkout_payment.payment[i].checked) {' . "\n" .
  128.       '          payment_value = document.checkout_payment.payment[i].value;' . "\n" .
  129.       '        }' . "\n" .
  130.       '      }' . "\n" .
  131.       '    } else if (document.checkout_payment.payment.checked) {' . "\n" .
  132.       '      payment_value = document.checkout_payment.payment.value;' . "\n" .
  133.       '    } else if (document.checkout_payment.payment.value) {' . "\n" .
  134.       '      payment_value = document.checkout_payment.payment.value;' . "\n" .
  135.       '    }' . "\n" .
  136.       '  }' . "\n\n";
  137.  
  138.       reset($this->modules);
  139.       while (list(, $value) = each($this->modules)) {
  140.         $class = substr($value, 0, strrpos($value, '.'));
  141.         if ($GLOBALS[$class]->enabled) {
  142.           $js .= $GLOBALS[$class]->javascript_validation();
  143.         }
  144.       }
  145.  
  146.       $js .= "\n" . '  if (payment_value == null && submitter != 1) {' . "\n" .
  147.       '    error_message = error_message + "' . JS_ERROR_NO_PAYMENT_MODULE_SELECTED . '";' . "\n" .
  148.       '    error = 1;' . "\n" .
  149.       '  }' . "\n\n" .
  150.       '  if (error == 1 && submitter != 1) {' . "\n" .
  151.       '    alert(error_message);' . "\n" .
  152.       '    return false;' . "\n" .
  153.       '  } else {' . "\n" .
  154.       '    return true;' . "\n" .
  155.       '  }' . "\n" .
  156.       '}' . "\n" .
  157.       '//--></script>' . "\n";
  158.     }
  159.  
  160.     return $js;
  161.   }
  162.  
  163.   function selection() {
  164.     $selection_array = array();
  165.     if (is_array($this->modules)) {
  166.       reset($this->modules);
  167.       while (list(, $value) = each($this->modules)) {
  168.         $class = substr($value, 0, strrpos($value, '.'));
  169.         if ($GLOBALS[$class]->enabled) {
  170.           $selection = $GLOBALS[$class]->selection();
  171.           if (is_array($selection)) $selection_array[] = $selection;
  172.         }
  173.       }
  174.     }
  175.     return $selection_array;
  176.   }
  177.   function in_special_checkout() {
  178.     $result = false;
  179.     if (is_array($this->modules)) {
  180.       reset($this->modules);
  181.       while (list(, $value) = each($this->modules)) {
  182.         $class = substr($value, 0, strrpos($value, '.'));
  183.         if ($GLOBALS[$class]->enabled && method_exists($GLOBALS[$class], 'in_special_checkout')) {
  184.           $module_result = $GLOBALS[$class]->in_special_checkout();
  185.           if ($module_result === true) $result = true;
  186.         }
  187.       }
  188.     }
  189.     return $result;
  190.   }
  191.  
  192.   function pre_confirmation_check() {
  193.     global $credit_covers, $payment_modules;
  194.     if (is_array($this->modules)) {
  195.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  196.         if ($credit_covers) {
  197.           $GLOBALS[$this->selected_module]->enabled = false;
  198.           $GLOBALS[$this->selected_module] = NULL;
  199.           $payment_modules = '';
  200.         } else {
  201.           $GLOBALS[$this->selected_module]->pre_confirmation_check();
  202.         }
  203.       }
  204.     }
  205.   }
  206.  
  207.   function confirmation() {
  208.     if (is_array($this->modules)) {
  209.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  210.         return $GLOBALS[$this->selected_module]->confirmation();
  211.       }
  212.     }
  213.   }
  214.  
  215.   function process_button() {
  216.     if (is_array($this->modules)) {
  217.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  218.         return $GLOBALS[$this->selected_module]->process_button();
  219.       }
  220.     }
  221.   }
  222.  
  223.   function before_process() {
  224.     if (is_array($this->modules)) {
  225.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  226.         return $GLOBALS[$this->selected_module]->before_process();
  227.       }
  228.     }
  229.   }
  230.  
  231.   function after_process() {
  232.     if (is_array($this->modules)) {
  233.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  234.         return $GLOBALS[$this->selected_module]->after_process();
  235.       }
  236.     }
  237.   }
  238.  
  239.   function after_order_create($zf_order_id) {
  240.     if (is_array($this->modules)) {
  241.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) && (method_exists($GLOBALS[$this->selected_module], 'after_order_create'))) {
  242.         return $GLOBALS[$this->selected_module]->after_order_create($zf_order_id);
  243.       }
  244.     }
  245.   }
  246.  
  247.   function admin_notification($zf_order_id) {
  248.     if (is_array($this->modules)) {
  249.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) && (method_exists($GLOBALS[$this->selected_module], 'admin_notification'))) {
  250.         return $GLOBALS[$this->selected_module]->admin_notification($zf_order_id);
  251.       }
  252.     }
  253.   }
  254.  
  255.   function get_error() {
  256.     if (is_array($this->modules)) {
  257.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  258.         return $GLOBALS[$this->selected_module]->get_error();
  259.       }
  260.     }
  261.   }
  262.  
  263.   function get_checkout_confirm_form_replacement() {
  264.     if (is_array($this->modules)) {
  265.       if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
  266.         if (method_exists($GLOBALS[$this->selected_module], 'get_checkout_confirm_form_replacement')) {
  267.           return $GLOBALS[$this->selected_module]->get_checkout_confirm_form_replacement();
  268.         }
  269.       }
  270.     }
  271.     return array(false, '');
  272.   }
  273. }
  274.