Quick Search:

View

Revision:

Diff

Diff from 5 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 /*
3   $Id: payment.php 5 2005-01-31 01:40:15Z hpdl $
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       if (PHP_VERSION < 4.1) {
19         global $_SERVER;
20       }
21
22       global $osC_Session;
23
24       if (defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED)) {
25         $this->modules = explode(';', MODULE_PAYMENT_INSTALLED);
26
27         $include_modules = array();
28
29         if ( (tep_not_null($module)) && (in_array($module . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->modules)) ) {
30           $this->selected_module = $module;
31
32           $include_modules[] = array('class' => $module, 'file' => $module . '.php');
33         } else {
34           reset($this->modules);
35           while (list(, $value) = each($this->modules)) {
36             $class = substr($value, 0, strrpos($value, '.'));
37             $include_modules[] = array('class' => $class, 'file' => $value);
38           }
39         }
40
41         for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
42           include(DIR_WS_LANGUAGES . $osC_Session->value('language') . '/modules/payment/' . $include_modules[$i]['file']);
43           include(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']);
44
45           $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
46         }
47
48 // if there is only one payment method, select it as default because in
49 // checkout_confirmation.php the $payment variable is being assigned the
50 // $_POST['payment'] value which will be empty (no radio button selection possible)
51         if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$osC_Session->value('payment')]) || (isset($GLOBALS[$osC_Session->value('payment')]) && !is_object($GLOBALS[$osC_Session->value('payment')]))) ) {
52           $osC_Session->set('payment', $include_modules[0]['class']);
53         }
54
55         if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS[$module]->form_action_url)) ) {
56           $this->form_action_url = $GLOBALS[$module]->form_action_url;
57         }
58       }
59     }
60
61 // class methods
62 /* The following method is needed in the checkout_confirmation.php page
63    due to a chicken and egg problem with the payment class and order class.
64    The payment modules needs the order destination data for the dynamic status
65    feature, and the order class needs the payment module title.
66    The following method is a work-around to implementing the method in all
67    payment modules available which would break the modules in the contributions
68    section. This should be looked into again post 2.2.
69 */
70     function update_status() {
71       if (is_array($this->modules)) {
72         if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
73           if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
74             $GLOBALS[$this->selected_module]->update_status();
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 ?>