shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

firstdata.php (15263B)


      1 <?php
      2 class ControllerExtensionPaymentFirstdata extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('extension/payment/firstdata');
      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', $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 		$data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify';
     21 
     22 		$this->load->model('localisation/order_status');
     23 
     24 		$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
     25 
     26 		$this->load->model('localisation/geo_zone');
     27 
     28 		$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
     29 
     30 		if (isset($this->error['warning'])) {
     31 			$data['error_warning'] = $this->error['warning'];
     32 		} else {
     33 			$data['error_warning'] = '';
     34 		}
     35 
     36 		if (isset($this->error['error_merchant_id'])) {
     37 			$data['error_merchant_id'] = $this->error['error_merchant_id'];
     38 		} else {
     39 			$data['error_merchant_id'] = '';
     40 		}
     41 
     42 		if (isset($this->error['error_secret'])) {
     43 			$data['error_secret'] = $this->error['error_secret'];
     44 		} else {
     45 			$data['error_secret'] = '';
     46 		}
     47 
     48 		if (isset($this->error['error_live_url'])) {
     49 			$data['error_live_url'] = $this->error['error_live_url'];
     50 		} else {
     51 			$data['error_live_url'] = '';
     52 		}
     53 
     54 		if (isset($this->error['error_demo_url'])) {
     55 			$data['error_demo_url'] = $this->error['error_demo_url'];
     56 		} else {
     57 			$data['error_demo_url'] = '';
     58 		}
     59 
     60 		$data['breadcrumbs'] = array();
     61 
     62 		$data['breadcrumbs'][] = array(
     63 			'text' => $this->language->get('text_home'),
     64 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     65 		);
     66 
     67 		$data['breadcrumbs'][] = array(
     68 			'text' => $this->language->get('text_extension'),
     69 			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
     70 		);
     71 
     72 		$data['breadcrumbs'][] = array(
     73 			'text' => $this->language->get('heading_title'),
     74 			'href' => $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true)
     75 		);
     76 
     77 		$data['action'] = $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true);
     78 		
     79 		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true);
     80 
     81 		if (isset($this->request->post['payment_firstdata_merchant_id'])) {
     82 			$data['payment_firstdata_merchant_id'] = $this->request->post['payment_firstdata_merchant_id'];
     83 		} else {
     84 			$data['payment_firstdata_merchant_id'] = $this->config->get('payment_firstdata_merchant_id');
     85 		}
     86 
     87 		if (isset($this->request->post['payment_firstdata_secret'])) {
     88 			$data['payment_firstdata_secret'] = $this->request->post['payment_firstdata_secret'];
     89 		} else {
     90 			$data['payment_firstdata_secret'] = $this->config->get('payment_firstdata_secret');
     91 		}
     92 
     93 		if (isset($this->request->post['payment_firstdata_live_demo'])) {
     94 			$data['payment_firstdata_live_demo'] = $this->request->post['payment_firstdata_live_demo'];
     95 		} else {
     96 			$data['payment_firstdata_live_demo'] = $this->config->get('payment_firstdata_live_demo');
     97 		}
     98 
     99 		if (isset($this->request->post['payment_firstdata_geo_zone_id'])) {
    100 			$data['payment_firstdata_geo_zone_id'] = $this->request->post['payment_firstdata_geo_zone_id'];
    101 		} else {
    102 			$data['payment_firstdata_geo_zone_id'] = $this->config->get('payment_firstdata_geo_zone_id');
    103 		}
    104 
    105 		if (isset($this->request->post['payment_firstdata_total'])) {
    106 			$data['payment_firstdata_total'] = $this->request->post['payment_firstdata_total'];
    107 		} else {
    108 			$data['payment_firstdata_total'] = $this->config->get('payment_firstdata_total');
    109 		}
    110 
    111 		if (isset($this->request->post['payment_firstdata_sort_order'])) {
    112 			$data['payment_firstdata_sort_order'] = $this->request->post['payment_firstdata_sort_order'];
    113 		} else {
    114 			$data['payment_firstdata_sort_order'] = $this->config->get('payment_firstdata_sort_order');
    115 		}
    116 
    117 		if (isset($this->request->post['payment_firstdata_status'])) {
    118 			$data['payment_firstdata_status'] = $this->request->post['payment_firstdata_status'];
    119 		} else {
    120 			$data['payment_firstdata_status'] = $this->config->get('payment_firstdata_status');
    121 		}
    122 
    123 		if (isset($this->request->post['payment_firstdata_debug'])) {
    124 			$data['payment_firstdata_debug'] = $this->request->post['payment_firstdata_debug'];
    125 		} else {
    126 			$data['payment_firstdata_debug'] = $this->config->get('payment_firstdata_debug');
    127 		}
    128 
    129 		if (isset($this->request->post['payment_firstdata_auto_settle'])) {
    130 			$data['payment_firstdata_auto_settle'] = $this->request->post['payment_firstdata_auto_settle'];
    131 		} elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('payment_firstdata_auto_settle') != '') {
    132 			$data['payment_firstdata_auto_settle'] = $this->config->get('payment_firstdata_auto_settle');
    133 		} else {
    134 			$data['payment_firstdata_auto_settle'] = 1;
    135 		}
    136 
    137 		if (isset($this->request->post['payment_firstdata_order_status_success_settled_id'])) {
    138 			$data['payment_firstdata_order_status_success_settled_id'] = $this->request->post['payment_firstdata_order_status_success_settled_id'];
    139 		} else {
    140 			$data['payment_firstdata_order_status_success_settled_id'] = $this->config->get('payment_firstdata_order_status_success_settled_id');
    141 		}
    142 
    143 		if (isset($this->request->post['payment_firstdata_order_status_success_unsettled_id'])) {
    144 			$data['payment_firstdata_order_status_success_unsettled_id'] = $this->request->post['payment_firstdata_order_status_success_unsettled_id'];
    145 		} else {
    146 			$data['payment_firstdata_order_status_success_unsettled_id'] = $this->config->get('payment_firstdata_order_status_success_unsettled_id');
    147 		}
    148 
    149 		if (isset($this->request->post['payment_firstdata_order_status_decline_id'])) {
    150 			$data['payment_firstdata_order_status_decline_id'] = $this->request->post['payment_firstdata_order_status_decline_id'];
    151 		} else {
    152 			$data['payment_firstdata_order_status_decline_id'] = $this->config->get('payment_firstdata_order_status_decline_id');
    153 		}
    154 
    155 		if (isset($this->request->post['payment_firstdata_order_status_void_id'])) {
    156 			$data['payment_firstdata_order_status_void_id'] = $this->request->post['payment_firstdata_order_status_void_id'];
    157 		} else {
    158 			$data['payment_firstdata_order_status_void_id'] = $this->config->get('payment_firstdata_order_status_void_id');
    159 		}
    160 
    161 		if (isset($this->request->post['payment_firstdata_live_url'])) {
    162 			$data['payment_firstdata_live_url'] = $this->request->post['payment_firstdata_live_url'];
    163 		} else {
    164 			$data['payment_firstdata_live_url'] = $this->config->get('payment_firstdata_live_url');
    165 		}
    166 
    167 		if (empty($data['payment_firstdata_live_url'])) {
    168 			$data['payment_firstdata_live_url'] = 'https://ipg-online.com/connect/gateway/processing';
    169 		}
    170 
    171 		if (isset($this->request->post['payment_firstdata_demo_url'])) {
    172 			$data['payment_firstdata_demo_url'] = $this->request->post['payment_firstdata_demo_url'];
    173 		} else {
    174 			$data['payment_firstdata_demo_url'] = $this->config->get('payment_firstdata_demo_url');
    175 		}
    176 
    177 		if (isset($this->request->post['payment_firstdata_card_storage'])) {
    178 			$data['payment_firstdata_card_storage'] = $this->request->post['payment_firstdata_card_storage'];
    179 		} else {
    180 			$data['payment_firstdata_card_storage'] = $this->config->get('payment_firstdata_card_storage');
    181 		}
    182 
    183 		if (empty($data['payment_firstdata_demo_url'])) {
    184 			$data['payment_firstdata_demo_url'] = 'https://test.ipg-online.com/connect/gateway/processing';
    185 		}
    186 
    187 		$data['header'] = $this->load->controller('common/header');
    188 		$data['column_left'] = $this->load->controller('common/column_left');
    189 		$data['footer'] = $this->load->controller('common/footer');
    190 
    191 		$this->response->setOutput($this->load->view('extension/payment/firstdata', $data));
    192 	}
    193 
    194 	public function install() {
    195 		$this->load->model('extension/payment/firstdata');
    196 		$this->model_extension_payment_firstdata->install();
    197 	}
    198 
    199 	public function uninstall() {
    200 		$this->load->model('extension/payment/firstdata');
    201 		$this->model_extension_payment_firstdata->uninstall();
    202 	}
    203 
    204 	public function order() {
    205 		if ($this->config->get('payment_firstdata_status')) {
    206 			$this->load->model('extension/payment/firstdata');
    207 
    208 			$firstdata_order = $this->model_extension_payment_firstdata->getOrder($this->request->get['order_id']);
    209 
    210 			if (!empty($firstdata_order)) {
    211 				$this->load->language('extension/payment/firstdata');
    212 
    213 				$firstdata_order['total_captured'] = $this->model_extension_payment_firstdata->getTotalCaptured($firstdata_order['firstdata_order_id']);
    214 				$firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true);
    215 				$firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true);
    216 
    217 				$data['firstdata_order'] = $firstdata_order;
    218 				$data['merchant_id'] = $this->config->get('payment_firstdata_merchant_id');
    219 				$data['currency'] = $this->model_extension_payment_firstdata->mapCurrency($firstdata_order['currency_code']);
    220 				$data['amount'] = number_format($firstdata_order['total'], 2);
    221 
    222 				$data['request_timestamp'] = date("Y:m:d-H:i:s");
    223 
    224 				$data['hash'] = sha1(bin2hex($data['merchant_id'] . $data['request_timestamp'] . $data['amount'] . $data['currency'] . $this->config->get('payment_firstdata_secret')));
    225 
    226 				$data['void_url'] = $this->url->link('extension/payment/firstdata/void', 'user_token=' . $this->session->data['user_token'], true);
    227 				$data['capture_url'] = $this->url->link('extension/payment/firstdata/capture', 'user_token=' . $this->session->data['user_token'], true);
    228 				$data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify';
    229 
    230 				if ($this->config->get('payment_firstdata_live_demo') == 1) {
    231 					$data['action_url'] = $this->config->get('payment_firstdata_live_url');
    232 				} else {
    233 					$data['action_url'] = $this->config->get('payment_firstdata_demo_url');
    234 				}
    235 
    236 				if (isset($this->session->data['void_success'])) {
    237 					$data['void_success'] = $this->session->data['void_success'];
    238 
    239 					unset($this->session->data['void_success']);
    240 				} else {
    241 					$data['void_success'] = '';
    242 				}
    243 
    244 				if (isset($this->session->data['void_error'])) {
    245 					$data['void_error'] = $this->session->data['void_error'];
    246 
    247 					unset($this->session->data['void_error']);
    248 				} else {
    249 					$data['void_error'] = '';
    250 				}
    251 
    252 				if (isset($this->session->data['capture_success'])) {
    253 					$data['capture_success'] = $this->session->data['capture_success'];
    254 
    255 					unset($this->session->data['capture_success']);
    256 				} else {
    257 					$data['capture_success'] = '';
    258 				}
    259 
    260 				if (isset($this->session->data['capture_error'])) {
    261 					$data['capture_error'] = $this->session->data['capture_error'];
    262 
    263 					unset($this->session->data['capture_error']);
    264 				} else {
    265 					$data['capture_error'] = '';
    266 				}
    267 
    268 				$data['text_payment_info'] = $this->language->get('text_payment_info');
    269 				$data['text_order_ref'] = $this->language->get('text_order_ref');
    270 				$data['text_order_total'] = $this->language->get('text_order_total');
    271 				$data['text_total_captured'] = $this->language->get('text_total_captured');
    272 				$data['text_capture_status'] = $this->language->get('text_capture_status');
    273 				$data['text_void_status'] = $this->language->get('text_void_status');
    274 				$data['text_transactions'] = $this->language->get('text_transactions');
    275 				$data['text_yes'] = $this->language->get('text_yes');
    276 				$data['text_no'] = $this->language->get('text_no');
    277 				$data['text_column_amount'] = $this->language->get('text_column_amount');
    278 				$data['text_column_type'] = $this->language->get('text_column_type');
    279 				$data['text_column_date_added'] = $this->language->get('text_column_date_added');
    280 				$data['button_capture'] = $this->language->get('button_capture');
    281 				$data['button_void'] = $this->language->get('button_void');
    282 				$data['text_confirm_void'] = $this->language->get('text_confirm_void');
    283 				$data['text_confirm_capture'] = $this->language->get('text_confirm_capture');
    284 
    285 				$data['order_id'] = $this->request->get['order_id'];
    286 				$data['user_token'] = $this->request->get['user_token'];
    287 
    288 				return $this->load->view('extension/payment/firstdata_order', $data);
    289 			}
    290 		}
    291 	}
    292 
    293 	public function void() {
    294 		$this->load->language('extension/payment/firstdata');
    295 
    296 		if ($this->request->post['status'] == 'FAILED') {
    297 			if (isset($this->request->post['fail_reason'])) {
    298 				$this->session->data['void_error'] = $this->request->post['fail_reason'];
    299 			} else {
    300 				$this->session->data['void_error'] = $this->language->get('error_void_error');
    301 			}
    302 		}
    303 
    304 		if ($this->request->post['status'] == 'DECLINED') {
    305 			$this->session->data['void_success'] = $this->language->get('success_void');
    306 		}
    307 
    308 		$this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true));
    309 	}
    310 
    311 	public function capture() {
    312 		$this->load->language('extension/payment/firstdata');
    313 
    314 		if ($this->request->post['status'] == 'FAILED') {
    315 			if (isset($this->request->post['fail_reason'])) {
    316 				$this->session->data['capture_error'] = $this->request->post['fail_reason'];
    317 			} else {
    318 				$this->session->data['capture_error'] = $this->language->get('error_capture_error');
    319 			}
    320 		}
    321 
    322 		if ($this->request->post['status'] == 'APPROVED') {
    323 			$this->session->data['capture_success'] = $this->language->get('success_capture');
    324 		}
    325 
    326 		$this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true));
    327 	}
    328 
    329 	protected function validate() {
    330 		if (!$this->user->hasPermission('modify', 'extension/payment/firstdata')) {
    331 			$this->error['warning'] = $this->language->get('error_permission');
    332 		}
    333 
    334 		if (!$this->request->post['payment_firstdata_merchant_id']) {
    335 			$this->error['error_merchant_id'] = $this->language->get('error_merchant_id');
    336 		}
    337 
    338 		if (!$this->request->post['payment_firstdata_secret']) {
    339 			$this->error['error_secret'] = $this->language->get('error_secret');
    340 		}
    341 
    342 		if (!$this->request->post['payment_firstdata_live_url']) {
    343 			$this->error['error_live_url'] = $this->language->get('error_live_url');
    344 		}
    345 
    346 		if (!$this->request->post['payment_firstdata_demo_url']) {
    347 			$this->error['error_demo_url'] = $this->language->get('error_demo_url');
    348 		}
    349 
    350 		return !$this->error;
    351 	}
    352 }