  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: payment.php 443 2006-02-19 23:01:01Z hpdl $ |
| |
| 3 | + | $Id: payment.php 554 2006-04-29 16:26:53Z 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', $certificate = '') { |
| |
| 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 | + | if (empty($certificate) === false) { |
| |
| 91 | + | curl_setopt($curl, CURLOPT_SSLCERT, $certificate); |
| |
| 92 | + | } |
| |
| 93 | + | |
| |
| 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 | + | /* |
| |
| 106 | + | 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)) : '') . (empty($certificate) === false ? ' -E ' . escapeshellarg($certificate) : ''), $result); |
| |
| 107 | + | $result = implode("\n", $result); |
| |
| 108 | + | */ |
| |
| 109 | + | /* |
| |
| 110 | + | if ($fp = @fsockopen(($server['scheme'] == 'https' ? 'ssl' : $server['scheme']) . '://' . $server['host'], $server['port'])) { |
| |
| 111 | + | @fputs($fp, 'POST ' . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . ' HTTP/1.1' . "\r\n" . |
| |
| 112 | + | 'Host: ' . $server['host'] . "\r\n" . |
| |
| 113 | + | 'Content-type: application/x-www-form-urlencoded' . "\r\n" . |
| |
| 114 | + | 'Content-length: ' . strlen($parameters) . "\r\n" . |
| |
| 115 | + | (empty($header) === false ? implode("\r\n", $header) . "\r\n" : '') . |
| |
| 116 | + | 'Connection: close' . "\r\n\r\n" . |
| |
| 117 | + | $parameters . "\r\n\r\n"); |
| |
| 118 | + | |
| |
| 119 | + | $result = @stream_get_contents($fp); |
| |
| 120 | + | |
| |
| 121 | + | @fclose($fp); |
| |
| 122 | + | |
| |
| 123 | + | $result = trim(substr($result, strpos($result, "\r\n\r\n", strpos(strtolower($result), 'content-length:')))); |
| |
| 124 | + | } |
| |
| 125 | + | */ |
| |
| 126 | + | /* |
| |
| 127 | + | $options = array('http' => array('method' => 'POST', |
| |
| 128 | + | 'header' => 'Host: ' . $server['host'] . "\r\n" . |
| |
| 129 | + | 'Content-type: application/x-www-form-urlencoded' . "\r\n" . |
| |
| 130 | + | 'Content-length: ' . strlen($parameters) . "\r\n" . |
| |
| 131 | + | (empty($header) === false ? implode("\r\n", $header) . "\r\n" : '') . |
| |
| 132 | + | 'Connection: close', |
| |
| 133 | + | 'content' => $parameters)); |
| |
| 134 | + | |
| |
| 135 | + | if (empty($certificate) === false) { |
| |
| 136 | + | $options['ssl'] = array('local_cert' => $certificate); |
| |
| 137 | + | } |
| |
| 138 | + | |
| |
| 139 | + | $context = stream_context_create($options); |
| |
| 140 | + | |
| |
| 141 | + | if ($fp = fopen($url, 'r', false, $context)) { |
| |
| 142 | + | $result = ''; |
| |
| 143 | + | |
| |
| 144 | + | while (!feof($fp)) { |
| |
| 145 | + | $result .= fgets($fp, 4096); |
| |
| 146 | + | } |
| |
| 147 | + | |
| |
| 148 | + | fclose($fp); |
| |
| 149 | + | } |
| |
| 150 | + | */ |
| |
| 151 | + | |
| |
| 152 | + | return $result; |
| |
| 153 | + | } |
| |
| 154 | + | |
|
59 | 155 | | function getCode() { |
| |
60 | 156 | | return $this->_code; |
| |
61 | 157 | | } |
| |
|
|
 |
… |
|
68 | 164 | | return $this->_description; |
| |
69 | 165 | | } |
| |
70 | 166 | | |
  |
