  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: payment.php 434 2006-02-15 20:49:45Z hpdl $ |
| |
| 3 | + | $Id: payment.php 486 2006-04-17 23:39:28Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
  |
| 13 | + | include(dirname(__FILE__) . '/credit_card.php'); |
| |
| 14 | + | |
|
13 | 15 | | class osC_Payment { |
| |
14 | 16 | | var $selected_module; |
| |
15 | 17 | | |
| |
|
|
 |
… |
|
56 | 58 | | } |
| |
57 | 59 | | |
| |
58 | 60 | | // class methods |
  |
| 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 | + | |
|
59 | 125 | | function getCode() { |
| |
60 | 126 | | return $this->_code; |
| |
61 | 127 | | } |
| |
|
|
 |
… |
|
68 | 134 | | return $this->_description; |
| |
69 | 135 | | } |
| |
70 | 136 | | |
  |
71 | | - | function getStatus() { |
| |
| 137 | + | function getMethodTitle() { |
| |
| 138 | + | return $this->_method_title; |
| |
| 139 | + | } |
| |
| 140 | + | |
| |
| 141 | + | function isEnabled() { |
|
72 | 142 | | return $this->_status; |
| |
73 | 143 | | } |
| |
74 | 144 | | |
| |
|
|
 |
… |
|
104 | 174 | | ' var error = 0;' . "\n" . |
| |
105 | 175 | | ' var error_message = "' . $osC_Language->get('js_error') . '";' . "\n" . |
| |
106 | 176 | | ' var payment_value = null;' . "\n" . |
  |
107 | | - | ' if (document.checkout_payment.payment.length) {' . "\n" . |
| |
108 | | - | ' for (var i=0; i<document.checkout_payment.payment.length; i++) {' . "\n" . |
| |
109 | | - | ' if (document.checkout_payment.payment[i].checked) {' . "\n" . |
| |
110 | | - | ' payment_value = document.checkout_payment.payment[i].value;' . "\n" . |
| |
| 177 | + | ' if (document.checkout_payment.payment_method.length) {' . "\n" . |
| |
| 178 | + | ' for (var i=0; i<document.checkout_payment.payment_method.length; i++) {' . "\n" . |
| |
| 179 | + | ' if (document.checkout_payment.payment_method[i].checked) {' . "\n" . |
| |
| 180 | + | ' payment_value = document.checkout_payment.payment_method[i].value;' . "\n" . |
|
111 | 181 | | ' }' . "\n" . |
| |
112 | 182 | | ' }' . "\n" . |
  |
113 | | - | ' } else if (document.checkout_payment.payment.checked) {' . "\n" . |
| |
114 | | - | ' payment_value = document.checkout_payment.payment.value;' . "\n" . |
| |
115 | | - | ' } else if (document.checkout_payment.payment.value) {' . "\n" . |
| |
116 | | - | ' payment_value = document.checkout_payment.payment.value;' . "\n" . |
| |
| 183 | + | ' } else if (document.checkout_payment.payment_method.checked) {' . "\n" . |
| |
| 184 | + | ' payment_value = document.checkout_payment.payment_method.value;' . "\n" . |
| |
| 185 | + | ' } else if (document.checkout_payment.payment_method.value) {' . "\n" . |
| |
| 186 | + | ' payment_value = document.checkout_payment.payment_method.value;' . "\n" . |
|
117 | 187 | | ' }' . "\n\n"; |
| |
118 | 188 | | |
| |
119 | 189 | | foreach ($this->_modules as $module) { |
  |
120 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 190 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
121 | 191 | | $js .= $GLOBALS['osC_Payment_' . $module]->javascript_validation(); |
| |
122 | 192 | | } |
| |
123 | 193 | | } |
| |
|
|
 |
