[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * Payment Class. 4 * 5 * @package classes 6 * @copyright Copyright 2003-2006 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 $Id: payment.php 5382 2006-12-24 18:22:47Z drbyte $ 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; 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 include_once(zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/payment/', $include_modules[$i]['file'], 'false')); 63 include_once(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']); 64 65 $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class']; 66 } 67 68 // if there is only one payment method, select it as default because in 69 // checkout_confirmation.php the $payment variable is being assigned the 70 // $_POST['payment'] value which will be empty (no radio button selection possible) 71 if ( (zen_count_payment_modules() == 1) && (!isset($_SESSION['payment']) || (isset($_SESSION['payment']) && !is_object($_SESSION['payment']))) ) { 72 if (!$credit_covers) $_SESSION['payment'] = $include_modules[0]['class']; 73 } 74 75 if ( (zen_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) { 76 $this->form_action_url = $GLOBALS[$module]->form_action_url; 77 } 78 } 79 } 80 81 // class methods 82 /* The following method is needed in the checkout_confirmation.php page 83 due to a chicken and egg problem with the payment class and order class. 84 The payment modules needs the order destination data for the dynamic status 85 feature, and the order class needs the payment module title. 86 The following method is a work-around to implementing the method in all 87 payment modules available which would break the modules in the contributions 88 section. This should be looked into again post 2.2. 89 */ 90 function update_status() { 91 if (is_array($this->modules)) { 92 if (is_object($GLOBALS[$this->selected_module])) { 93 if (method_exists($GLOBALS[$this->selected_module], 'update_status')) { 94 $GLOBALS[$this->selected_module]->update_status(); 95 } 96 } 97 } 98 } 99 100 function javascript_validation() { 101 $js = ''; 102 if (is_array($this->modules) && sizeof($this->selection()) > 0) { 103 $js = '<script language="javascript" type="text/javascript"><!-- ' . "\n" . 104 'function check_form() {' . "\n" . 105 ' var error = 0;' . "\n" . 106 ' var error_message = "' . JS_ERROR . '";' . "\n" . 107 ' var payment_value = null;' . "\n" . 108 ' if (document.checkout_payment.payment) {' . "\n" . 109 ' if (document.checkout_payment.payment.length) {' . "\n" . 110 ' for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" . 111 ' if (document.checkout_payment.payment[i].checked) {' . "\n" . 112 ' payment_value = document.checkout_payment.payment[i].value;' . "\n" . 113 ' }' . "\n" . 114 ' }' . "\n" . 115 ' } else if (document.checkout_payment.payment.checked) {' . "\n" . 116 ' payment_value = document.checkout_payment.payment.value;' . "\n" . 117 ' } else if (document.checkout_payment.payment.value) {' . "\n" . 118 ' payment_value = document.checkout_payment.payment.value;' . "\n" . 119 ' }' . "\n" . 120 ' }' . "\n\n"; 121 122 reset($this->modules); 123 while (list(, $value) = each($this->modules)) { 124 $class = substr($value, 0, strrpos($value, '.')); 125 if ($GLOBALS[$class]->enabled) { 126 $js .= $GLOBALS[$class]->javascript_validation(); 127 } 128 } 129 130 $js .= "\n" . ' if (payment_value == null && submitter != 1) {' . "\n" . 131 ' error_message = error_message + "' . JS_ERROR_NO_PAYMENT_MODULE_SELECTED . '";' . "\n" . 132 ' error = 1;' . "\n" . 133 ' }' . "\n\n" . 134 ' if (error == 1 && submitter != 1) {' . "\n" . 135 ' alert(error_message);' . "\n" . 136 ' return false;' . "\n" . 137 ' } else {' . "\n" . 138 ' return true;' . "\n" . 139 ' }' . "\n" . 140 '}' . "\n" . 141 '//--></script>' . "\n"; 142 } 143 144 return $js; 145 } 146 147 function selection() { 148 $selection_array = array(); 149 if (is_array($this->modules)) { 150 reset($this->modules); 151 while (list(, $value) = each($this->modules)) { 152 $class = substr($value, 0, strrpos($value, '.')); 153 if ($GLOBALS[$class]->enabled) { 154 $selection = $GLOBALS[$class]->selection(); 155 if (is_array($selection)) $selection_array[] = $selection; 156 } 157 } 158 } 159 return $selection_array; 160 } 161 function in_special_checkout() { 162 $result = false; 163 if (is_array($this->modules)) { 164 reset($this->modules); 165 while (list(, $value) = each($this->modules)) { 166 $class = substr($value, 0, strrpos($value, '.')); 167 if ($GLOBALS[$class]->enabled && method_exists($GLOBALS[$class], 'in_special_checkout')) { 168 $module_result = $GLOBALS[$class]->in_special_checkout(); 169 if ($module_result === true) $result = true; 170 } 171 } 172 } 173 return $result; 174 } 175 176 function pre_confirmation_check() { 177 global $credit_covers, $payment_modules; 178 if (is_array($this->modules)) { 179 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 180 if ($credit_covers) { 181 $GLOBALS[$this->selected_module]->enabled = false; 182 $GLOBALS[$this->selected_module] = NULL; 183 $payment_modules = ''; 184 } else { 185 $GLOBALS[$this->selected_module]->pre_confirmation_check(); 186 } 187 } 188 } 189 } 190 191 function confirmation() { 192 if (is_array($this->modules)) { 193 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 194 return $GLOBALS[$this->selected_module]->confirmation(); 195 } 196 } 197 } 198 199 function process_button() { 200 if (is_array($this->modules)) { 201 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 202 return $GLOBALS[$this->selected_module]->process_button(); 203 } 204 } 205 } 206 207 function before_process() { 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]->before_process(); 211 } 212 } 213 } 214 215 function after_process() { 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]->after_process(); 219 } 220 } 221 } 222 223 function after_order_create($zf_order_id) { 224 if (is_array($this->modules)) { 225 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) && (method_exists($GLOBALS[$this->selected_module], 'after_order_create'))) { 226 return $GLOBALS[$this->selected_module]->after_order_create($zf_order_id); 227 } 228 } 229 } 230 231 function admin_notification($zf_order_id) { 232 if (is_array($this->modules)) { 233 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) && (method_exists($GLOBALS[$this->selected_module], 'admin_notification'))) { 234 return $GLOBALS[$this->selected_module]->admin_notification($zf_order_id); 235 } 236 } 237 } 238 239 function get_error() { 240 if (is_array($this->modules)) { 241 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 242 return $GLOBALS[$this->selected_module]->get_error(); 243 } 244 } 245 } 246 } 247 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |