firstdata_remote.php (20836B)
1 <?php 2 class ControllerExtensionPaymentFirstdataRemote extends Controller { 3 private $error = array(); 4 5 public function index() { 6 $this->load->language('extension/payment/firstdata_remote'); 7 8 $this->document->setTitle($this->language->get('heading_title')); 9 10 $this->load->model('setting/setting'); 11 12 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 13 $this->model_setting_setting->editSetting('payment_firstdata_remote', $this->request->post); 14 15 $this->session->data['success'] = $this->language->get('text_success'); 16 17 $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); 18 } 19 20 $this->load->model('localisation/order_status'); 21 22 $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); 23 24 $this->load->model('localisation/geo_zone'); 25 26 $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); 27 28 if (isset($this->error['warning'])) { 29 $data['error_warning'] = $this->error['warning']; 30 } else { 31 $data['error_warning'] = ''; 32 } 33 34 if (isset($this->error['error_merchant_id'])) { 35 $data['error_merchant_id'] = $this->error['error_merchant_id']; 36 } else { 37 $data['error_merchant_id'] = ''; 38 } 39 40 if (isset($this->error['error_user_id'])) { 41 $data['error_user_id'] = $this->error['error_user_id']; 42 } else { 43 $data['error_user_id'] = ''; 44 } 45 46 if (isset($this->error['error_password'])) { 47 $data['error_password'] = $this->error['error_password']; 48 } else { 49 $data['error_password'] = ''; 50 } 51 52 if (isset($this->error['error_certificate'])) { 53 $data['error_certificate'] = $this->error['error_certificate']; 54 } else { 55 $data['error_certificate'] = ''; 56 } 57 58 if (isset($this->error['error_key'])) { 59 $data['error_key'] = $this->error['error_key']; 60 } else { 61 $data['error_key'] = ''; 62 } 63 64 if (isset($this->error['error_key_pw'])) { 65 $data['error_key_pw'] = $this->error['error_key_pw']; 66 } else { 67 $data['error_key_pw'] = ''; 68 } 69 70 if (isset($this->error['error_ca'])) { 71 $data['error_ca'] = $this->error['error_ca']; 72 } else { 73 $data['error_ca'] = ''; 74 } 75 76 $data['breadcrumbs'] = array(); 77 78 $data['breadcrumbs'][] = array( 79 'text' => $this->language->get('text_home'), 80 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 81 ); 82 83 $data['breadcrumbs'][] = array( 84 'text' => $this->language->get('text_extension'), 85 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) 86 ); 87 88 $data['breadcrumbs'][] = array( 89 'text' => $this->language->get('heading_title'), 90 'href' => $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) 91 ); 92 93 $data['action'] = $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'], true); 94 95 $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); 96 97 if (isset($this->request->post['firstdata_remote_merchant_id'])) { 98 $data['firstdata_remote_merchant_id'] = $this->request->post['firstdata_remote_merchant_id']; 99 } else { 100 $data['firstdata_remote_merchant_id'] = $this->config->get('firstdata_remote_merchant_id'); 101 } 102 103 if (isset($this->request->post['firstdata_remote_user_id'])) { 104 $data['firstdata_remote_user_id'] = $this->request->post['firstdata_remote_user_id']; 105 } else { 106 $data['firstdata_remote_user_id'] = $this->config->get('firstdata_remote_user_id'); 107 } 108 109 if (isset($this->request->post['firstdata_remote_password'])) { 110 $data['firstdata_remote_password'] = $this->request->post['firstdata_remote_password']; 111 } else { 112 $data['firstdata_remote_password'] = $this->config->get('firstdata_remote_password'); 113 } 114 115 if (isset($this->request->post['firstdata_remote_certificate'])) { 116 $data['firstdata_remote_certificate'] = $this->request->post['firstdata_remote_certificate']; 117 } else { 118 $data['firstdata_remote_certificate'] = $this->config->get('firstdata_remote_certificate'); 119 } 120 121 if (isset($this->request->post['firstdata_remote_key'])) { 122 $data['firstdata_remote_key'] = $this->request->post['firstdata_remote_key']; 123 } else { 124 $data['firstdata_remote_key'] = $this->config->get('firstdata_remote_key'); 125 } 126 127 if (isset($this->request->post['firstdata_remote_key_pw'])) { 128 $data['firstdata_remote_key_pw'] = $this->request->post['firstdata_remote_key_pw']; 129 } else { 130 $data['firstdata_remote_key_pw'] = $this->config->get('firstdata_remote_key_pw'); 131 } 132 133 if (isset($this->request->post['firstdata_remote_ca'])) { 134 $data['firstdata_remote_ca'] = $this->request->post['firstdata_remote_ca']; 135 } else { 136 $data['firstdata_remote_ca'] = $this->config->get('firstdata_remote_ca'); 137 } 138 139 if (isset($this->request->post['firstdata_remote_geo_zone_id'])) { 140 $data['firstdata_remote_geo_zone_id'] = $this->request->post['firstdata_remote_geo_zone_id']; 141 } else { 142 $data['firstdata_remote_geo_zone_id'] = $this->config->get('firstdata_remote_geo_zone_id'); 143 } 144 145 if (isset($this->request->post['firstdata_remote_total'])) { 146 $data['firstdata_remote_total'] = $this->request->post['firstdata_remote_total']; 147 } else { 148 $data['firstdata_remote_total'] = $this->config->get('firstdata_remote_total'); 149 } 150 151 if (isset($this->request->post['firstdata_remote_sort_order'])) { 152 $data['firstdata_remote_sort_order'] = $this->request->post['firstdata_remote_sort_order']; 153 } else { 154 $data['firstdata_remote_sort_order'] = $this->config->get('firstdata_remote_sort_order'); 155 } 156 157 if (isset($this->request->post['firstdata_remote_status'])) { 158 $data['firstdata_remote_status'] = $this->request->post['firstdata_remote_status']; 159 } else { 160 $data['firstdata_remote_status'] = $this->config->get('firstdata_remote_status'); 161 } 162 163 if (isset($this->request->post['firstdata_remote_debug'])) { 164 $data['firstdata_remote_debug'] = $this->request->post['firstdata_remote_debug']; 165 } else { 166 $data['firstdata_remote_debug'] = $this->config->get('firstdata_remote_debug'); 167 } 168 if (isset($this->request->post['firstdata_remote_auto_settle'])) { 169 $data['firstdata_remote_auto_settle'] = $this->request->post['firstdata_remote_auto_settle']; 170 } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('firstdata_remote_auto_settle') != '') { 171 $data['firstdata_remote_auto_settle'] = $this->config->get('firstdata_remote_auto_settle'); 172 } else { 173 $data['firstdata_remote_auto_settle'] = 1; 174 } 175 176 if (isset($this->request->post['firstdata_remote_3d'])) { 177 $data['firstdata_remote_3d'] = $this->request->post['firstdata_remote_3d']; 178 } else { 179 $data['firstdata_remote_3d'] = $this->config->get('firstdata_remote_3d'); 180 } 181 182 if (isset($this->request->post['firstdata_remote_liability'])) { 183 $data['firstdata_remote_liability'] = $this->request->post['firstdata_remote_liability']; 184 } else { 185 $data['firstdata_remote_liability'] = $this->config->get('firstdata_remote_liability'); 186 } 187 188 if (isset($this->request->post['firstdata_remote_order_status_success_settled_id'])) { 189 $data['firstdata_remote_order_status_success_settled_id'] = $this->request->post['firstdata_remote_order_status_success_settled_id']; 190 } else { 191 $data['firstdata_remote_order_status_success_settled_id'] = $this->config->get('firstdata_remote_order_status_success_settled_id'); 192 } 193 194 if (isset($this->request->post['firstdata_remote_order_status_success_unsettled_id'])) { 195 $data['firstdata_remote_order_status_success_unsettled_id'] = $this->request->post['firstdata_remote_order_status_success_unsettled_id']; 196 } else { 197 $data['firstdata_remote_order_status_success_unsettled_id'] = $this->config->get('firstdata_remote_order_status_success_unsettled_id'); 198 } 199 200 if (isset($this->request->post['firstdata_remote_order_status_decline_id'])) { 201 $data['firstdata_remote_order_status_decline_id'] = $this->request->post['firstdata_remote_order_status_decline_id']; 202 } else { 203 $data['firstdata_remote_order_status_decline_id'] = $this->config->get('firstdata_remote_order_status_decline_id'); 204 } 205 206 if (isset($this->request->post['firstdata_remote_order_status_void_id'])) { 207 $data['firstdata_remote_order_status_void_id'] = $this->request->post['firstdata_remote_order_status_void_id']; 208 } else { 209 $data['firstdata_remote_order_status_void_id'] = $this->config->get('firstdata_remote_order_status_void_id'); 210 } 211 212 if (isset($this->request->post['firstdata_remote_order_status_refunded_id'])) { 213 $data['firstdata_remote_order_status_refunded_id'] = $this->request->post['firstdata_remote_order_status_refunded_id']; 214 } else { 215 $data['firstdata_remote_order_status_refunded_id'] = $this->config->get('firstdata_remote_order_status_refunded_id'); 216 } 217 218 if (isset($this->request->post['firstdata_remote_card_storage'])) { 219 $data['firstdata_remote_card_storage'] = $this->request->post['firstdata_remote_card_storage']; 220 } else { 221 $data['firstdata_remote_card_storage'] = $this->config->get('firstdata_remote_card_storage'); 222 } 223 224 $data['cards'] = array(); 225 226 $data['cards'][] = array( 227 'text' => $this->language->get('text_mastercard'), 228 'value' => 'mastercard' 229 ); 230 231 $data['cards'][] = array( 232 'text' => $this->language->get('text_visa'), 233 'value' => 'visa' 234 ); 235 236 $data['cards'][] = array( 237 'text' => $this->language->get('text_diners'), 238 'value' => 'diners' 239 ); 240 241 $data['cards'][] = array( 242 'text' => $this->language->get('text_amex'), 243 'value' => 'amex' 244 ); 245 246 $data['cards'][] = array( 247 'text' => $this->language->get('text_maestro'), 248 'value' => 'maestro' 249 ); 250 251 if (isset($this->request->post['firstdata_remote_cards_accepted'])) { 252 $data['firstdata_remote_cards_accepted'] = $this->request->post['firstdata_remote_cards_accepted']; 253 } elseif ($this->config->get('firstdata_remote_cards_accepted')) { 254 $data['firstdata_remote_cards_accepted'] = $this->config->get('firstdata_remote_cards_accepted'); 255 } else { 256 $data['firstdata_remote_cards_accepted'] = array(); 257 } 258 259 $data['header'] = $this->load->controller('common/header'); 260 $data['column_left'] = $this->load->controller('common/column_left'); 261 $data['footer'] = $this->load->controller('common/footer'); 262 263 $this->response->setOutput($this->load->view('extension/payment/firstdata_remote', $data)); 264 } 265 266 public function install() { 267 $this->load->model('extension/payment/firstdata_remote'); 268 $this->model_extension_payment_firstdata_remote->install(); 269 } 270 271 public function uninstall() { 272 $this->load->model('extension/payment/firstdata_remote'); 273 $this->model_extension_payment_firstdata_remote->uninstall(); 274 } 275 276 public function order() { 277 if ($this->config->get('firstdata_remote_status')) { 278 $this->load->model('extension/payment/firstdata_remote'); 279 280 $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->get['order_id']); 281 282 if (!empty($firstdata_order)) { 283 $this->load->language('extension/payment/firstdata_remote'); 284 285 $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); 286 287 $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true); 288 $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true); 289 290 $data['firstdata_order'] = $firstdata_order; 291 292 $data['text_payment_info'] = $this->language->get('text_payment_info'); 293 $data['text_order_ref'] = $this->language->get('text_order_ref'); 294 $data['text_order_total'] = $this->language->get('text_order_total'); 295 $data['text_total_captured'] = $this->language->get('text_total_captured'); 296 $data['text_capture_status'] = $this->language->get('text_capture_status'); 297 $data['text_void_status'] = $this->language->get('text_void_status'); 298 $data['text_refund_status'] = $this->language->get('text_refund_status'); 299 $data['text_transactions'] = $this->language->get('text_transactions'); 300 $data['text_yes'] = $this->language->get('text_yes'); 301 $data['text_no'] = $this->language->get('text_no'); 302 $data['text_column_amount'] = $this->language->get('text_column_amount'); 303 $data['text_column_type'] = $this->language->get('text_column_type'); 304 $data['text_column_date_added'] = $this->language->get('text_column_date_added'); 305 $data['text_confirm_void'] = $this->language->get('text_confirm_void'); 306 $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); 307 $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); 308 309 $data['button_capture'] = $this->language->get('button_capture'); 310 $data['button_refund'] = $this->language->get('button_refund'); 311 $data['button_void'] = $this->language->get('button_void'); 312 313 $data['order_id'] = $this->request->get['order_id']; 314 $data['user_token'] = $this->request->get['user_token']; 315 316 return $this->load->view('extension/payment/firstdata_remote_order', $data); 317 } 318 } 319 } 320 321 public function void() { 322 $this->load->language('extension/payment/firstdata_remote'); 323 324 $json = array(); 325 326 if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { 327 $this->load->model('extension/payment/firstdata_remote'); 328 329 $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); 330 331 $void_response = $this->model_extension_payment_firstdata_remote->void($firstdata_order['order_ref'], $firstdata_order['tdate']); 332 333 $this->model_extension_payment_firstdata_remote->logger('Void result:\r\n' . print_r($void_response, 1)); 334 335 if (strtoupper($void_response['transaction_result']) == 'APPROVED') { 336 $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'void', 0.00); 337 338 $this->model_extension_payment_firstdata_remote->updateVoidStatus($firstdata_order['firstdata_remote_order_id'], 1); 339 340 $json['msg'] = $this->language->get('text_void_ok'); 341 $json['data'] = array(); 342 $json['data']['column_date_added'] = date('Y-m-d H:i:s'); 343 $json['error'] = false; 344 } else { 345 $json['error'] = true; 346 $json['msg'] = isset($void_response['error']) && !empty($void_response['error']) ? (string)$void_response['error'] : 'Unable to void'; 347 } 348 } else { 349 $json['error'] = true; 350 $json['msg'] = 'Missing data'; 351 } 352 353 $this->response->addHeader('Content-Type: application/json'); 354 $this->response->setOutput(json_encode($json)); 355 } 356 357 public function capture() { 358 $this->load->language('extension/payment/firstdata'); 359 $json = array(); 360 361 if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { 362 $this->load->model('extension/payment/firstdata_remote'); 363 364 $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); 365 366 $capture_response = $this->model_extension_payment_firstdata_remote->capture($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']); 367 368 $this->model_extension_payment_firstdata_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); 369 370 if (strtoupper($capture_response['transaction_result']) == 'APPROVED') { 371 $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'payment', $firstdata_order['total']); 372 $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); 373 374 $this->model_extension_payment_firstdata_remote->updateCaptureStatus($firstdata_order['firstdata_remote_order_id'], 1); 375 $capture_status = 1; 376 $json['msg'] = $this->language->get('text_capture_ok_order'); 377 $json['data'] = array(); 378 $json['data']['column_date_added'] = date("Y-m-d H:i:s"); 379 $json['data']['amount'] = (float)$firstdata_order['total']; 380 $json['data']['capture_status'] = $capture_status; 381 $json['data']['total'] = (float)$total_captured; 382 $json['data']['total_formatted'] = $this->currency->format($total_captured, $firstdata_order['currency_code'], 1, true); 383 $json['error'] = false; 384 } else { 385 $json['error'] = true; 386 $json['msg'] = isset($capture_response['error']) && !empty($capture_response['error']) ? (string)$capture_response['error'] : 'Unable to capture'; 387 388 } 389 } else { 390 $json['error'] = true; 391 $json['msg'] = 'Missing data'; 392 } 393 394 $this->response->addHeader('Content-Type: application/json'); 395 $this->response->setOutput(json_encode($json)); 396 } 397 398 public function refund() { 399 $this->load->language('extension/payment/firstdata_remote'); 400 401 $json = array(); 402 403 if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { 404 $this->load->model('extension/payment/firstdata_remote'); 405 406 $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); 407 408 $refund_response = $this->model_extension_payment_firstdata_remote->refund($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']); 409 410 $this->model_extension_payment_firstdata_remote->logger('Refund result:\r\n' . print_r($refund_response, 1)); 411 412 if (strtoupper($refund_response['transaction_result']) == 'APPROVED') { 413 $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'refund', $firstdata_order['total'] * -1); 414 415 $total_refunded = $this->model_extension_payment_firstdata_remote->getTotalRefunded($firstdata_order['firstdata_remote_order_id']); 416 $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); 417 418 if ($total_captured <= 0 && $firstdata_order['capture_status'] == 1) { 419 $this->model_extension_payment_firstdata_remote->updateRefundStatus($firstdata_order['firstdata_remote_order_id'], 1); 420 $refund_status = 1; 421 $json['msg'] = $this->language->get('text_refund_ok_order'); 422 } else { 423 $refund_status = 0; 424 $json['msg'] = $this->language->get('text_refund_ok'); 425 } 426 427 $json['data'] = array(); 428 $json['data']['column_date_added'] = date("Y-m-d H:i:s"); 429 $json['data']['amount'] = $firstdata_order['total'] * -1; 430 $json['data']['total_captured'] = (float)$total_captured; 431 $json['data']['total_refunded'] = (float)$total_refunded; 432 $json['data']['refund_status'] = $refund_status; 433 $json['error'] = false; 434 } else { 435 $json['error'] = true; 436 $json['msg'] = isset($refund_response['error']) && !empty($refund_response['error']) ? (string)$refund_response['error'] : 'Unable to refund'; 437 } 438 } else { 439 $json['error'] = true; 440 $json['msg'] = 'Missing data'; 441 } 442 443 $this->response->addHeader('Content-Type: application/json'); 444 $this->response->setOutput(json_encode($json)); 445 } 446 447 protected function validate() { 448 if (!$this->user->hasPermission('modify', 'extension/payment/firstdata_remote')) { 449 $this->error['warning'] = $this->language->get('error_permission'); 450 } 451 452 if (!$this->request->post['firstdata_remote_merchant_id']) { 453 $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); 454 } 455 456 if (!$this->request->post['firstdata_remote_user_id']) { 457 $this->error['error_user_id'] = $this->language->get('error_user_id'); 458 } 459 460 if (!$this->request->post['firstdata_remote_password']) { 461 $this->error['error_password'] = $this->language->get('error_password'); 462 } 463 464 if (!$this->request->post['firstdata_remote_certificate']) { 465 $this->error['error_certificate'] = $this->language->get('error_certificate'); 466 } 467 468 if (!$this->request->post['firstdata_remote_key']) { 469 $this->error['error_key'] = $this->language->get('error_key'); 470 } 471 472 if (!$this->request->post['firstdata_remote_key_pw']) { 473 $this->error['error_key_pw'] = $this->language->get('error_key_pw'); 474 } 475 476 if (!$this->request->post['firstdata_remote_ca']) { 477 $this->error['error_ca'] = $this->language->get('error_ca'); 478 } 479 480 return !$this->error; 481 } 482 }