71 | | - | function getStatus() { |
| |
| 167 | + | function getMethodTitle() { |
| |
| 168 | + | return $this->_method_title; |
| |
| 169 | + | } |
| |
| 170 | + | |
| |
| 171 | + | function isEnabled() { |
|
72 | 172 | | return $this->_status; |
| |
73 | 173 | | } |
| |
74 | 174 | | |
| |
75 | 175 | | function getSortOrder() { |
| |
76 | 176 | | return $this->_sort_order; |
| |
77 | 177 | | } |
| |
78 | 178 | | |
  |
79 | | - | /* The following method is needed in the checkout_confirmation.php page |
| |
80 | | - | due to a chicken and egg problem with the payment class and order class. |
| |
81 | | - | The payment modules needs the order destination data for the dynamic status |
| |
82 | | - | feature, and the order class needs the payment module title. |
| |
83 | | - | The following method is a work-around to implementing the method in all |
| |
84 | | - | payment modules available which would break the modules in the contributions |
| |
85 | | - | section. This should be looked into again post 2.2. |
| |
86 | | - | */ |
| |
87 | | - | function update_status() { |
| |
88 | | - | if (is_array($this->_modules)) { |
| |
89 | | - | if (isset($GLOBALS[$this->selected_module]) && is_object($GLOBALS[$this->selected_module])) { |
| |
90 | | - | if (method_exists($GLOBALS[$this->selected_module], 'update_status')) { |
| |
91 | | - | $GLOBALS[$this->selected_module]->update_status(); |
| |
92 | | - | } |
| |
93 | | - | } |
| |
94 | | - | } |
| |
| 179 | + | function getJavascriptBlock() { |
|
95 | 180 | | } |
| |
96 | 181 | | |
  |
97 | | - | function javascript_validation() { |
| |
| 182 | + | function getJavascriptBlocks() { |
|
98 | 183 | | global $osC_Language; |
| |
99 | 184 | | |
| |
100 | 185 | | $js = ''; |
| |
|
|
 |
… |
|
104 | 189 | | ' var error = 0;' . "\n" . |
| |
105 | 190 | | ' var error_message = "' . $osC_Language->get('js_error') . '";' . "\n" . |
| |
106 | 191 | | ' 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" . |
| |
| 192 | + | ' if (document.checkout_payment.payment_method.length) {' . "\n" . |
| |
| 193 | + | ' for (var i=0; i<document.checkout_payment.payment_method.length; i++) {' . "\n" . |
| |
| 194 | + | ' if (document.checkout_payment.payment_method[i].checked) {' . "\n" . |
| |
| 195 | + | ' payment_value = document.checkout_payment.payment_method[i].value;' . "\n" . |
|
111 | 196 | | ' }' . "\n" . |
| |
112 | 197 | | ' }' . "\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" . |
| |
| 198 | + | ' } else if (document.checkout_payment.payment_method.checked) {' . "\n" . |
| |
| 199 | + | ' payment_value = document.checkout_payment.payment_method.value;' . "\n" . |
| |
| 200 | + | ' } else if (document.checkout_payment.payment_method.value) {' . "\n" . |
| |
| 201 | + | ' payment_value = document.checkout_payment.payment_method.value;' . "\n" . |
|
117 | 202 | | ' }' . "\n\n"; |
| |
118 | 203 | | |
| |
119 | 204 | | foreach ($this->_modules as $module) { |
  |
120 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
121 | | - | $js .= $GLOBALS['osC_Payment_' . $module]->javascript_validation(); |
| |
| 205 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
| |
| 206 | + | $js .= $GLOBALS['osC_Payment_' . $module]->getJavascriptBlock(); |
|
122 | 207 | | } |
| |
123 | 208 | | } |
| |
124 | 209 | | |
| |
|
|
 |
… |
|
143 | 228 | | $selection_array = array(); |
| |
144 | 229 | | |
| |
145 | 230 | | foreach ($this->_modules as $module) { |
  |
146 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 231 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
147 | 232 | | $selection = $GLOBALS['osC_Payment_' . $module]->selection(); |
| |
148 | 233 | | if (is_array($selection)) $selection_array[] = $selection; |
| |
149 | 234 | | } |
| |
|
|
 |
… |
|
154 | 239 | | |
| |
155 | 240 | | function pre_confirmation_check() { |
| |
156 | 241 | | if (is_array($this->_modules)) { |
  |
157 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 242 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
158 | 243 | | $GLOBALS[$this->selected_module]->pre_confirmation_check(); |
| |
159 | 244 | | } |
| |
160 | 245 | | } |
| |
161 | 246 | | } |
| |
162 | 247 | | |
| |
163 | 248 | | function confirmation() { |
| |
164 | 249 | | if (is_array($this->_modules)) { |
  |
165 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 250 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
166 | 251 | | return $GLOBALS[$this->selected_module]->confirmation(); |
| |
167 | 252 | | } |
| |
168 | 253 | | } |
| |
169 | 254 | | } |
| |
170 | 255 | | |
| |
171 | 256 | | function process_button() { |
| |
172 | 257 | | if (is_array($this->_modules)) { |
  |
173 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 258 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
174 | 259 | | return $GLOBALS[$this->selected_module]->process_button(); |
| |
175 | 260 | | } |
| |
176 | 261 | | } |
| |
177 | 262 | | } |
| |
178 | 263 | | |
  |
