hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
143
|
3
|
$Id: payment.php 431 2006-02-15 05:57:09Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
404
|
8
|
Copyright (c) 2006 osCommerce
|
hpdl
|
1
|
9
|
|
|
10
|
Released under the GNU General Public License
|
|
11
|
*/
|
|
12
|
|
hpdl
|
421
|
13
|
class osC_Payment {
|
hpdl
|
1
|
14
|
var $modules, $selected_module;
|
|
15
|
|
|
16
|
// class constructor
|
hpdl
|
421
|
17
|
function osC_Payment($module = '') {
|
hpdl
|
431
|
18
|
global $osC_Database, $osC_Language;
|
hpdl
|
377
|
19
|
|
hpdl
|
431
|
20
|
$Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "payment"');
|
|
21
|
$Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
22
|
$Qmodules->setCache('modules-payment');
|
|
23
|
$Qmodules->execute();
|
hpdl
|
1
|
24
|
|
hpdl
|
431
|
25
|
while ($Qmodules->next()) {
|
|
26
|
$this->modules[] = $Qmodules->value('code');
|
|
27
|
}
|
hpdl
|
1
|
28
|
|
hpdl
|
431
|
29
|
$Qmodules->freeResult();
|
hpdl
|
1
|
30
|
|
hpdl
|
431
|
31
|
if (empty($this->modules) === false) {
|
|
32
|
if ((empty($module) === false) && in_array($module, $this->modules)) {
|
|
33
|
$this->modules = array($module);
|
|
34
|
$this->selected_module = 'osC_Payment_' . $module;
|
hpdl
|
1
|
35
|
}
|
|
36
|
|
hpdl
|
404
|
37
|
$osC_Language->load('modules-payment');
|
|
38
|
|
hpdl
|
431
|
39
|
foreach ($this->modules as $modules) {
|
|
40
|
include('includes/modules/payment/' . $modules . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
|
hpdl
|
1
|
41
|
|
hpdl
|
431
|
42
|
$module_class = 'osC_Payment_' . $modules;
|
hpdl
|
1
|
43
|
|
hpdl
|
431
|
44
|
$GLOBALS[$module_class] = new $module_class();
|
hpdl
|
1
|
45
|
}
|
|
46
|
|
hpdl
|
431
|
47
|
usort($this->modules, array('osC_Payment', '_usortModules'));
|
|
48
|
|
|
49
|
if ( (tep_not_null($module)) && (in_array($module, $this->modules)) && (isset($GLOBALS['osC_Payment_' . $module]->form_action_url)) ) {
|
|
50
|
$this->form_action_url = $GLOBALS['osC_Payment_' . $module]->form_action_url;
|
hpdl
|
1
|
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() {
|
hpdl
|
387
|
75
|
global $osC_Language;
|
|
76
|
|
hpdl
|
1
|
77
|
$js = '';
|
|
78
|
if (is_array($this->modules)) {
|
hpdl
|
241
|
79
|
$js = '<script type="text/javascript">
|
hpdl
|
1
|
80
|
|
|
81
|
|
hpdl
|
387
|
82
|
|
hpdl
|
1
|
83
|
|
|
84
|
|
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
|
|
94
|
|
|
95
|
|
hpdl
|
431
|
96
|
|
|
97
|
|
|
98
|
|
hpdl
|
1
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
hpdl
|
390
|
103
|
|
hpdl
|
1
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
|
109
|
|
|
110
|
|
|
111
|
|
|
112
|
|
|
113
|
</script>' . "\n";
|
|
114
|
}
|
|
115
|
|
|
116
|
return $js;
|
|
117
|
}
|
|
118
|
|
|
119
|
function selection() {
|
|
120
|
$selection_array = array();
|
|
121
|
|
hpdl
|
431
|
122
|
foreach ($this->modules as $module) {
|
|
123
|
if ($GLOBALS['osC_Payment_' . $module]->enabled) {
|
|
124
|
$selection = $GLOBALS['osC_Payment_' . $module]->selection();
|
|
125
|
if (is_array($selection)) $selection_array[] = $selection;
|
hpdl
|
1
|
126
|
}
|
|
127
|
}
|
|
128
|
|
|
129
|
return $selection_array;
|
|
130
|
}
|
|
131
|
|
|
132
|
function pre_confirmation_check() {
|
|
133
|
if (is_array($this->modules)) {
|
|
134
|
if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
|
|
135
|
$GLOBALS[$this->selected_module]->pre_confirmation_check();
|
|
136
|
}
|
|
137
|
}
|
|
138
|
}
|
|
139
|
|
|
140
|
function confirmation() {
|
|
141
|
if (is_array($this->modules)) {
|
|
142
|
if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
|
|
143
|
return $GLOBALS[$this->selected_module]->confirmation();
|
|
144
|
}
|
|
145
|
}
|
|
146
|
}
|
|
147
|
|
|
148
|
function process_button() {
|
|
149
|
if (is_array($this->modules)) {
|
|
150
|
if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
|
|
151
|
return $GLOBALS[$this->selected_module]->process_button();
|
|
152
|
}
|
|
153
|
}
|
|
154
|
}
|
|
155
|
|
|
156
|
function before_process() {
|
|
157
|
if (is_array($this->modules)) {
|
|
158
|
if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
|
|
159
|
return $GLOBALS[$this->selected_module]->before_process();
|
|
160
|
}
|
|
161
|
}
|
|
162
|
}
|
|
163
|
|
|
164
|
function after_process() {
|
|
165
|
if (is_array($this->modules)) {
|
|
166
|
if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
|
|
167
|
return $GLOBALS[$this->selected_module]->after_process();
|
|
168
|
}
|
|
169
|
}
|
|
170
|
}
|
|
171
|
|
|
172
|
function get_error() {
|
|
173
|
if (is_array($this->modules)) {
|
|
174
|
if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
|
|
175
|
return $GLOBALS[$this->selected_module]->get_error();
|
|
176
|
}
|
|
177
|
}
|
|
178
|
}
|
hpdl
|
431
|
179
|
|
|
180
|
function hasActive() {
|
|
181
|
static $has_active;
|
|
182
|
|
|
183
|
if (isset($has_active) === false) {
|
|
184
|
$has_active = false;
|
|
185
|
|
|
186
|
foreach ($this->modules as $module) {
|
|
187
|
if ($GLOBALS['osC_Payment_' . $module]->enabled) {
|
|
188
|
$has_active = true;
|
|
189
|
break;
|
|
190
|
}
|
|
191
|
}
|
|
192
|
}
|
|
193
|
|
|
194
|
return $has_active;
|
|
195
|
}
|
|
196
|
|
|
197
|
function numberOfActive() {
|
|
198
|
static $active;
|
|
199
|
|
|
200
|
if (isset($active) === false) {
|
|
201
|
$active = 0;
|
|
202
|
|
|
203
|
foreach ($this->modules as $module) {
|
|
204
|
if ($GLOBALS['osC_Payment_' . $module]->enabled) {
|
|
205
|
$active++;
|
|
206
|
}
|
|
207
|
}
|
|
208
|
}
|
|
209
|
|
|
210
|
return $active;
|
|
211
|
}
|
|
212
|
|
|
213
|
function hasKeys() {
|
|
214
|
static $has_keys;
|
|
215
|
|
|
216
|
if (isset($has_keys) === false) {
|
|
217
|
$has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
|
|
218
|
}
|
|
219
|
|
|
220
|
return $has_keys;
|
|
221
|
}
|
|
222
|
|
|
223
|
function install() {
|
|
224
|
global $osC_Database, $osC_Language;
|
|
225
|
|
|
226
|
$Qinstall = $osC_Database->query('insert into :table_templates_boxes (title, code, author_name, author_www, modules_group) values (:title, :code, :author_name, :author_www, :modules_group)');
|
|
227
|
$Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
228
|
$Qinstall->bindValue(':title', $this->_title);
|
|
229
|
$Qinstall->bindValue(':code', $this->_code);
|
|
230
|
$Qinstall->bindValue(':author_name', $this->_author_name);
|
|
231
|
$Qinstall->bindValue(':author_www', $this->_author_www);
|
|
232
|
$Qinstall->bindValue(':modules_group', $this->_group);
|
|
233
|
$Qinstall->execute();
|
|
234
|
|
|
235
|
foreach ($osC_Language->getAll() as $key => $value) {
|
|
236
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
237
|
foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
238
|
$Qcheck = $osC_Database->query('select id from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id limit 1');
|
|
239
|
$Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
240
|
$Qcheck->bindValue(':definition_key', $def['key']);
|
|
241
|
$Qcheck->bindValue(':content_group', $def['group']);
|
|
242
|
$Qcheck->bindInt(':languages_id', $value['id']);
|
|
243
|
$Qcheck->execute();
|
|
244
|
|
|
245
|
if ($Qcheck->numberOfRows() === 1) {
|
|
246
|
$Qdef = $osC_Database->query('update :table_languages_definitions set definition_value = :definition_value where definition_key = :definition_key and content_group = :content_group and languages_id = :languages_id');
|
|
247
|
} else {
|
|
248
|
$Qdef = $osC_Database->query('insert into :table_languages_definitions (languages_id, content_group, definition_key, definition_value) values (:languages_id, :content_group, :definition_key, :definition_value)');
|
|
249
|
}
|
|
250
|
$Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
251
|
$Qdef->bindInt(':languages_id', $value['id']);
|
|
252
|
$Qdef->bindValue(':content_group', $def['group']);
|
|
253
|
$Qdef->bindValue(':definition_key', $def['key']);
|
|
254
|
$Qdef->bindValue(':definition_value', $def['value']);
|
|
255
|
$Qdef->execute();
|
|
256
|
}
|
|
257
|
}
|
|
258
|
}
|
|
259
|
|
|
260
|
osC_Cache::clear('languages');
|
|
261
|
}
|
|
262
|
|
|
263
|
function remove() {
|
|
264
|
global $osC_Database, $osC_Language;
|
|
265
|
|
|
266
|
$Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
|
|
267
|
$Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
268
|
$Qdel->bindValue(':code', $this->_code);
|
|
269
|
$Qdel->bindValue(':modules_group', $this->_group);
|
|
270
|
$Qdel->execute();
|
|
271
|
|
|
272
|
if ($this->hasKeys()) {
|
|
273
|
$Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
|
|
274
|
$Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
|
|
275
|
$Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
|
|
276
|
$Qdel->execute();
|
|
277
|
}
|
|
278
|
|
|
279
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
280
|
foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
281
|
$Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
|
|
282
|
$Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
283
|
$Qdel->bindValue(':definition_key', $def['key']);
|
|
284
|
$Qdel->bindValue(':content_group', $def['group']);
|
|
285
|
$Qdel->execute();
|
|
286
|
}
|
|
287
|
|
|
288
|
osC_Cache::clear('languages');
|
|
289
|
}
|
|
290
|
}
|
|
291
|
|
|
292
|
function _usortModules($a, $b) {
|
|
293
|
if ($GLOBALS['osC_Payment_' . $a]->sort_order == $GLOBALS['osC_Payment_' . $b]->sort_order) {
|
|
294
|
return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->title, $GLOBALS['osC_Payment_' . $a]->title);
|
|
295
|
}
|
|
296
|
|
|
297
|
return ($GLOBALS['osC_Payment_' . $a]->sort_order < $GLOBALS['osC_Payment_' . $b]->sort_order) ? -1 : 1;
|
|
298
|
}
|
hpdl
|
1
|
299
|
}
|
|
300
|
?>
|