[ Index ] |
|
Code source de osCommerce 2.2ms2-060817 |
1 <?php 2 /* 3 $Id: payment.php,v 1.37 2003/06/09 22:26:32 hpdl Exp $ 4 5 osCommerce, Open Source E-Commerce Solutions 6 http://www.oscommerce.com 7 8 Copyright (c) 2003 osCommerce 9 10 Released under the GNU General Public License 11 */ 12 13 class payment { 14 var $modules, $selected_module; 15 16 // class constructor 17 function payment($module = '') { 18 global $payment, $language, $PHP_SELF; 19 20 if (defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED)) { 21 $this->modules = explode(';', MODULE_PAYMENT_INSTALLED); 22 23 $include_modules = array(); 24 25 if ( (tep_not_null($module)) && (in_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) { 26 $this->selected_module = $module; 27 28 $include_modules[] = array('class' => $module, 'file' => $module . '.php'); 29 } else { 30 reset($this->modules); 31 while (list(, $value) = each($this->modules)) { 32 $class = substr($value, 0, strrpos($value, '.')); 33 $include_modules[] = array('class' => $class, 'file' => $value); 34 } 35 } 36 37 for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) { 38 include(DIR_WS_LANGUAGES . $language . '/modules/payment/' . $include_modules[$i]['file']); 39 include(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']); 40 41 $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class']; 42 } 43 44 // if there is only one payment method, select it as default because in 45 // checkout_confirmation.php the $payment variable is being assigned the 46 // $HTTP_POST_VARS['payment'] value which will be empty (no radio button selection possible) 47 if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$payment]) || (isset($GLOBALS[$payment]) && !is_object($GLOBALS[$payment]))) ) { 48 $payment = $include_modules[0]['class']; 49 } 50 51 if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) { 52 $this->form_action_url = $GLOBALS[$module]->form_action_url; 53 } 54 } 55 } 56 57 // class methods 58 /* The following method is needed in the checkout_confirmation.php page 59 due to a chicken and egg problem with the payment class and order class. 60 The payment modules needs the order destination data for the dynamic status 61 feature, and the order class needs the payment module title. 62 The following method is a work-around to implementing the method in all 63 payment modules available which would break the modules in the contributions 64 section. This should be looked into again post 2.2. 65 */ 66 function update_status() { 67 if (is_array($this->modules)) { 68 if (is_object($GLOBALS[$this->selected_module])) { 69 if (function_exists('method_exists')) { 70 if (method_exists($GLOBALS[$this->selected_module], 'update_status')) { 71 $GLOBALS[$this->selected_module]->update_status(); 72 } 73 } else { // PHP3 compatibility 74 @call_user_method('update_status', $GLOBALS[$this->selected_module]); 75 } 76 } 77 } 78 } 79 80 function javascript_validation() { 81 $js = ''; 82 if (is_array($this->modules)) { 83 $js = '<script language="javascript"><!-- ' . "\n" . 84 'function check_form() {' . "\n" . 85 ' var error = 0;' . "\n" . 86 ' var error_message = "' . JS_ERROR . '";' . "\n" . 87 ' var payment_value = null;' . "\n" . 88 ' if (document.checkout_payment.payment.length) {' . "\n" . 89 ' for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" . 90 ' if (document.checkout_payment.payment[i].checked) {' . "\n" . 91 ' payment_value = document.checkout_payment.payment[i].value;' . "\n" . 92 ' }' . "\n" . 93 ' }' . "\n" . 94 ' } else if (document.checkout_payment.payment.checked) {' . "\n" . 95 ' payment_value = document.checkout_payment.payment.value;' . "\n" . 96 ' } else if (document.checkout_payment.payment.value) {' . "\n" . 97 ' payment_value = document.checkout_payment.payment.value;' . "\n" . 98 ' }' . "\n\n"; 99 100 reset($this->modules); 101 while (list(, $value) = each($this->modules)) { 102 $class = substr($value, 0, strrpos($value, '.')); 103 if ($GLOBALS[$class]->enabled) { 104 $js .= $GLOBALS[$class]->javascript_validation(); 105 } 106 } 107 108 $js .= "\n" . ' if (payment_value == null) {' . "\n" . 109 ' error_message = error_message + "' . JS_ERROR_NO_PAYMENT_MODULE_SELECTED . '";' . "\n" . 110 ' error = 1;' . "\n" . 111 ' }' . "\n\n" . 112 ' if (error == 1) {' . "\n" . 113 ' alert(error_message);' . "\n" . 114 ' return false;' . "\n" . 115 ' } else {' . "\n" . 116 ' return true;' . "\n" . 117 ' }' . "\n" . 118 '}' . "\n" . 119 '//--></script>' . "\n"; 120 } 121 122 return $js; 123 } 124 125 function selection() { 126 $selection_array = array(); 127 128 if (is_array($this->modules)) { 129 reset($this->modules); 130 while (list(, $value) = each($this->modules)) { 131 $class = substr($value, 0, strrpos($value, '.')); 132 if ($GLOBALS[$class]->enabled) { 133 $selection = $GLOBALS[$class]->selection(); 134 if (is_array($selection)) $selection_array[] = $selection; 135 } 136 } 137 } 138 139 return $selection_array; 140 } 141 142 function pre_confirmation_check() { 143 if (is_array($this->modules)) { 144 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 145 $GLOBALS[$this->selected_module]->pre_confirmation_check(); 146 } 147 } 148 } 149 150 function confirmation() { 151 if (is_array($this->modules)) { 152 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 153 return $GLOBALS[$this->selected_module]->confirmation(); 154 } 155 } 156 } 157 158 function process_button() { 159 if (is_array($this->modules)) { 160 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 161 return $GLOBALS[$this->selected_module]->process_button(); 162 } 163 } 164 } 165 166 function before_process() { 167 if (is_array($this->modules)) { 168 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 169 return $GLOBALS[$this->selected_module]->before_process(); 170 } 171 } 172 } 173 174 function after_process() { 175 if (is_array($this->modules)) { 176 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 177 return $GLOBALS[$this->selected_module]->after_process(); 178 } 179 } 180 } 181 182 function get_error() { 183 if (is_array($this->modules)) { 184 if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) { 185 return $GLOBALS[$this->selected_module]->get_error(); 186 } 187 } 188 } 189 } 190 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 19:48:25 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |