shop.balmet.com

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

globalpay.php (13897B)


      1 <?php
      2 class ControllerExtensionPaymentGlobalpay extends Controller {
      3 	public function index() {
      4 		$this->load->language('extension/payment/globalpay');
      5 
      6 		$this->load->model('checkout/order');
      7 
      8 		$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
      9 
     10 		if ($this->config->get('payment_globalpay_live_demo') == 1) {
     11 			$data['action'] = $this->config->get('payment_globalpay_live_url');
     12 		} else {
     13 			$data['action'] = $this->config->get('payment_globalpay_demo_url');
     14 		}
     15 
     16 		if ($this->config->get('payment_globalpay_card_select') == 1) {
     17 			$card_types = array(
     18 				'visa' => $this->language->get('text_card_visa'),
     19 				'mc' => $this->language->get('text_card_mc'),
     20 				'amex' => $this->language->get('text_card_amex'),
     21 				'switch' => $this->language->get('text_card_switch'),
     22 				'laser' => $this->language->get('text_card_laser'),
     23 				'diners' => $this->language->get('text_card_diners'),
     24 			);
     25 
     26 			$data['cards'] = array();
     27 
     28 			$accounts = $this->config->get('payment_globalpay_account');
     29 
     30 			foreach ($accounts as $card => $account) {
     31 				if (isset($account['enabled']) && $account['enabled'] == 1) {
     32 					$data['cards'][] = array(
     33 						'type' => $card_types[$card],
     34 						'account' => (isset($account['default']) && $account['default'] == 1 ? $this->config->get('payment_globalpay_merchant_id') : $account['merchant_id']),
     35 					);
     36 				}
     37 			}
     38 
     39 			$data['card_select'] = true;
     40 		} else {
     41 			$data['card_select'] = false;
     42 		}
     43 
     44 		if ($this->config->get('payment_globalpay_auto_settle') == 0) {
     45 			$data['settle'] = 0;
     46 		} elseif ($this->config->get('payment_globalpay_auto_settle') == 1) {
     47 			$data['settle'] = 1;
     48 		} elseif ($this->config->get('payment_globalpay_auto_settle') == 2) {
     49 			$data['settle'] = 'MULTI';
     50 		}
     51 
     52 		$data['tss'] = (int)$this->config->get('payment_globalpay_tss_check');
     53 		$data['merchant_id'] = $this->config->get('payment_globalpay_merchant_id');
     54 
     55 		$data['timestamp'] = strftime("%Y%m%d%H%M%S");
     56 		$data['order_id'] = $this->session->data['order_id'] . 'T' . $data['timestamp'] . mt_rand(1, 999);
     57 
     58 		$data['amount'] = round($this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false)*100);
     59 		$data['currency'] = $order_info['currency_code'];
     60 
     61 		$tmp = $data['timestamp'] . '.' . $data['merchant_id'] . '.' . $data['order_id'] . '.' . $data['amount'] . '.' . $data['currency'];
     62 		$hash = sha1($tmp);
     63 		$tmp = $hash . '.' . $this->config->get('payment_globalpay_secret');
     64 		$data['hash'] = sha1($tmp);
     65 
     66 		$data['billing_code'] = filter_var(str_replace('-', '', $order_info['payment_postcode']), FILTER_SANITIZE_NUMBER_INT) . '|' . filter_var(str_replace('-', '', $order_info['payment_address_1']), FILTER_SANITIZE_NUMBER_INT);
     67 		$data['payment_country'] = $order_info['payment_iso_code_2'];
     68 
     69 		if ($this->cart->hasShipping()) {
     70 			$data['shipping_code'] = filter_var(str_replace('-', '', $order_info['shipping_postcode']), FILTER_SANITIZE_NUMBER_INT) . '|' . filter_var(str_replace('-', '', $order_info['shipping_address_1']), FILTER_SANITIZE_NUMBER_INT);
     71 			$data['shipping_country'] = $order_info['shipping_iso_code_2'];
     72 		} else {
     73 			$data['shipping_code'] = filter_var(str_replace('-', '', $order_info['payment_postcode']), FILTER_SANITIZE_NUMBER_INT) . '|' . filter_var(str_replace('-', '', $order_info['payment_address_1']), FILTER_SANITIZE_NUMBER_INT);
     74 			$data['shipping_country'] = $order_info['payment_iso_code_2'];
     75 		}
     76 
     77 		$data['response_url'] = HTTPS_SERVER . 'index.php?route=extension/payment/globalpay/notify';
     78 
     79 		return $this->load->view('extension/payment/globalpay', $data);
     80 	}
     81 
     82 	public function notify() {
     83 		$this->load->model('extension/payment/globalpay');
     84 
     85 		$this->model_extension_payment_globalpay->logger(print_r($this->request->post, 1));
     86 
     87 		$this->load->language('extension/payment/globalpay');
     88 
     89 		$hash = sha1($this->request->post['TIMESTAMP'] . '.' . $this->config->get('payment_globalpay_merchant_id') . '.' . $this->request->post['ORDER_ID'] . '.' . $this->request->post['RESULT'] . '.' . $this->request->post['MESSAGE'] . '.' . $this->request->post['PASREF'] . '.' . $this->request->post['AUTHCODE']);
     90 		$tmp = $hash . '.' . $this->config->get('payment_globalpay_secret');
     91 		$hash = sha1($tmp);
     92 
     93 		//Check to see if hashes match or not
     94 		if ($hash != $this->request->post['SHA1HASH']) {
     95 			$data['text_response'] = $this->language->get('text_hash_failed');
     96 			$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
     97 		} else {
     98 			$this->load->model('checkout/order');
     99 
    100 			$order_id_parts = explode('T', $this->request->post['ORDER_ID']);
    101 			$order_id = (int)$order_id_parts[0];
    102 
    103 			$order_info = $this->model_checkout_order->getOrder($order_id);
    104 
    105 			$auto_settle = (int)$this->config->get('payment_globalpay_auto_settle');
    106 			$tss = (int)$this->config->get('payment_globalpay_tss_check');
    107 
    108 			$message = '<strong>' . $this->language->get('text_result') . ':</strong> ' . $this->request->post['RESULT'];
    109 			$message .= '<br /><strong>' . $this->language->get('text_message') . ':</strong> ' . $this->request->post['MESSAGE'];
    110 
    111 			if (isset($this->request->post['ORDER_ID'])) {
    112 				$message .= '<br /><strong>' . $this->language->get('text_order_ref') . ':</strong> ' . $this->request->post['ORDER_ID'];
    113 			}
    114 
    115 			if (isset($this->request->post['CVNRESULT'])) {
    116 				$message .= '<br /><strong>' . $this->language->get('text_cvn_result') . ':</strong> ' . $this->request->post['CVNRESULT'];
    117 			}
    118 
    119 			if (isset($this->request->post['AVSPOSTCODERESULT'])) {
    120 				$message .= '<br /><strong>' . $this->language->get('text_avs_postcode') . ':</strong> ' . $this->request->post['AVSPOSTCODERESULT'];
    121 			}
    122 
    123 			if (isset($this->request->post['AVSADDRESSRESULT'])) {
    124 				$message .= '<br /><strong>' . $this->language->get('text_avs_address') . ':</strong> ' . $this->request->post['AVSADDRESSRESULT'];
    125 			}
    126 
    127 			//3D Secure message
    128 			if (isset($this->request->post['ECI']) && isset($this->request->post['CAVV']) && isset($this->request->post['XID'])) {
    129 				$eci = $this->request->post['ECI'];
    130 
    131 				if (($this->request->post['ECI'] == 6 || $this->request->post['ECI'] == 1) && empty($this->request->post['CAVV']) && empty($this->request->post['XID'])) {
    132 					$scenario_id = 1;
    133 				}
    134 
    135 				if (($this->request->post['ECI'] == 5 || $this->request->post['ECI'] == 0) && !empty($this->request->post['CAVV']) && !empty($this->request->post['XID'])) {
    136 					$scenario_id = 5;
    137 				}
    138 
    139 				if (($this->request->post['ECI'] == 6 || $this->request->post['ECI'] == 1) && !empty($this->request->post['CAVV']) && !empty($this->request->post['XID'])) {
    140 					$scenario_id = 6;
    141 				}
    142 
    143 				if (isset($scenario_id)) {
    144 					$scenario_message = $this->language->get('text_3d_s' . $scenario_id);
    145 				} else {
    146 					if (isset($this->request->post['CARDTYPE'])) {
    147 						if ($this->request->post['CARDTYPE'] == 'VISA') {
    148 							$eci = 7;
    149 						} else {
    150 							$eci = 2;
    151 						}
    152 					}
    153 
    154 					$scenario_message = $this->language->get('text_3d_liability');
    155 				}
    156 
    157 				$message .= '<br /><strong>' . $this->language->get('text_eci') . ':</strong> (' . $eci . ') ' . $scenario_message;
    158 			}
    159 
    160 			if ($tss == 1 && isset($this->request->post['TSS'])) {
    161 				$message .= '<br /><strong>' . $this->language->get('text_tss') . ':</strong> ' . $this->request->post['TSS'];
    162 			}
    163 
    164 			if (isset($this->request->post['TIMESTAMP'])) {
    165 				$message .= '<br /><strong>' . $this->language->get('text_timestamp') . ':</strong> ' . $this->request->post['TIMESTAMP'];
    166 			}
    167 
    168 			if (isset($this->request->post['CARDDIGITS'])) {
    169 				$message .= '<br /><strong>' . $this->language->get('text_card_digits') . ':</strong> ' . $this->request->post['CARDDIGITS'];
    170 			}
    171 
    172 			if (isset($this->request->post['CARDTYPE'])) {
    173 				$message .= '<br /><strong>' . $this->language->get('text_card_type') . ':</strong> ' . $this->request->post['CARDTYPE'];
    174 			}
    175 
    176 			if (isset($this->request->post['EXPDATE'])) {
    177 				$message .= '<br /><strong>' . $this->language->get('text_card_exp') . ':</strong> ' . $this->request->post['EXPDATE'];
    178 			}
    179 
    180 			if (isset($this->request->post['CARDNAME'])) {
    181 				$message .= '<br /><strong>' . $this->language->get('text_card_name') . ':</strong> ' . $this->request->post['CARDNAME'];
    182 			}
    183 
    184 			if (isset($this->request->post['DCCAUTHCARDHOLDERAMOUNT']) && isset($this->request->post['DCCAUTHRATE'])) {
    185 				$message .= '<br /><strong>DCCAUTHCARDHOLDERAMOUNT:</strong> ' . $this->request->post['DCCAUTHCARDHOLDERAMOUNT'];
    186 				$message .= '<br /><strong>DCCAUTHRATE:</strong> ' . $this->request->post['DCCAUTHRATE'];
    187 				$message .= '<br /><strong>DCCAUTHCARDHOLDERCURRENCY:</strong> ' . $this->request->post['DCCAUTHCARDHOLDERCURRENCY'];
    188 				$message .= '<br /><strong>DCCAUTHMERCHANTCURRENCY:</strong> ' . $this->request->post['DCCAUTHMERCHANTCURRENCY'];
    189 				$message .= '<br /><strong>DCCAUTHMERCHANTAMOUNT:</strong> ' . $this->request->post['DCCAUTHMERCHANTAMOUNT'];
    190 				$message .= '<br /><strong>DCCCCP:</strong> ' . $this->request->post['DCCCCP'];
    191 				$message .= '<br /><strong>DCCRATE:</strong> ' . $this->request->post['DCCRATE'];
    192 				$message .= '<br /><strong>DCCMARGINRATEPERCENTAGE:</strong> ' . $this->request->post['DCCMARGINRATEPERCENTAGE'];
    193 				$message .= '<br /><strong>DCCEXCHANGERATESOURCENAME:</strong> ' . $this->request->post['DCCEXCHANGERATESOURCENAME'];
    194 				$message .= '<br /><strong>DCCCOMMISSIONPERCENTAGE:</strong> ' . $this->request->post['DCCCOMMISSIONPERCENTAGE'];
    195 				$message .= '<br /><strong>DCCEXCHANGERATESOURCETIMESTAMP:</strong> ' . $this->request->post['DCCEXCHANGERATESOURCETIMESTAMP'];
    196 				$message .= '<br /><strong>DCCCHOICE:</strong> ' . $this->request->post['DCCCHOICE'];
    197 			}
    198 
    199 			if ($this->request->post['RESULT'] == "00") {
    200 				$globalpay_order_id = $this->model_extension_payment_globalpay->addOrder($order_info, $this->request->post['PASREF'], $this->request->post['AUTHCODE'], $this->request->post['ACCOUNT'], $this->request->post['ORDER_ID']);
    201 
    202 				if ($auto_settle == 1) {
    203 					$this->model_extension_payment_globalpay->addTransaction($globalpay_order_id, 'payment', $order_info);
    204 					$this->model_checkout_order->addOrderHistory($order_id, $this->config->get('globalpay_order_status_success_settled_id'), $message, false);
    205 				} else {
    206 					$this->model_extension_payment_globalpay->addTransaction($globalpay_order_id, 'auth', 0.00);
    207 					$this->model_checkout_order->addOrderHistory($order_id, $this->config->get('payment_globalpay_order_status_success_unsettled_id'), $message, false);
    208 				}
    209 
    210 				$data['text_response'] = $this->language->get('text_success');
    211 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/success', '', true));
    212 			} elseif ($this->request->post['RESULT'] == "101") {
    213 				// Decline
    214 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_id'), $message);
    215 				$data['text_response'] = $this->language->get('text_decline');
    216 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    217 			} elseif ($this->request->post['RESULT'] == "102") {
    218 				// Referal B
    219 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_pending_id'), $message);
    220 				$data['text_response'] = $this->language->get('text_decline');
    221 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    222 			} elseif ($this->request->post['RESULT'] == "103") {
    223 				// Referal A
    224 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_stolen_id'), $message);
    225 				$data['text_response'] = $this->language->get('text_decline');
    226 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    227 			} elseif ($this->request->post['RESULT'] == "200") {
    228 				// Error Connecting to Bank
    229 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_bank_id'), $message);
    230 				$data['text_response'] = $this->language->get('text_bank_error');
    231 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    232 			} elseif ($this->request->post['RESULT'] == "204") {
    233 				// Error Connecting to Bank
    234 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_bank_id'), $message);
    235 				$data['text_response'] = $this->language->get('text_bank_error');
    236 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    237 			} elseif ($this->request->post['RESULT'] == "205") {
    238 				// Comms Error
    239 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_bank_id'), $message);
    240 				$data['text_response'] = $this->language->get('text_bank_error');
    241 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    242 			} else {
    243 				// Other error
    244 				$this->model_extension_payment_globalpay->addHistory($order_id, $this->config->get('payment_globalpay_order_status_decline_id'), $message);
    245 				$data['text_response'] = $this->language->get('text_generic_error');
    246 				$data['text_link'] = sprintf($this->language->get('text_link'), $this->url->link('checkout/checkout', '', true));
    247 			}
    248 		}
    249 
    250 		$this->response->setOutput($this->load->view('extension/payment/globalpay_response', $data));
    251 	}
    252 }