Quick Search:

View

Revision:

Diff

Diff from 383 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 383 2006-01-09 16:35:46Z hpdl $
hpdl
1
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 = '') {
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
37         for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
hpdl
383
38           include('includes/languages/' . $osC_Language->getDirectory() . '/modules/payment/' . $include_modules[$i]['file']);
hpdl
368
39           include('includes/modules/payment/' . $include_modules[$i]['file']);
hpdl
1
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
hpdl
146
46 // $_POST['payment_mod_sel'] value which will be empty (no radio button selection possible)
hpdl
368
47         if ( (tep_count_payment_modules() == 1) && (!isset($GLOBALS[$_SESSION['payment']]) || (isset($GLOBALS[$_SESSION['payment']]) && !is_object($GLOBALS[$_SESSION['payment']]))) ) {
48           $_SESSION['payment'] = $include_modules[0]['class'];
hpdl
1
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 (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
69           if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
70             $GLOBALS[$this->selected_module]->update_status();
71           }
72         }
73       }
74     }
75
76     function javascript_validation() {
77       $js = '';
78       if (is_array($this->modules)) {
hpdl
368
79         $js = '<script type="text/javascript"><!-- ' . "\n" .
hpdl
1
80               'function check_form() {' . "\n" .
81               '  var error = 0;' . "\n" .
82               '  var error_message = "' . JS_ERROR . '";' . "\n" .
83               '  var payment_value = null;' . "\n" .
84               '  if (document.checkout_payment.payment.length) {' . "\n" .
85               '    for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" .
86               '      if (document.checkout_payment.payment[i].checked) {' . "\n" .
87               '        payment_value = document.checkout_payment.payment[i].value;' . "\n" .
88               '      }' . "\n" .
89               '    }' . "\n" .
90               '  } else if (document.checkout_payment.payment.checked) {' . "\n" .
91               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
92               '  } else if (document.checkout_payment.payment.value) {' . "\n" .
93               '    payment_value = document.checkout_payment.payment.value;' . "\n" .
94               '  }' . "\n\n";
95
96         reset($this->modules);
97         while (list(, $value) = each($this->modules)) {
98           $class = substr($value, 0, strrpos($value, '.'));
99           if ($GLOBALS[$class]->enabled) {
100             $js .= $GLOBALS[$class]->javascript_validation();
101           }
102         }
103
104         $js .= "\n" . '  if (payment_value == null) {' . "\n" .
105                '    error_message = error_message + "' . JS_ERROR_NO_PAYMENT_MODULE_SELECTED . '";' . "\n" .
106                '    error = 1;' . "\n" .
107                '  }' . "\n\n" .
108                '  if (error == 1) {' . "\n" .
109                '    alert(error_message);' . "\n" .
110                '    return false;' . "\n" .
111                '  } else {' . "\n" .
112                '    return true;' . "\n" .
113                '  }' . "\n" .
114                '}' . "\n" .
115                '//--></script>' . "\n";
116       }
117
118       return $js;
119     }
120
121     function selection() {
122       $selection_array = array();
123
124       if (is_array($this->modules)) {
125         reset($this->modules);
126         while (list(, $value) = each($this->modules)) {
127           $class = substr($value, 0, strrpos($value, '.'));
128           if ($GLOBALS[$class]->enabled) {
129             $selection = $GLOBALS[$class]->selection();
130             if (is_array($selection)) $selection_array[] = $selection;
131           }
132         }
133       }
134
135       return $selection_array;
136     }
137
138     function pre_confirmation_check() {
139       if (is_array($this->modules)) {
140         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
141           $GLOBALS[$this->selected_module]->pre_confirmation_check();
142         }
143       }
144     }
145
146     function confirmation() {
147       if (is_array($this->modules)) {
148         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
149           return $GLOBALS[$this->selected_module]->confirmation();
150         }
151       }
152     }
153
154     function process_button() {
155       if (is_array($this->modules)) {
156         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
157           return $GLOBALS[$this->selected_module]->process_button();
158         }
159       }
160     }
161
162     function before_process() {
163       if (is_array($this->modules)) {
164         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
165           return $GLOBALS[$this->selected_module]->before_process();
166         }
167       }
168     }
169
170     function after_process() {
171       if (is_array($this->modules)) {
172         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
173           return $GLOBALS[$this->selected_module]->after_process();
174         }
175       }
176     }
177
178     function get_error() {
179       if (is_array($this->modules)) {
180         if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
181           return $GLOBALS[$this->selected_module]->get_error();
182         }
183       }
184     }
185   }
186 ?>