Quick Search:

View

Revision:

Diff

Diff from 410 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/payment.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
146
3   $Id: payment.php 410 2006-01-26 09:17:09Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
410
8   Copyright (c) 2006 osCommerce
hpdl
1
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 = '') {
hpdl
383
18       global $osC_Language;
19
hpdl
1
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($_SERVER['PHP_SELF'], (strrpos($_SERVER['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
hpdl
410
37         $osC_Language->load('modules-payment');
38
hpdl
1
39         for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
hpdl
368
40           include('includes/modules/payment/' . $include_modules[$i]['file']);
hpdl
1
41
42           $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
43         }
44
45 // if there is only one payment method, select it as default because in
46 // checkout_confirmation.php the $payment variable is being assigned the
hpdl
146
47 // $_POST['payment_mod_sel'] value which will be empty (no radio button selection possible)
hpdl
368
48         if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$_SESSION['payment']]) || (isset($GLOBALS[$_SESSION['payment']]) && !is_object($GLOBALS[$_SESSION['payment']]))) ) {
49           $_SESSION['payment'] = $include_modules[0]['class'];
hpdl
1
50         }
51
52         if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) {
53           $this->form_action_url = $GLOBALS[$module]->form_action_url;
54         }
55       }
56     }
57
58 // class methods
59 /* The following method is needed in the checkout_confirmation.php page
60    due to a chicken and egg problem with the payment class and order class.
61    The payment modules needs the order destination data for the dynamic status
62    feature, and the order class needs the payment module title.
63    The following method is a work-around to implementing the method in all
64    payment modules available which would break the modules in the contributions
65    section. This should be looked into again post 2.2.
66 */
67     function update_status() {
68       if (is_array($this->modules)) {
69         if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
70           if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
71             $GLOBALS[$this->selected_module]->update_status();
72           }
73         }
74       }
75     }
76
77     function javascript_validation() {
hpdl
410
78       global $osC_Language;
79
hpdl
1
80       $js = '';
81       if (is_array($this->modules)) {
hpdl
368
82         $js = '<script type="text/javascript"><!-- ' . "\n" .
hpdl
1
83               'function check_form() {' . "\n" .
84               '  var error = 0;' . "\n" .
hpdl
410
85               '  var error_message = "' . $osC_Language->get('js_error') . '";' . "\n" .
hpdl
1
86               '  var payment_value = null;' . "\n" .
87               '  if (document.checkout_payment.payment.length) {' . "\n" .
88               '    for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
89               '      if (document.checkout_payment.payment[i].checked) {' . "\n" .
90               '        payment_value = document.checkout_payment.payment[i].value;' . "\n" .
91               '      }' . "\n" .
92               '    }' . "\n" .
93               '  } else if (document.checkout_payment.payment.checked) {' . "\n" .
94               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
95               '  } else if (document.checkout_payment.payment.value) {' . "\n" .
96               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
97               '  }' . "\n\n";
98
99         reset($this->modules);
100         while (list(, $value) = each($this->modules)) {
101           $class = substr($value, 0, strrpos($value, '.'));
102           if ($GLOBALS[$class]->enabled) {
103             $js .= $GLOBALS[$class]->javascript_validation();
104           }
105         }
106
107         $js .= "\n" . '  if (payment_value == null) {' . "\n" .
hpdl
410
108                '    error_message = error_message + "' . $osC_Language->get('js_no_payment_module_selected') . '\n";' . "\n" .
hpdl
1
109                '    error = 1;' . "\n" .
110                '  }' . "\n\n" .
111                '  if (error == 1) {' . "\n" .
112                '    alert(error_message);' . "\n" .
113                '    return false;' . "\n" .
114                '  } else {' . "\n" .
115                '    return true;' . "\n" .
116                '  }' . "\n" .
117                '}' . "\n" .
118                '//--></script>' . "\n";
119       }
120
121       return $js;
122     }
123
124     function selection() {
125       $selection_array = array();
126
127       if (is_array($this->modules)) {
128         reset($this->modules);
129         while (list(, $value) = each($this->modules)) {
130           $class = substr($value, 0, strrpos($value, '.'));
131           if ($GLOBALS[$class]->enabled) {
132             $selection = $GLOBALS[$class]->selection();
133             if (is_array($selection)) $selection_array[] = $selection;
134           }
135         }
136       }
137
138       return $selection_array;
139     }
140
141     function pre_confirmation_check() {
142       if (is_array($this->modules)) {
143         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
144           $GLOBALS[$this->selected_module]->pre_confirmation_check();
145         }
146       }
147     }
148
149     function confirmation() {
150       if (is_array($this->modules)) {
151         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
152           return $GLOBALS[$this->selected_module]->confirmation();
153         }
154       }
155     }
156
157     function process_button() {
158       if (is_array($this->modules)) {
159         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
160           return $GLOBALS[$this->selected_module]->process_button();
161         }
162       }
163     }
164
165     function before_process() {
166       if (is_array($this->modules)) {
167         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
168           return $GLOBALS[$this->selected_module]->before_process();
169         }
170       }
171     }
172
173     function after_process() {
174       if (is_array($this->modules)) {
175         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
176           return $GLOBALS[$this->selected_module]->after_process();
177         }
178       }
179     }
180
181     function get_error() {
182       if (is_array($this->modules)) {
183         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
184           return $GLOBALS[$this->selected_module]->get_error();
185         }
186       }
187     }
188   }
189 ?>