… |
|
143 | 213 | | $selection_array = array(); |
| |
144 | 214 | | |
| |
145 | 215 | | foreach ($this->_modules as $module) { |
  |
146 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 216 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
147 | 217 | | $selection = $GLOBALS['osC_Payment_' . $module]->selection(); |
| |
148 | 218 | | if (is_array($selection)) $selection_array[] = $selection; |
| |
149 | 219 | | } |
| |
|
|
 |
… |
|
154 | 224 | | |
| |
155 | 225 | | function pre_confirmation_check() { |
| |
156 | 226 | | if (is_array($this->_modules)) { |
  |
157 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 227 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
158 | 228 | | $GLOBALS[$this->selected_module]->pre_confirmation_check(); |
| |
159 | 229 | | } |
| |
160 | 230 | | } |
| |
161 | 231 | | } |
| |
162 | 232 | | |
| |
163 | 233 | | function confirmation() { |
| |
164 | 234 | | if (is_array($this->_modules)) { |
  |
165 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 235 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
166 | 236 | | return $GLOBALS[$this->selected_module]->confirmation(); |
| |
167 | 237 | | } |
| |
168 | 238 | | } |
| |
169 | 239 | | } |
| |
170 | 240 | | |
| |
171 | 241 | | function process_button() { |
| |
172 | 242 | | if (is_array($this->_modules)) { |
  |
173 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 243 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
174 | 244 | | return $GLOBALS[$this->selected_module]->process_button(); |
| |
175 | 245 | | } |
| |
176 | 246 | | } |
| |
177 | 247 | | } |
| |
178 | 248 | | |
| |
179 | 249 | | function before_process() { |
| |
180 | 250 | | if (is_array($this->_modules)) { |
  |
181 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 251 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
182 | 252 | | return $GLOBALS[$this->selected_module]->before_process(); |
| |
183 | 253 | | } |
| |
184 | 254 | | } |
| |
185 | 255 | | } |
| |
186 | 256 | | |
| |
187 | 257 | | function after_process() { |
| |
188 | 258 | | if (is_array($this->_modules)) { |
  |
189 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 259 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
190 | 260 | | return $GLOBALS[$this->selected_module]->after_process(); |
| |
191 | 261 | | } |
| |
192 | 262 | | } |
| |
193 | 263 | | } |
| |
194 | 264 | | |
| |
195 | 265 | | function get_error() { |
| |
196 | 266 | | if (is_array($this->_modules)) { |
  |
197 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 267 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
198 | 268 | | return $GLOBALS[$this->selected_module]->get_error(); |
| |
199 | 269 | | } |
| |
200 | 270 | | } |
| |
201 | 271 | | } |
| |
202 | 272 | | |
| |
203 | 273 | | function hasActionURL() { |
| |
204 | 274 | | if (is_array($this->_modules)) { |
  |
205 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 275 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
206 | 276 | | if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) { |
| |
207 | 277 | | return true; |
| |
208 | 278 | | } |
| |
|
|
 |
… |
|
223 | 293 | | $has_active = false; |
| |
224 | 294 | | |
| |
225 | 295 | | foreach ($this->_modules as $module) { |
  |
226 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 296 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
227 | 297 | | $has_active = true; |
| |
228 | 298 | | break; |
| |
229 | 299 | | } |
| |
|
|
 |
… |
|
240 | 310 | | $active = 0; |
| |
241 | 311 | | |
| |
242 | 312 | | foreach ($this->_modules as $module) { |
  |
243 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 313 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
244 | 314 | | $active++; |
| |
245 | 315 | | } |
| |
246 | 316 | | } |
| |
|
|
 |
… |
|
259 | 329 | | return $has_keys; |
| |
260 | 330 | | } |
| |
261 | 331 | | |
  |
| 332 | + | function getPostTransactionActions($history) { |
| |
| 333 | + | return false; |
| |
| 334 | + | } |
| |
| 335 | + | |
  |
262 | 336 | | function install() { |
| |
263 | 337 | | global $osC_Database, $osC_Language; |
| |
264 | 338 | | |