[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/classes/ -> payment.php (source)

   1  <?php
   2  /*

   3  $Id: payment.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   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  // LINE CHANGED: MOD - Downloads Controller - Added $cart

  19        global $payment, $language, $PHP_SELF, $cart;
  20  
  21        if (defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED)) {
  22  // BOF: MOD - Separate Pricing Per Customer, next line original code

  23  //      $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);

  24          global $sppc_customer_group_id, $customer_id;
  25          if(!tep_session_is_registered('sppc_customer_group_id')) { 
  26            $customer_group_id = '0';
  27          } else {
  28           $customer_group_id = $sppc_customer_group_id;
  29          }
  30          $customer_payment_query = tep_db_query("select IF(c.customers_payment_allowed <> '', c.customers_payment_allowed, cg.group_payment_allowed) as payment_allowed from " . TABLE_CUSTOMERS . " c, " . TABLE_CUSTOMERS_GROUPS . " cg where c.customers_id = '" . $customer_id . "' and cg.customers_group_id =  '" . $customer_group_id . "'");
  31          if ($customer_payment = tep_db_fetch_array($customer_payment_query)  ) {  
  32            if (tep_not_null($customer_payment['payment_allowed'])) {
  33              $temp_payment_array = explode(';', $customer_payment['payment_allowed']);
  34              $installed_modules = explode(';', MODULE_PAYMENT_INSTALLED);
  35              for ($n = 0; $n < sizeof($installed_modules) ; $n++) {
  36  // check to see if a payment method is not de-installed

  37              if ( in_array($installed_modules[$n], $temp_payment_array ) ) {
  38                $payment_array[] = $installed_modules[$n];
  39              }
  40        } // end for loop

  41        $this->modules = $payment_array;
  42            } else {  
  43              $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);
  44            }
  45          } else { // default
  46            $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);
  47          }
  48  // EOF: MOD - Separate Pricing Per Customer

  49          $include_modules = array();
  50  
  51          if ( (tep_not_null($module)) && (in_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
  52            $this->selected_module = $module;
  53  
  54            $include_modules[] = array('class' => $module, 'file' => $module . '.php');
  55          } else {
  56            reset($this->modules);
  57  // BOF: MOD - Downloads Controller - Free Shipping and Payments

  58  // Show either normal payment modules or free payment module when Free Shipping Module is On

  59            // Free Payment Only

  60  
  61            if (tep_get_configuration_key_value('MODULE_PAYMENT_FREECHARGER_STATUS') and ($cart->show_total()==0 and $cart->show_weight==0)) {
  62              $this->selected_module = $module;
  63              $include_modules[] = array('class'=> 'freecharger', 'file' => 'freecharger.php');
  64            } else {
  65              // All Other Payment Modules

  66              while (list(, $value) = each($this->modules)) {
  67                $class = substr($value, 0, strrpos($value, '.'));
  68                // Don't show Free Payment Module

  69                if ($class !='freecharger') {
  70                  $include_modules[] = array('class' => $class, 'file' => $value);
  71                }
  72              }
  73  // EOF: MOD - Downloads Controller

  74            }
  75          }
  76  
  77          for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
  78            include(DIR_WS_LANGUAGES . $language . '/modules/payment/' . $include_modules[$i]['file']);
  79            include(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']);
  80  
  81            $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
  82          }
  83  
  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  // $HTTP_POST_VARS['payment'] value which will be empty (no radio button selection possible)

  87          if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$payment]) || (isset($GLOBALS[$payment]) && !is_object($GLOBALS[$payment]))) ) {
  88            $payment = $include_modules[0]['class'];
  89          }
  90  
  91          if ( (tep_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 (function_exists('method_exists')) {
 110              if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
 111                $GLOBALS[$this->selected_module]->update_status();
 112              }
 113            } else { // PHP3 compatibility
 114              @call_user_method('update_status', $GLOBALS[$this->selected_module]);
 115            }
 116          }
 117        }
 118      }
 119  
 120      function javascript_validation() {
 121        $js = '';
 122        if (is_array($this->modules)) {
 123          $js = '<script language="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.length) {' . "\n" .
 129                '    for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
 130                '      if (document.checkout_payment.payment[i].checked) {' . "\n" .
 131                '        payment_value = document.checkout_payment.payment[i].value;' . "\n" .
 132                '      }' . "\n" .
 133                '    }' . "\n" .
 134                '  } else if (document.checkout_payment.payment.checked) {' . "\n" .
 135                '    payment_value = document.checkout_payment.payment.value;' . "\n" .
 136                '  } else if (document.checkout_payment.payment.value) {' . "\n" .
 137                '    payment_value = document.checkout_payment.payment.value;' . "\n" .
 138                '  }' . "\n\n";
 139  
 140          reset($this->modules);
 141          while (list(, $value) = each($this->modules)) {
 142            $class = substr($value, 0, strrpos($value, '.'));
 143            if ($GLOBALS[$class]->enabled) {
 144              $js .= $GLOBALS[$class]->javascript_validation();
 145            }
 146          }
 147  
 148  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 149          $js .= "\n" . '  if (payment_value == null && submitter != 1) {' . "\n" .
 150                 '    error_message = error_message + "' . JS_ERROR_NO_PAYMENT_MODULE_SELECTED . '";' . "\n" .
 151                 '    error = 1;' . "\n" .
 152                 '  }' . "\n\n" .
 153                 '  if (error == 1 && submitter != 1) {' . "\n" .
 154  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 155                 '    alert(error_message);' . "\n" .
 156                 '    return false;' . "\n" .
 157                 '  } else {' . "\n" .
 158                 '    return true;' . "\n" .
 159                 '  }' . "\n" .
 160                 '}' . "\n" .
 161                 '//--></script>' . "\n";
 162        }
 163  
 164        return $js;
 165      }
 166  
 167      function checkout_initialization_method() {
 168        $initialize_array = array();
 169  
 170        if (is_array($this->modules)) {
 171          reset($this->modules);
 172          while (list(, $value) = each($this->modules)) {
 173            $class = substr($value, 0, strrpos($value, '.'));
 174            if ($GLOBALS[$class]->enabled && method_exists($GLOBALS[$class], 'checkout_initialization_method')) {
 175              $initialize_array[] = $GLOBALS[$class]->checkout_initialization_method();
 176            }
 177          }
 178        }
 179  
 180        return $initialize_array;
 181      }
 182  
 183      function selection() {
 184        $selection_array = array();
 185  
 186        if (is_array($this->modules)) {
 187          reset($this->modules);
 188          while (list(, $value) = each($this->modules)) {
 189            $class = substr($value, 0, strrpos($value, '.'));
 190            if ($GLOBALS[$class]->enabled) {
 191              $selection = $GLOBALS[$class]->selection();
 192              if (is_array($selection)) $selection_array[] = $selection;
 193            }
 194          }
 195        }
 196  
 197        return $selection_array;
 198      }
 199  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 200  // check credit covers was setup to test whether credit covers is set in other parts of the code

 201    function check_credit_covers() {
 202        global $credit_covers;
 203  
 204        return $credit_covers;
 205    }
 206  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 207      function pre_confirmation_check() {
 208  // BOF - MOD: CREDIT CLASS Gift Voucher Contribution

 209        global $credit_covers, $payment_modules;
 210        if (is_array($this->modules)) {
 211          if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
 212            if ($credit_covers) {
 213              $GLOBALS[$this->selected_module]->enabled = false;
 214              $GLOBALS[$this->selected_module] = NULL;
 215              $payment_modules = '';
 216            } else {
 217              $GLOBALS[$this->selected_module]->pre_confirmation_check();
 218            }
 219  // EOF - MOD: CREDIT CLASS Gift Voucher Contribution

 220          }
 221        }
 222      }
 223  
 224      function confirmation() {
 225        if (is_array($this->modules)) {
 226          if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
 227            return $GLOBALS[$this->selected_module]->confirmation();
 228          }
 229        }
 230      }
 231  
 232      function process_button() {
 233        if (is_array($this->modules)) {
 234          if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
 235            return $GLOBALS[$this->selected_module]->process_button();
 236          }
 237        }
 238      }
 239  
 240      function before_process() {
 241        if (is_array($this->modules)) {
 242          if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
 243            return $GLOBALS[$this->selected_module]->before_process();
 244          }
 245        }
 246      }
 247  
 248      function after_process() {
 249        if (is_array($this->modules)) {
 250          if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
 251            return $GLOBALS[$this->selected_module]->after_process();
 252          }
 253        }
 254      }
 255  
 256      function get_error() {
 257        if (is_array($this->modules)) {
 258          if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
 259            return $GLOBALS[$this->selected_module]->get_error();
 260          }
 261        }
 262      }
 263    }
 264  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7