hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
143
|
3
|
$Id: payment.php 486 2006-04-17 23:39:28Z 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
|
486
|
13
|
include(dirname(__FILE__) . '/credit_card.php');
|
|
14
|
|
hpdl
|
421
|
15
|
class osC_Payment {
|
hpdl
|
434
|
16
|
var $selected_module;
|
hpdl
|
1
|
17
|
|
hpdl
|
434
|
18
|
var $_modules = array(),
|
|
19
|
$_group = 'payment';
|
hpdl
|
432
|
20
|
|
hpdl
|
1
|
21
|
// class constructor
|
hpdl
|
421
|
22
|
function osC_Payment($module = '') {
|
hpdl
|
431
|
23
|
global $osC_Database, $osC_Language;
|
hpdl
|
377
|
24
|
|
hpdl
|
431
|
25
|
$Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "payment"');
|
|
26
|
$Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
27
|
$Qmodules->setCache('modules-payment');
|
|
28
|
$Qmodules->execute();
|
hpdl
|
1
|
29
|
|
hpdl
|
431
|
30
|
while ($Qmodules->next()) {
|
hpdl
|
434
|
31
|
$this->_modules[] = $Qmodules->value('code');
|
hpdl
|
431
|
32
|
}
|
hpdl
|
1
|
33
|
|
hpdl
|
431
|
34
|
$Qmodules->freeResult();
|
hpdl
|
1
|
35
|
|
hpdl
|
434
|
36
|
if (empty($this->_modules) === false) {
|
|
37
|
if ((empty($module) === false) && in_array($module, $this->_modules)) {
|
|
38
|
$this->_modules = array($module);
|
hpdl
|
431
|
39
|
$this->selected_module = 'osC_Payment_' . $module;
|
hpdl
|
1
|
40
|
}
|
|
41
|
|
hpdl
|
404
|
42
|
$osC_Language->load('modules-payment');
|
|
43
|
|
hpdl
|
434
|
44
|
foreach ($this->_modules as $modules) {
|
hpdl
|
431
|
45
|
include('includes/modules/payment/' . $modules . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
|
hpdl
|
1
|
46
|
|
hpdl
|
431
|
47
|
$module_class = 'osC_Payment_' . $modules;
|
hpdl
|
1
|
48
|
|
hpdl
|
431
|
49
|
$GLOBALS[$module_class] = new $module_class();
|
hpdl
|
1
|
50
|
}
|
|
51
|
|
hpdl
|
434
|
52
|
usort($this->_modules, array('osC_Payment', '_usortModules'));
|
hpdl
|
431
|
53
|
|
hpdl
|
434
|
54
|
if ( (tep_not_null($module)) && (in_array($module, $this->_modules)) && (isset($GLOBALS['osC_Payment_' . $module]->form_action_url)) ) {
|
hpdl
|
431
|
55
|
$this->form_action_url = $GLOBALS['osC_Payment_' . $module]->form_action_url;
|
hpdl
|
1
|
56
|
}
|
|
57
|
}
|
|
58
|
}
|
|
59
|
|
|
60
|
// class methods
|
hpdl
|
486
|
61
|
function sendTransactionToGateway($url, $parameters, $header='', $method='post') {
|
|
62
|
if (empty($header) || (is_array($header) === false)) {
|
|
63
|
$header = array();
|
|
64
|
}
|
|
65
|
|
|
66
|
$result = '';
|
|
67
|
|
|
68
|
$server = parse_url($url);
|
|
69
|
|
|
70
|
if (isset($server['port']) === false) {
|
|
71
|
$server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
|
|
72
|
}
|
|
73
|
|
|
74
|
if (isset($server['path']) === false) {
|
|
75
|
$server['path'] = '/';
|
|
76
|
}
|
|
77
|
|
|
78
|
if (isset($server['user']) && isset($server['pass'])) {
|
|
79
|
$header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
|
|
80
|
}
|
|
81
|
|
|
82
|
|
|
83
|
$curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
|
|
84
|
curl_setopt($curl, CURLOPT_PORT, $server['port']);
|
|
85
|
|
|
86
|
if (empty($header) === false) {
|
|
87
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
88
|
}
|
|
89
|
|
|
90
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
91
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
92
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
93
|
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
|
|
94
|
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
|
|
95
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
96
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
|
|
97
|
$result = curl_exec($curl);
|
|
98
|
curl_close($curl);
|
|
99
|
|
|
100
|
/*
|
|
101
|
exec('/usr/bin/curl -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k ' . (empty($header) === false ? '-H ' . escapeshellarg(implode("\r\n", $header)) : ''), $result);
|
|
102
|
$result = implode("\n", $result);
|
|
103
|
*/
|
|
104
|
/*
|
|
105
|
if ($fp = @fsockopen(($server['scheme'] == 'https' ? 'ssl' : $server['scheme']) . '://' . $server['host'], $server['port'])) {
|
|
106
|
@fputs($fp, 'POST ' . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . ' HTTP/1.1' . "\r\n" .
|
|
107
|
'Host: ' . $server['host'] . "\r\n" .
|
|
108
|
'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
|
109
|
'Content-length: ' . strlen($parameters) . "\r\n" .
|
|
110
|
(empty($header) === false ? implode("\r\n", $header) . "\r\n" : '') .
|
|
111
|
'Connection: close' . "\r\n\r\n" .
|
|
112
|
$parameters . "\r\n\r\n");
|
|
113
|
|
|
114
|
$result = @stream_get_contents($fp);
|
|
115
|
|
|
116
|
@fclose($fp);
|
|
117
|
|
|
118
|
$result = trim(substr($result, strpos($result, "\r\n\r\n", strpos(strtolower($result), 'content-length:'))));
|
|
119
|
}
|
|
120
|
*/
|
|
121
|
|
|
122
|
return $result;
|
|
123
|
}
|
|
124
|
|
hpdl
|
432
|
125
|
function getCode() {
|
|
126
|
return $this->_code;
|
|
127
|
}
|
|
128
|
|
|
129
|
function getTitle() {
|
|
130
|
return $this->_title;
|
|
131
|
}
|
|
132
|
|
|
133
|
function getDescription() {
|
|
134
|
return $this->_description;
|
|
135
|
}
|
|
136
|
|
hpdl
|
486
|
137
|
function getMethodTitle() {
|
|
138
|
return $this->_method_title;
|
|
139
|
}
|
|
140
|
|
|
141
|
function isEnabled() {
|
hpdl
|
432
|
142
|
return $this->_status;
|
|
143
|
}
|
|
144
|
|
|
145
|
function getSortOrder() {
|
|
146
|
return $this->_sort_order;
|
|
147
|
}
|
|
148
|
|
hpdl
|
1
|
149
|
/* The following method is needed in the checkout_confirmation.php page
|
|
150
|
due to a chicken and egg problem with the payment class and order class.
|
|
151
|
The payment modules needs the order destination data for the dynamic status
|
|
152
|
feature, and the order class needs the payment module title.
|
|
153
|
The following method is a work-around to implementing the method in all
|
|
154
|
payment modules available which would break the modules in the contributions
|
|
155
|
section. This should be looked into again post 2.2.
|
|
156
|
*/
|
|
157
|
function update_status() {
|
hpdl
|
434
|
158
|
if (is_array($this->_modules)) {
|
hpdl
|
1
|
159
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
|
|
160
|
if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
|
|
161
|
$GLOBALS[$this->selected_module]->update_status();
|
|
162
|
}
|
|
163
|
}
|
|
164
|
}
|
|
165
|
}
|
|
166
|
|
|
167
|
function javascript_validation() {
|
hpdl
|
387
|
168
|
global $osC_Language;
|
|
169
|
|
hpdl
|
1
|
170
|
$js = '';
|
hpdl
|
434
|
171
|
if (is_array($this->_modules)) {
|
hpdl
|
241
|
172
|
$js = '<script type="text/javascript">
|
hpdl
|
1
|
173
|
|
|
174
|
|
hpdl
|
387
|
175
|
|
hpdl
|
1
|
176
|
|
hpdl
|
486
|
177
|
|
|
178
|
|
|
179
|
|
|
180
|
|
hpdl
|
1
|
181
|
|
|
182
|
|
hpdl
|
486
|
183
|
|
|
184
|
|
|
185
|
|
|
186
|
|
hpdl
|
1
|
187
|
|
|
188
|
|
hpdl
|
434
|
189
|
|
hpdl
|
486
|
190
|
|
hpdl
|
431
|
191
|
|
hpdl
|
1
|
192
|
|
|
193
|
|
|
194
|
|
|
195
|
|
hpdl
|
390
|
196
|
|
hpdl
|
1
|
197
|
|
|
198
|
|
|
199
|
|
|
200
|
|
|
201
|
|
|
202
|
|
|
203
|
|
|
204
|
|
|
205
|
|
|
206
|
</script>' . "\n";
|
|
207
|
}
|
|
208
|
|
|
209
|
return $js;
|
|
210
|
}
|
|
211
|
|
|
212
|
function selection() {
|
|
213
|
$selection_array = array();
|
|
214
|
|
hpdl
|
434
|
215
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
216
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
217
|
$selection = $GLOBALS['osC_Payment_' . $module]->selection();
|
|
218
|
if (is_array($selection)) $selection_array[] = $selection;
|
hpdl
|
1
|
219
|
}
|
|
220
|
}
|
|
221
|
|
|
222
|
return $selection_array;
|
|
223
|
}
|
|
224
|
|
|
225
|
function pre_confirmation_check() {
|
hpdl
|
434
|
226
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
227
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
228
|
$GLOBALS[$this->selected_module]->pre_confirmation_check();
|
|
229
|
}
|
|
230
|
}
|
|
231
|
}
|
|
232
|
|
|
233
|
function confirmation() {
|
hpdl
|
434
|
234
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
235
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
236
|
return $GLOBALS[$this->selected_module]->confirmation();
|
|
237
|
}
|
|
238
|
}
|
|
239
|
}
|
|
240
|
|
|
241
|
function process_button() {
|
hpdl
|
434
|
242
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
243
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
244
|
return $GLOBALS[$this->selected_module]->process_button();
|
|
245
|
}
|
|
246
|
}
|
|
247
|
}
|
|
248
|
|
|
249
|
function before_process() {
|
hpdl
|
434
|
250
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
251
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
252
|
return $GLOBALS[$this->selected_module]->before_process();
|
|
253
|
}
|
|
254
|
}
|
|
255
|
}
|
|
256
|
|
|
257
|
function after_process() {
|
hpdl
|
434
|
258
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
259
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
260
|
return $GLOBALS[$this->selected_module]->after_process();
|
|
261
|
}
|
|
262
|
}
|
|
263
|
}
|
|
264
|
|
|
265
|
function get_error() {
|
hpdl
|
434
|
266
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
267
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
268
|
return $GLOBALS[$this->selected_module]->get_error();
|
|
269
|
}
|
|
270
|
}
|
|
271
|
}
|
hpdl
|
431
|
272
|
|
hpdl
|
434
|
273
|
function hasActionURL() {
|
|
274
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
275
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
434
|
276
|
if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) {
|
|
277
|
return true;
|
|
278
|
}
|
|
279
|
}
|
|
280
|
}
|
|
281
|
|
|
282
|
return false;
|
|
283
|
}
|
|
284
|
|
|
285
|
function getActionURL() {
|
|
286
|
return $GLOBALS[$this->selected_module]->form_action_url;
|
|
287
|
}
|
|
288
|
|
hpdl
|
431
|
289
|
function hasActive() {
|
|
290
|
static $has_active;
|
|
291
|
|
|
292
|
if (isset($has_active) === false) {
|
|
293
|
$has_active = false;
|
|
294
|
|
hpdl
|
434
|
295
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
296
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
297
|
$has_active = true;
|
|
298
|
break;
|
|
299
|
}
|
|
300
|
}
|
|
301
|
}
|
|
302
|
|
|
303
|
return $has_active;
|
|
304
|
}
|
|
305
|
|
|
306
|
function numberOfActive() {
|
|
307
|
static $active;
|
|
308
|
|
|
309
|
if (isset($active) === false) {
|
|
310
|
$active = 0;
|
|
311
|
|
hpdl
|
434
|
312
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
313
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
314
|
$active++;
|
|
315
|
}
|
|
316
|
}
|
|
317
|
}
|
|
318
|
|
|
319
|
return $active;
|
|
320
|
}
|
|
321
|
|
|
322
|
function hasKeys() {
|
|
323
|
static $has_keys;
|
|
324
|
|
|
325
|
if (isset($has_keys) === false) {
|
|
326
|
$has_keys = (sizeof($this->getKeys()) > 0) ? true : false;
|
|
327
|
}
|
|
328
|
|
|
329
|
return $has_keys;
|
|
330
|
}
|
|
331
|
|
hpdl
|
486
|
332
|
function getPostTransactionActions($history) {
|
|
333
|
return false;
|
|
334
|
}
|
|
335
|
|
hpdl
|
431
|
336
|
function install() {
|
|
337
|
global $osC_Database, $osC_Language;
|
|
338
|
|
|
339
|
$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)');
|
|
340
|
$Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
341
|
$Qinstall->bindValue(':title', $this->_title);
|
|
342
|
$Qinstall->bindValue(':code', $this->_code);
|
|
343
|
$Qinstall->bindValue(':author_name', $this->_author_name);
|
|
344
|
$Qinstall->bindValue(':author_www', $this->_author_www);
|
|
345
|
$Qinstall->bindValue(':modules_group', $this->_group);
|
|
346
|
$Qinstall->execute();
|
|
347
|
|
|
348
|
foreach ($osC_Language->getAll() as $key => $value) {
|
|
349
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
350
|
foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
351
|
$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');
|
|
352
|
$Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
353
|
$Qcheck->bindValue(':definition_key', $def['key']);
|
|
354
|
$Qcheck->bindValue(':content_group', $def['group']);
|
|
355
|
$Qcheck->bindInt(':languages_id', $value['id']);
|
|
356
|
$Qcheck->execute();
|
|
357
|
|
|
358
|
if ($Qcheck->numberOfRows() === 1) {
|
|
359
|
$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');
|
|
360
|
} else {
|
|
361
|
$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)');
|
|
362
|
}
|
|
363
|
$Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
364
|
$Qdef->bindInt(':languages_id', $value['id']);
|
|
365
|
$Qdef->bindValue(':content_group', $def['group']);
|
|
366
|
$Qdef->bindValue(':definition_key', $def['key']);
|
|
367
|
$Qdef->bindValue(':definition_value', $def['value']);
|
|
368
|
$Qdef->execute();
|
|
369
|
}
|
|
370
|
}
|
|
371
|
}
|
|
372
|
|
|
373
|
osC_Cache::clear('languages');
|
|
374
|
}
|
|
375
|
|
|
376
|
function remove() {
|
|
377
|
global $osC_Database, $osC_Language;
|
|
378
|
|
|
379
|
$Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group');
|
|
380
|
$Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
381
|
$Qdel->bindValue(':code', $this->_code);
|
|
382
|
$Qdel->bindValue(':modules_group', $this->_group);
|
|
383
|
$Qdel->execute();
|
|
384
|
|
|
385
|
if ($this->hasKeys()) {
|
|
386
|
$Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")');
|
|
387
|
$Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION);
|
|
388
|
$Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys()));
|
|
389
|
$Qdel->execute();
|
|
390
|
}
|
|
391
|
|
|
392
|
if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) {
|
|
393
|
foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) {
|
|
394
|
$Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group');
|
|
395
|
$Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS);
|
|
396
|
$Qdel->bindValue(':definition_key', $def['key']);
|
|
397
|
$Qdel->bindValue(':content_group', $def['group']);
|
|
398
|
$Qdel->execute();
|
|
399
|
}
|
|
400
|
|
|
401
|
osC_Cache::clear('languages');
|
|
402
|
}
|
|
403
|
}
|
|
404
|
|
|
405
|
function _usortModules($a, $b) {
|
hpdl
|
432
|
406
|
if ($GLOBALS['osC_Payment_' . $a]->getSortOrder() == $GLOBALS['osC_Payment_' . $b]->getSortOrder()) {
|
|
407
|
return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->getTitle(), $GLOBALS['osC_Payment_' . $a]->getTitle());
|
hpdl
|
431
|
408
|
}
|
|
409
|
|
hpdl
|
432
|
410
|
return ($GLOBALS['osC_Payment_' . $a]->getSortOrder() < $GLOBALS['osC_Payment_' . $b]->getSortOrder()) ? -1 : 1;
|
hpdl
|
431
|
411
|
}
|
hpdl
|
1
|
412
|
}
|
|
413
|
?>
|