Quick Search:

View

Revision:

Diff

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