[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文件
文件大小: 11.67 KiB
MD5: 117a3babce859b2f081878529590679a

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