hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
143
|
3
|
$Id: payment.php 1497 2007-03-29 13:40:05Z 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
|
|
hpdl
|
1497
|
10
|
This program is free software; you can redistribute it and/or modify
|
|
11
|
it under the terms of the GNU General Public License v2 (1991)
|
|
12
|
as published by the Free Software Foundation.
|
hpdl
|
1
|
13
|
*/
|
|
14
|
|
hpdl
|
486
|
15
|
include(dirname(__FILE__) . '/credit_card.php');
|
|
16
|
|
hpdl
|
421
|
17
|
class osC_Payment {
|
hpdl
|
434
|
18
|
var $selected_module;
|
hpdl
|
1
|
19
|
|
hpdl
|
434
|
20
|
var $_modules = array(),
|
|
21
|
$_group = 'payment';
|
hpdl
|
432
|
22
|
|
hpdl
|
1
|
23
|
// class constructor
|
hpdl
|
421
|
24
|
function osC_Payment($module = '') {
|
hpdl
|
431
|
25
|
global $osC_Database, $osC_Language;
|
hpdl
|
377
|
26
|
|
hpdl
|
431
|
27
|
$Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "payment"');
|
|
28
|
$Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
|
|
29
|
$Qmodules->setCache('modules-payment');
|
|
30
|
$Qmodules->execute();
|
hpdl
|
1
|
31
|
|
hpdl
|
431
|
32
|
while ($Qmodules->next()) {
|
hpdl
|
434
|
33
|
$this->_modules[] = $Qmodules->value('code');
|
hpdl
|
431
|
34
|
}
|
hpdl
|
1
|
35
|
|
hpdl
|
431
|
36
|
$Qmodules->freeResult();
|
hpdl
|
1
|
37
|
|
hpdl
|
434
|
38
|
if (empty($this->_modules) === false) {
|
|
39
|
if ((empty($module) === false) && in_array($module, $this->_modules)) {
|
|
40
|
$this->_modules = array($module);
|
hpdl
|
431
|
41
|
$this->selected_module = 'osC_Payment_' . $module;
|
hpdl
|
1
|
42
|
}
|
|
43
|
|
hpdl
|
404
|
44
|
$osC_Language->load('modules-payment');
|
|
45
|
|
hpdl
|
434
|
46
|
foreach ($this->_modules as $modules) {
|
hpdl
|
431
|
47
|
include('includes/modules/payment/' . $modules . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
|
hpdl
|
1
|
48
|
|
hpdl
|
431
|
49
|
$module_class = 'osC_Payment_' . $modules;
|
hpdl
|
1
|
50
|
|
hpdl
|
431
|
51
|
$GLOBALS[$module_class] = new $module_class();
|
hpdl
|
1
|
52
|
}
|
|
53
|
|
hpdl
|
434
|
54
|
usort($this->_modules, array('osC_Payment', '_usortModules'));
|
hpdl
|
431
|
55
|
|
hpdl
|
734
|
56
|
if ( (!empty($module)) && (in_array($module, $this->_modules)) && (isset($GLOBALS['osC_Payment_' . $module]->form_action_url)) ) {
|
hpdl
|
431
|
57
|
$this->form_action_url = $GLOBALS['osC_Payment_' . $module]->form_action_url;
|
hpdl
|
1
|
58
|
}
|
|
59
|
}
|
|
60
|
}
|
|
61
|
|
|
62
|
// class methods
|
hpdl
|
523
|
63
|
function sendTransactionToGateway($url, $parameters, $header = '', $method = 'post', $certificate = '') {
|
hpdl
|
607
|
64
|
if (empty($header) || !is_array($header)) {
|
hpdl
|
486
|
65
|
$header = array();
|
|
66
|
}
|
|
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
|
|
hpdl
|
607
|
82
|
$connection_method = 0;
|
hpdl
|
486
|
83
|
|
hpdl
|
607
|
84
|
if (function_exists('curl_init')) {
|
|
85
|
$connection_method = 1;
|
|
86
|
} elseif ( ($server['scheme'] == 'http') || (($server['scheme'] == 'https') && extension_loaded('openssl')) ) {
|
|
87
|
if (function_exists('stream_context_create')) {
|
|
88
|
$connection_method = 3;
|
|
89
|
} else {
|
|
90
|
$connection_method = 2;
|
|
91
|
}
|
hpdl
|
486
|
92
|
}
|
|
93
|
|
hpdl
|
607
|
94
|
$result = '';
|
hpdl
|
523
|
95
|
|
hpdl
|
607
|
96
|
switch ($connection_method) {
|
|
97
|
case 1:
|
|
98
|
$curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
|
|
99
|
curl_setopt($curl, CURLOPT_PORT, $server['port']);
|
hpdl
|
486
|
100
|
|
hpdl
|
607
|
101
|
if (!empty($header)) {
|
|
102
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
|
103
|
}
|
hpdl
|
533
|
104
|
|
hpdl
|
607
|
105
|
if (!empty($certificate)) {
|
|
106
|
curl_setopt($curl, CURLOPT_SSLCERT, $certificate);
|
|
107
|
}
|
hpdl
|
486
|
108
|
|
hpdl
|
607
|
109
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
110
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
111
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
112
|
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
|
|
113
|
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
|
|
114
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
115
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
|
hpdl
|
486
|
116
|
|
hpdl
|
607
|
117
|
$result = curl_exec($curl);
|
hpdl
|
486
|
118
|
|
hpdl
|
607
|
119
|
curl_close($curl);
|
hpdl
|
486
|
120
|
|
hpdl
|
607
|
121
|
break;
|
hpdl
|
533
|
122
|
|
hpdl
|
607
|
123
|
case 2:
|
|
124
|
if ($fp = @fsockopen(($server['scheme'] == 'https' ? 'ssl' : $server['scheme']) . '://' . $server['host'], $server['port'])) {
|
|
125
|
@fputs($fp, 'POST ' . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . ' HTTP/1.1' . "\r\n" .
|
|
126
|
'Host: ' . $server['host'] . "\r\n" .
|
|
127
|
'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
|
128
|
'Content-length: ' . strlen($parameters) . "\r\n" .
|
|
129
|
(!empty($header) ? implode("\r\n", $header) . "\r\n" : '') .
|
|
130
|
'Connection: close' . "\r\n\r\n" .
|
|
131
|
$parameters . "\r\n\r\n");
|
hpdl
|
533
|
132
|
|
hpdl
|
607
|
133
|
$result = @stream_get_contents($fp);
|
hpdl
|
533
|
134
|
|
hpdl
|
607
|
135
|
@fclose($fp);
|
hpdl
|
533
|
136
|
|
hpdl
|
607
|
137
|
$result = trim(substr($result, strpos($result, "\r\n\r\n", strpos(strtolower($result), 'content-length:'))));
|
|
138
|
}
|
|
139
|
|
|
140
|
break;
|
|
141
|
|
|
142
|
case 3:
|
|
143
|
$options = array('http' => array('method' => 'POST',
|
|
144
|
'header' => 'Host: ' . $server['host'] . "\r\n" .
|
|
145
|
'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
|
146
|
'Content-length: ' . strlen($parameters) . "\r\n" .
|
|
147
|
(!empty($header) ? implode("\r\n", $header) . "\r\n" : '') .
|
|
148
|
'Connection: close',
|
|
149
|
'content' => $parameters));
|
|
150
|
|
|
151
|
if (!empty($certificate)) {
|
|
152
|
$options['ssl'] = array('local_cert' => $certificate);
|
|
153
|
}
|
|
154
|
|
|
155
|
$context = stream_context_create($options);
|
|
156
|
|
|
157
|
if ($fp = fopen($url, 'r', false, $context)) {
|
|
158
|
$result = '';
|
|
159
|
|
|
160
|
while (!feof($fp)) {
|
|
161
|
$result .= fgets($fp, 4096);
|
|
162
|
}
|
|
163
|
|
|
164
|
fclose($fp);
|
|
165
|
}
|
|
166
|
|
|
167
|
break;
|
|
168
|
|
|
169
|
default:
|
|
170
|
exec(escapeshellarg(CFG_APP_CURL) . ' -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k' . (!empty($header) ? ' -H ' . escapeshellarg(implode("\r\n", $header)) : '') . (!empty($certificate) ? ' -E ' . escapeshellarg($certificate) : ''), $result);
|
|
171
|
$result = implode("\n", $result);
|
hpdl
|
533
|
172
|
}
|
|
173
|
|
hpdl
|
486
|
174
|
return $result;
|
|
175
|
}
|
|
176
|
|
hpdl
|
432
|
177
|
function getCode() {
|
|
178
|
return $this->_code;
|
|
179
|
}
|
|
180
|
|
|
181
|
function getTitle() {
|
|
182
|
return $this->_title;
|
|
183
|
}
|
|
184
|
|
|
185
|
function getDescription() {
|
|
186
|
return $this->_description;
|
|
187
|
}
|
|
188
|
|
hpdl
|
486
|
189
|
function getMethodTitle() {
|
|
190
|
return $this->_method_title;
|
|
191
|
}
|
|
192
|
|
|
193
|
function isEnabled() {
|
hpdl
|
432
|
194
|
return $this->_status;
|
|
195
|
}
|
|
196
|
|
|
197
|
function getSortOrder() {
|
|
198
|
return $this->_sort_order;
|
|
199
|
}
|
|
200
|
|
hpdl
|
547
|
201
|
function getJavascriptBlock() {
|
hpdl
|
1
|
202
|
}
|
|
203
|
|
hpdl
|
547
|
204
|
function getJavascriptBlocks() {
|
hpdl
|
387
|
205
|
global $osC_Language;
|
|
206
|
|
hpdl
|
1
|
207
|
$js = '';
|
hpdl
|
434
|
208
|
if (is_array($this->_modules)) {
|
hpdl
|
241
|
209
|
$js = '<script type="text/javascript">
|
hpdl
|
1
|
210
|
|
|
211
|
|
hpdl
|
387
|
212
|
|
hpdl
|
1
|
213
|
|
hpdl
|
486
|
214
|
|
|
215
|
|
|
216
|
|
|
217
|
|
hpdl
|
1
|
218
|
|
|
219
|
|
hpdl
|
486
|
220
|
|
|
221
|
|
|
222
|
|
|
223
|
|
hpdl
|
1
|
224
|
|
|
225
|
|
hpdl
|
434
|
226
|
|
hpdl
|
486
|
227
|
|
hpdl
|
547
|
228
|
|
hpdl
|
1
|
229
|
|
|
230
|
|
|
231
|
|
|
232
|
|
hpdl
|
390
|
233
|
|
hpdl
|
1
|
234
|
|
|
235
|
|
|
236
|
|
|
237
|
|
|
238
|
|
|
239
|
|
|
240
|
|
|
241
|
|
|
242
|
|
|
243
|
</script>' . "\n";
|
|
244
|
}
|
|
245
|
|
|
246
|
return $js;
|
|
247
|
}
|
|
248
|
|
|
249
|
function selection() {
|
|
250
|
$selection_array = array();
|
|
251
|
|
hpdl
|
434
|
252
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
253
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
254
|
$selection = $GLOBALS['osC_Payment_' . $module]->selection();
|
|
255
|
if (is_array($selection)) $selection_array[] = $selection;
|
hpdl
|
1
|
256
|
}
|
|
257
|
}
|
|
258
|
|
|
259
|
return $selection_array;
|
|
260
|
}
|
|
261
|
|
|
262
|
function pre_confirmation_check() {
|
hpdl
|
434
|
263
|
if (is_array($this->_modules)) {
|
hpdl
|
830
|
264
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
265
|
$GLOBALS[$this->selected_module]->pre_confirmation_check();
|
|
266
|
}
|
|
267
|
}
|
|
268
|
}
|
|
269
|
|
|
270
|
function confirmation() {
|
hpdl
|
434
|
271
|
if (is_array($this->_modules)) {
|
hpdl
|
830
|
272
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
273
|
return $GLOBALS[$this->selected_module]->confirmation();
|
|
274
|
}
|
|
275
|
}
|
|
276
|
}
|
|
277
|
|
|
278
|
function process_button() {
|
hpdl
|
434
|
279
|
if (is_array($this->_modules)) {
|
hpdl
|
830
|
280
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
281
|
return $GLOBALS[$this->selected_module]->process_button();
|
|
282
|
}
|
|
283
|
}
|
|
284
|
}
|
|
285
|
|
hpdl
|
523
|
286
|
function process() {
|
hpdl
|
434
|
287
|
if (is_array($this->_modules)) {
|
hpdl
|
830
|
288
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
523
|
289
|
return $GLOBALS[$this->selected_module]->process();
|
hpdl
|
1
|
290
|
}
|
|
291
|
}
|
|
292
|
}
|
|
293
|
|
|
294
|
function get_error() {
|
hpdl
|
434
|
295
|
if (is_array($this->_modules)) {
|
hpdl
|
830
|
296
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
297
|
return $GLOBALS[$this->selected_module]->get_error();
|
|
298
|
}
|
|
299
|
}
|
|
300
|
}
|
hpdl
|
431
|
301
|
|
hpdl
|
434
|
302
|
function hasActionURL() {
|
|
303
|
if (is_array($this->_modules)) {
|
hpdl
|
830
|
304
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
434
|
305
|
if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) {
|
|
306
|
return true;
|
|
307
|
}
|
|
308
|
}
|
|
309
|
}
|
|
310
|
|
|
311
|
return false;
|
|
312
|
}
|
|
313
|
|
|
314
|
function getActionURL() {
|
|
315
|
return $GLOBALS[$this->selected_module]->form_action_url;
|
|
316
|
}
|
|
317
|
|
hpdl
|
431
|
318
|
function hasActive() {
|
|
319
|
static $has_active;
|
|
320
|
|
|
321
|
if (isset($has_active) === false) {
|
|
322
|
$has_active = false;
|
|
323
|
|
hpdl
|
434
|
324
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
325
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
326
|
$has_active = true;
|
|
327
|
break;
|
|
328
|
}
|
|
329
|
}
|
|
330
|
}
|
|
331
|
|
|
332
|
return $has_active;
|
|
333
|
}
|
|
334
|
|
|
335
|
function numberOfActive() {
|
|
336
|
static $active;
|
|
337
|
|
|
338
|
if (isset($active) === false) {
|
|
339
|
$active = 0;
|
|
340
|
|
hpdl
|
434
|
341
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
342
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
343
|
$active++;
|
|
344
|
}
|
|
345
|
}
|
|
346
|
}
|
|
347
|
|
|
348
|
return $active;
|
|
349
|
}
|
|
350
|
|
|
351
|
function _usortModules($a, $b) {
|
hpdl
|
432
|
352
|
if ($GLOBALS['osC_Payment_' . $a]->getSortOrder() == $GLOBALS['osC_Payment_' . $b]->getSortOrder()) {
|
|
353
|
return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->getTitle(), $GLOBALS['osC_Payment_' . $a]->getTitle());
|
hpdl
|
431
|
354
|
}
|
|
355
|
|
hpdl
|
432
|
356
|
return ($GLOBALS['osC_Payment_' . $a]->getSortOrder() < $GLOBALS['osC_Payment_' . $b]->getSortOrder()) ? -1 : 1;
|
hpdl
|
431
|
357
|
}
|
hpdl
|
1
|
358
|
}
|
|
359
|
?>
|