179 | | - | function before_process() { |
| |
| 264 | + | function process() { |
|
180 | 265 | | if (is_array($this->_modules)) { |
  |
181 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
182 | | - | return $GLOBALS[$this->selected_module]->before_process(); |
| |
| 266 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
| |
| 267 | + | return $GLOBALS[$this->selected_module]->process(); |
|
183 | 268 | | } |
| |
184 | 269 | | } |
| |
185 | 270 | | } |
| |
186 | 271 | | |
  |
187 | | - | function after_process() { |
| |
188 | | - | if (is_array($this->_modules)) { |
| |
189 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
190 | | - | return $GLOBALS[$this->selected_module]->after_process(); |
| |
191 | | - | } |
| |
192 | | - | } |
| |
193 | | - | } |
| |
194 | | - | |
|
195 | 272 | | function get_error() { |
| |
196 | 273 | | if (is_array($this->_modules)) { |
  |
197 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 274 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
198 | 275 | | return $GLOBALS[$this->selected_module]->get_error(); |
| |
199 | 276 | | } |
| |
200 | 277 | | } |
| |
201 | 278 | | } |
| |
202 | 279 | | |
| |
203 | 280 | | function hasActionURL() { |
| |
204 | 281 | | if (is_array($this->_modules)) { |
  |
205 | | - | if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->getStatus() === true) ) { |
| |
| 282 | + | if (is_object($GLOBALS[$this->selected_module]) && $GLOBALS[$this->selected_module]->isEnabled()) { |
|
206 | 283 | | if (isset($GLOBALS[$this->selected_module]->form_action_url) && (empty($GLOBALS[$this->selected_module]->form_action_url) === false)) { |
| |
207 | 284 | | return true; |
| |
208 | 285 | | } |
| |
|
|
 |
… |
|
223 | 300 | | $has_active = false; |
| |
224 | 301 | | |
| |
225 | 302 | | foreach ($this->_modules as $module) { |
  |
226 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 303 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
227 | 304 | | $has_active = true; |
| |
228 | 305 | | break; |
| |
229 | 306 | | } |
| |
|
|
 |
… |
|
240 | 317 | | $active = 0; |
| |
241 | 318 | | |
| |
242 | 319 | | foreach ($this->_modules as $module) { |
  |
243 | | - | if ($GLOBALS['osC_Payment_' . $module]->getStatus() === true) { |
| |
| 320 | + | if ($GLOBALS['osC_Payment_' . $module]->isEnabled()) { |
|
244 | 321 | | $active++; |
| |
245 | 322 | | } |
| |
246 | 323 | | } |
| |
|
|
 |
… |
|
249 | 326 | | return $active; |
| |
250 | 327 | | } |
| |
251 | 328 | | |
  |
252 | | - | function hasKeys() { |
| |
253 | | - | static $has_keys; |
| |
254 | | - | |
| |
255 | | - | if (isset($has_keys) === false) { |
| |
256 | | - | $has_keys = (sizeof($this->getKeys()) > 0) ? true : false; |
| |
257 | | - | } |
| |
258 | | - | |
| |
259 | | - | return $has_keys; |
| |
260 | | - | } |
| |
261 | | - | |
| |
262 | | - | function install() { |
| |
263 | | - | global $osC_Database, $osC_Language; |
| |
264 | | - | |
| |
265 | | - | $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)'); |
| |
266 | | - | $Qinstall->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES); |
| |
267 | | - | $Qinstall->bindValue(':title', $this->_title); |
| |
268 | | - | $Qinstall->bindValue(':code', $this->_code); |
| |
269 | | - | $Qinstall->bindValue(':author_name', $this->_author_name); |
| |
270 | | - | $Qinstall->bindValue(':author_www', $this->_author_www); |
| |
271 | | - | $Qinstall->bindValue(':modules_group', $this->_group); |
| |
272 | | - | $Qinstall->execute(); |
| |
273 | | - | |
| |
274 | | - | foreach ($osC_Language->getAll() as $key => $value) { |
| |
275 | | - | if (file_exists(dirname(__FILE__) . '/../languages/' . $key . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) { |
| |
276 | | - | foreach ($osC_Language->extractDefinitions($key . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) { |
| |
277 | | - | $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'); |
| |
278 | | - | $Qcheck->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); |
| |
279 | | - | $Qcheck->bindValue(':definition_key', $def['key']); |
| |
280 | | - | $Qcheck->bindValue(':content_group', $def['group']); |
| |
281 | | - | $Qcheck->bindInt(':languages_id', $value['id']); |
| |
282 | | - | $Qcheck->execute(); |
| |
283 | | - | |
| |
284 | | - | if ($Qcheck->numberOfRows() === 1) { |
| |
285 | | - | $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'); |
| |
286 | | - | } else { |
| |
287 | | - | $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)'); |
| |
288 | | - | } |
| |
289 | | - | $Qdef->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); |
| |
290 | | - | $Qdef->bindInt(':languages_id', $value['id']); |
| |
291 | | - | $Qdef->bindValue(':content_group', $def['group']); |
| |
292 | | - | $Qdef->bindValue(':definition_key', $def['key']); |
| |
293 | | - | $Qdef->bindValue(':definition_value', $def['value']); |
| |
294 | | - | $Qdef->execute(); |
| |
295 | | - | } |
| |
296 | | - | } |
| |
297 | | - | } |
| |
298 | | - | |
| |
299 | | - | osC_Cache::clear('languages'); |
| |
300 | | - | } |
| |
301 | | - | |
| |
302 | | - | function remove() { |
| |
303 | | - | global $osC_Database, $osC_Language; |
| |
304 | | - | |
| |
305 | | - | $Qdel = $osC_Database->query('delete from :table_templates_boxes where code = :code and modules_group = :modules_group'); |
| |
306 | | - | $Qdel->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES); |
| |
307 | | - | $Qdel->bindValue(':code', $this->_code); |
| |
308 | | - | $Qdel->bindValue(':modules_group', $this->_group); |
| |
309 | | - | $Qdel->execute(); |
| |
310 | | - | |
| |
311 | | - | if ($this->hasKeys()) { |
| |
312 | | - | $Qdel = $osC_Database->query('delete from :table_configuration where configuration_key in (":configuration_key")'); |
| |
313 | | - | $Qdel->bindTable(':table_configuration', TABLE_CONFIGURATION); |
| |
314 | | - | $Qdel->bindRaw(':configuration_key', implode('", "', $this->getKeys())); |
| |
315 | | - | $Qdel->execute(); |
| |
316 | | - | } |
| |
317 | | - | |
| |
318 | | - | if (file_exists(dirname(__FILE__) . '/../languages/' . $osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml')) { |
| |
319 | | - | foreach ($osC_Language->extractDefinitions($osC_Language->getCode() . '/modules/' . $this->_group . '/' . $this->_code . '.xml') as $def) { |
| |
320 | | - | $Qdel = $osC_Database->query('delete from :table_languages_definitions where definition_key = :definition_key and content_group = :content_group'); |
| |
321 | | - | $Qdel->bindTable(':table_languages_definitions', TABLE_LANGUAGES_DEFINITIONS); |
| |
322 | | - | $Qdel->bindValue(':definition_key', $def['key']); |
| |
323 | | - | $Qdel->bindValue(':content_group', $def['group']); |
| |
324 | | - | $Qdel->execute(); |
| |
325 | | - | } |
| |
326 | | - | |
| |
327 | | - | osC_Cache::clear('languages'); |
| |
328 | | - | } |
| |
329 | | - | } |
| |
330 | | - | |
  |
331 | 329 | | function _usortModules($a, $b) { |
| |
332 | 330 | | if ($GLOBALS['osC_Payment_' . $a]->getSortOrder() == $GLOBALS['osC_Payment_' . $b]->getSortOrder()) { |
| |
333 | 331 | | return strnatcasecmp($GLOBALS['osC_Payment_' . $a]->getTitle(), $GLOBALS['osC_Payment_' . $a]->getTitle()); |