hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
143
|
3
|
$Id: payment.php 523 2006-04-25 14:36: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
|
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
|
523
|
61
|
function sendTransactionToGateway($url, $parameters, $header = '', $method = 'post', $certificate = '') {
|
hpdl
|
486
|
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
|
|
hpdl
|
523
|
90
|
if (empty($certificate) === false) {
|
|
91
|
curl_setopt($curl, CURLOPT_SSLCERT, $certificate);
|
|
92
|
}
|
|
93
|
|
hpdl
|
486
|
94
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
95
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
96
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
97
|
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
|
|
98
|
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
|
|
99
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
100
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
|
|
101
|
$result = curl_exec($curl);
|
|
102
|
curl_close($curl);
|
|
103
|
|
|
104
|
/*
|
|
105
|
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);
|
|
106
|
$result = implode("\n", $result);
|
|
107
|
*/
|
|
108
|
/*
|
|
109
|
if ($fp = @fsockopen(($server['scheme'] == 'https' ? 'ssl' : $server['scheme']) . '://' . $server['host'], $server['port'])) {
|
|
110
|
@fputs($fp, 'POST ' . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . ' HTTP/1.1' . "\r\n" .
|
|
111
|
'Host: ' . $server['host'] . "\r\n" .
|
|
112
|
'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
|
113
|
'Content-length: ' . strlen($parameters) . "\r\n" .
|
|
114
|
(empty($header) === false ? implode("\r\n", $header) . "\r\n" : '') .
|
|
115
|
'Connection: close' . "\r\n\r\n" .
|
|
116
|
$parameters . "\r\n\r\n");
|
|
117
|
|
|
118
|
$result = @stream_get_contents($fp);
|
|
119
|
|
|
120
|
@fclose($fp);
|
|
121
|
|
|
122
|
$result = trim(substr($result, strpos($result, "\r\n\r\n", strpos(strtolower($result), 'content-length:'))));
|
|
123
|
}
|
|
124
|
*/
|
|
125
|
|
|
126
|
return $result;
|
|
127
|
}
|
|
128
|
|
hpdl
|
432
|
129
|
function getCode() {
|
|
130
|
return $this->_code;
|
|
131
|
}
|
|
132
|
|
|
133
|
function getTitle() {
|
|
134
|
return $this->_title;
|
|
135
|
}
|
|
136
|
|
|
137
|
function getDescription() {
|
|
138
|
return $this->_description;
|
|
139
|
}
|
|
140
|
|
hpdl
|
486
|
141
|
function getMethodTitle() {
|
|
142
|
return $this->_method_title;
|
|
143
|
}
|
|
144
|
|
|
145
|
function isEnabled() {
|
hpdl
|
432
|
146
|
return $this->_status;
|
|
147
|
}
|
|
148
|
|
|
149
|
function getSortOrder() {
|
|
150
|
return $this->_sort_order;
|
|
151
|
}
|
|
152
|
|
hpdl
|
1
|
153
|
/* The following method is needed in the checkout_confirmation.php page
|
|
154
|
due to a chicken and egg problem with the payment class and order class.
|
|
155
|
The payment modules needs the order destination data for the dynamic status
|
|
156
|
feature, and the order class needs the payment module title.
|
|
157
|
The following method is a work-around to implementing the method in all
|
|
158
|
payment modules available which would break the modules in the contributions
|
|
159
|
section. This should be looked into again post 2.2.
|
|
160
|
*/
|
|
161
|
function update_status() {
|
hpdl
|
434
|
162
|
if (is_array($this->_modules)) {
|
hpdl
|
1
|
163
|
if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) {
|
|
164
|
if (method_exists($GLOBALS[$this->selected_module], 'update_status')) {
|
|
165
|
$GLOBALS[$this->selected_module]->update_status();
|
|
166
|
}
|
|
167
|
}
|
|
168
|
}
|
|
169
|
}
|
|
170
|
|
|
171
|
function javascript_validation() {
|
hpdl
|
387
|
172
|
global $osC_Language;
|
|
173
|
|
hpdl
|
1
|
174
|
$js = '';
|
hpdl
|
434
|
175
|
if (is_array($this->_modules)) {
|
hpdl
|
241
|
176
|
$js = '<script type="text/javascript">
|
hpdl
|
1
|
177
|
|
|
178
|
|
hpdl
|
387
|
179
|
|
hpdl
|
1
|
180
|
|
hpdl
|
486
|
181
|
|
|
182
|
|
|
183
|
|
|
184
|
|
hpdl
|
1
|
185
|
|
|
186
|
|
hpdl
|
486
|
187
|
|
|
188
|
|
|
189
|
|
|
190
|
|
hpdl
|
1
|
191
|
|
|
192
|
|
hpdl
|
434
|
193
|
|
hpdl
|
486
|
194
|
|
hpdl
|
431
|
195
|
|
hpdl
|
1
|
196
|
|
|
197
|
|
|
198
|
|
|
199
|
|
hpdl
|
390
|
200
|
|
hpdl
|
1
|
201
|
|
|
202
|
|
|
203
|
|
|
204
|
|
|
205
|
|
|
206
|
|
|
207
|
|
|
208
|
|
|
209
|
|
|
210
|
</script>' . "\n";
|
|
211
|
}
|
|
212
|
|
|
213
|
return $js;
|
|
214
|
}
|
|
215
|
|
|
216
|
function selection() {
|
|
217
|
$selection_array = array();
|
|
218
|
|
hpdl
|
434
|
219
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
220
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
221
|
$selection = $GLOBALS['osC_Payment_' . $module]->selection();
|
|
222
|
if (is_array($selection)) $selection_array[] = $selection;
|
hpdl
|
1
|
223
|
}
|
|
224
|
}
|
|
225
|
|
|
226
|
return $selection_array;
|
|
227
|
}
|
|
228
|
|
|
229
|
function pre_confirmation_check() {
|
hpdl
|
434
|
230
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
231
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
232
|
$GLOBALS[$this->selected_module]->pre_confirmation_check();
|
|
233
|
}
|
|
234
|
}
|
|
235
|
}
|
|
236
|
|
|
237
|
function confirmation() {
|
hpdl
|
434
|
238
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
239
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
240
|
return $GLOBALS[$this->selected_module]->confirmation();
|
|
241
|
}
|
|
242
|
}
|
|
243
|
}
|
|
244
|
|
|
245
|
function process_button() {
|
hpdl
|
434
|
246
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
247
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
248
|
return $GLOBALS[$this->selected_module]->process_button();
|
|
249
|
}
|
|
250
|
}
|
|
251
|
}
|
|
252
|
|
hpdl
|
523
|
253
|
function process() {
|
hpdl
|
434
|
254
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
255
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
523
|
256
|
return $GLOBALS[$this->selected_module]->process();
|
hpdl
|
1
|
257
|
}
|
|
258
|
}
|
|
259
|
}
|
|
260
|
|
|
261
|
function get_error() {
|
hpdl
|
434
|
262
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
263
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
1
|
264
|
return $GLOBALS[$this->selected_module]->get_error();
|
|
265
|
}
|
|
266
|
}
|
|
267
|
}
|
hpdl
|
431
|
268
|
|
hpdl
|
434
|
269
|
function hasActionURL() {
|
|
270
|
if (is_array($this->_modules)) {
|
hpdl
|
486
|
271
|
if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) {
|
hpdl
|
434
|
272
|
if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) {
|
|
273
|
return true;
|
|
274
|
}
|
|
275
|
}
|
|
276
|
}
|
|
277
|
|
|
278
|
return false;
|
|
279
|
}
|
|
280
|
|
|
281
|
function getActionURL() {
|
|
282
|
return $GLOBALS[$this->selected_module]->form_action_url;
|
|
283
|
}
|
|
284
|
|
hpdl
|
431
|
285
|
function hasActive() {
|
|
286
|
static $has_active;
|
|
287
|
|
|
288
|
if (isset($has_active) === false) {
|
|
289
|
$has_active = false;
|
|
290
|
|
hpdl
|
434
|
291
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
292
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
293
|
$has_active = true;
|
|
294
|
break;
|
|
295
|
}
|
|
296
|
}
|
|
297
|
}
|
|
298
|
|
|
299
|
return $has_active;
|
|
300
|
}
|
|
301
|
|
|
302
|
function numberOfActive() {
|
|
303
|
static $active;
|
|
304
|
|
|
305
|
if (isset($active) === false) {
|
|
306
|
$active = 0;
|
|
307
|
|
hpdl
|
434
|
308
|
foreach ($this->_modules as $module) {
|
hpdl
|
486
|
309
|
if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) {
|
hpdl
|
431
|
310
|
$active++;
|
|
311
|
}
|
|
312
|
}
|
|
313
|
}
|
|
314
|
|
|
315
|
return $active;
|
|
316
|
}
|
|
317
|
|
|
318
|
function _usortModules($a, $b) {
|
hpdl
|
432
|
319
|
if ($GLOBALS['osC_Payment_' . $a]->getSortOrder() == $GLOBALS['osC_Payment_' . $b]->getSortOrder()) {
|
|
320
|
return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->getTitle(), $GLOBALS['osC_Payment_' . $a]->getTitle());
|
hpdl
|
431
|
321
|
}
|
|
322
|
|
hpdl
|
432
|
323
|
return ($GLOBALS['osC_Payment_' . $a]->getSortOrder() < $GLOBALS['osC_Payment_' . $b]->getSortOrder()) ? -1 : 1;
|
hpdl
|
431
|
324
|
}
|
hpdl
|
1
|
325
|
}
|
|
326
|
?>
|