globalpay_remote.php (12602B)
1 <?php 2 class ControllerExtensionPaymentGlobalpayRemote extends Controller { 3 public function index() { 4 $this->load->language('extension/payment/globalpay_remote'); 5 6 $accounts = $this->config->get('payment_globalpay_remote_account'); 7 8 $card_types = array( 9 'visa' => $this->language->get('text_card_visa'), 10 'mc' => $this->language->get('text_card_mc'), 11 'amex' => $this->language->get('text_card_amex'), 12 'switch' => $this->language->get('text_card_switch'), 13 'laser' => $this->language->get('text_card_laser'), 14 'diners' => $this->language->get('text_card_diners'), 15 ); 16 17 $data['cards'] = array(); 18 19 foreach ($accounts as $card => $account) { 20 if (isset($account['enabled']) && $account['enabled'] == 1) { 21 $data['cards'][] = array( 22 'code' => $card, 23 'text' => $card_types[$card], 24 ); 25 } 26 } 27 28 $data['months'] = array(); 29 30 for ($i = 1; $i <= 12; $i++) { 31 $data['months'][] = array( 32 'text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)), 33 'value' => sprintf('%02d', $i) 34 ); 35 } 36 37 $today = getdate(); 38 39 $data['year_expire'] = array(); 40 41 for ($i = $today['year']; $i < $today['year'] + 11; $i++) { 42 $data['year_expire'][] = array( 43 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)), 44 'value' => strftime('%y', mktime(0, 0, 0, 1, 1, $i)) 45 ); 46 } 47 48 return $this->load->view('extension/payment/globalpay_remote', $data); 49 } 50 51 public function send() { 52 $this->load->model('checkout/order'); 53 $this->load->model('extension/payment/globalpay_remote'); 54 55 $this->load->language('extension/payment/globalpay_remote'); 56 57 if ($this->request->post['cc_number'] == '') { 58 $json['error'] = $this->language->get('error_card_number'); 59 } 60 61 if ($this->request->post['cc_name'] == '') { 62 $json['error'] = $this->language->get('error_card_name'); 63 } 64 65 if (strlen($this->request->post['cc_cvv2']) != 3 && strlen($this->request->post['cc_cvv2']) != 4) { 66 $json['error'] = $this->language->get('error_card_cvv'); 67 } 68 69 if (isset($json['error'])) { 70 $this->response->addHeader('Content-Type: application/json'); 71 $this->response->setOutput(json_encode($json)); 72 die(); 73 } 74 75 $order_id = $this->session->data['order_id']; 76 77 $order_ref = $order_id . 'T' . strftime("%Y%m%d%H%M%S") . mt_rand(1, 999); 78 79 $order_info = $this->model_checkout_order->getOrder($order_id); 80 81 $amount = round($this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false) * 100); 82 $currency = $order_info['currency_code']; 83 84 $accounts = $this->config->get('payment_globalpay_remote_account'); 85 86 if (isset($accounts[$this->request->post['cc_type']]['default']) && $accounts[$this->request->post['cc_type']]['default'] == 1) { 87 $account = $this->config->get('payment_globalpay_remote_merchant_id'); 88 } else { 89 $account = $accounts[$this->request->post['cc_type']]['merchant_id']; 90 } 91 92 $eci_ref = ''; 93 $eci = ''; 94 $cavv = ''; 95 $xid = ''; 96 97 if ($this->config->get('payment_globalpay_remote_3d') == 1) { 98 if ($this->request->post['cc_type'] == 'visa' || $this->request->post['cc_type'] == 'mc' || $this->request->post['cc_type'] == 'amex') { 99 $verify_3ds = $this->model_extension_payment_globalpay_remote->checkEnrollment($account, $amount, $currency, $order_ref); 100 101 $this->model_extension_payment_globalpay_remote->logger('Verify 3DS result:\r\n' . print_r($verify_3ds, 1)); 102 103 // Proceed to 3D secure 104 if (isset($verify_3ds->result) && $verify_3ds->result == '00') { 105 $enc_data = array( 106 'account' => $account, 107 'amount' => $amount, 108 'currency' => $currency, 109 'order_id' => $order_id, 110 'order_ref' => $order_ref, 111 'cc_number' => $this->request->post['cc_number'], 112 'cc_expire' => $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'], 113 'cc_name' => $this->request->post['cc_name'], 114 'cc_type' => $this->request->post['cc_type'], 115 'cc_cvv2' => $this->request->post['cc_cvv2'], 116 'cc_issue' => $this->request->post['cc_issue'] 117 ); 118 119 $md = $this->encryption->encrypt($this->config->get('config_encryption'), json_encode($enc_data)); 120 121 $json = array(); 122 $json['ACSURL'] = (string)$verify_3ds->url; 123 $json['MD'] = $md; 124 $json['PaReq'] = (string)$verify_3ds->pareq; 125 $json['TermUrl'] = $this->url->link('extension/payment/globalpay_remote/acsReturn', '', true); 126 127 $this->response->addHeader('Content-Type: application/json'); 128 $this->response->setOutput(json_encode($json)); 129 $this->response->output(); 130 die(); 131 } 132 133 // Cardholder Not Enrolled. Shift in liability. ECI = 6 134 if (isset($verify_3ds->result) && $verify_3ds->result == '110' && isset($verify_3ds->enrolled) && $verify_3ds->enrolled == 'N') { 135 $eci_ref = 1; 136 $xid = ''; 137 $cavv = ''; 138 if ($this->request->post['cc_type'] == 'mc') { 139 $eci = 1; 140 } else { 141 $eci = 6; 142 } 143 } 144 145 // Unable to Verify Enrollment. No shift in liability. ECI = 7 146 if (isset($verify_3ds->result) && $verify_3ds->result == '110' && isset($verify_3ds->enrolled) && $verify_3ds->enrolled == 'U') { 147 if ($this->config->get('payment_globalpay_remote_liability') != 1) { 148 $this->load->language('extension/payment/globalpay_remote'); 149 150 $json['error'] = $this->language->get('error_3d_unable'); 151 152 $this->response->addHeader('Content-Type: application/json'); 153 $this->response->setOutput(json_encode($json)); 154 $this->response->output(); 155 die(); 156 } else { 157 $eci_ref = 2; 158 $xid = ''; 159 $cavv = ''; 160 if ($this->request->post['cc_type'] == 'mc') { 161 $eci = 0; 162 } else { 163 $eci = 7; 164 } 165 } 166 } 167 168 // Invalid response from Enrollment Server. No shift in liability. ECI = 7 169 if (isset($verify_3ds->result) && $verify_3ds->result >= 500 && $verify_3ds->result < 600) { 170 if ($this->config->get('payment_globalpay_remote_liability') != 1) { 171 $this->load->language('extension/payment/globalpay_remote'); 172 173 $json['error'] = (string)$verify_3ds->message; 174 175 $this->response->addHeader('Content-Type: application/json'); 176 $this->response->setOutput(json_encode($json)); 177 $this->response->output(); 178 die(); 179 } else { 180 $eci_ref = 3; 181 if ($this->request->post['cc_type'] == 'mc') { 182 $eci = 0; 183 } else { 184 $eci = 7; 185 } 186 } 187 } 188 } 189 } 190 191 $capture_result = $this->model_extension_payment_globalpay_remote->capturePayment( 192 $account, 193 $amount, 194 $currency, 195 $order_id, 196 $order_ref, 197 $this->request->post['cc_number'], 198 $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'], 199 $this->request->post['cc_name'], 200 $this->request->post['cc_type'], 201 $this->request->post['cc_cvv2'], 202 $this->request->post['cc_issue'], 203 $eci_ref, 204 $eci, 205 $cavv, 206 $xid 207 ); 208 209 $this->model_extension_payment_globalpay_remote->logger('Capture result:\r\n' . print_r($capture_result, 1)); 210 211 if ($capture_result->result != '00') { 212 $json['error'] = (string)$capture_result->message . ' (' . (int)$capture_result->result . ')'; 213 } else { 214 $json['success'] = $this->url->link('checkout/success'); 215 } 216 217 $this->response->addHeader('Content-Type: application/json'); 218 $this->response->setOutput(json_encode($json)); 219 } 220 221 public function acsReturn() { 222 if (isset($this->session->data['order_id'])) { 223 $this->load->model('checkout/order'); 224 $this->load->model('extension/payment/globalpay_remote'); 225 226 $post = $this->request->post; 227 228 $md = json_decode($this->encryption->decrypt($this->config->get('config_encryption'), $post['MD']), true); 229 230 $signature_result = $this->model_extension_payment_globalpay_remote->enrollmentSignature($md['account'], $md['amount'], $md['currency'], $md['order_ref'], $md['cc_number'], $md['cc_expire'], $md['cc_type'], $md['cc_name'], $post['PaRes']); 231 232 $this->model_extension_payment_globalpay_remote->logger('Signature result:\r\n' . print_r($signature_result, 1)); 233 234 if ($signature_result->result == '00' && (strtoupper($signature_result->threedsecure->status) == 'Y' || strtoupper($signature_result->threedsecure->status) == 'A')) { 235 if (strtoupper($signature_result->threedsecure->status) == 'Y') { 236 $eci_ref = 5; 237 } else { 238 $eci_ref = 6; 239 } 240 241 $eci = (string)$signature_result->threedsecure->eci; 242 $cavv = (string)$signature_result->threedsecure->cavv; 243 $xid = (string)$signature_result->threedsecure->xid; 244 } else { 245 if ($md['cc_type'] == 'mc') { 246 $eci = 0; 247 } else { 248 $eci = 7; 249 } 250 251 // Enrolled but invalid response from ACS. No shift in liability. ECI = 7 252 if ($signature_result->result == '110' && strtoupper($signature_result->threedsecure->status) == 'Y') { 253 $eci_ref = 4; 254 $cavv = (string)$signature_result->threedsecure->cavv; 255 $xid = (string)$signature_result->threedsecure->xid; 256 } 257 258 // Incorrect password entered. No shift in liability. ECI = 7 259 if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'N') { 260 $eci_ref = 7; 261 $xid = (string)$signature_result->threedsecure->xid; 262 $cavv = ''; 263 } 264 265 // Authentication Unavailable. No shift in liability. ECI = 7 266 if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'U') { 267 $eci_ref = 8; 268 $xid = (string)$signature_result->threedsecure->xid; 269 $cavv = ''; 270 } 271 272 // Invalid response from ACS. No shift in liability. ECI = 7 273 if (isset($signature_result->result) && $signature_result->result >= 500 && $signature_result->result < 600) { 274 $eci_ref = 9; 275 $xid = ''; 276 $cavv = ''; 277 } 278 279 if ($this->config->get('payment_globalpay_remote_liability') != 1) { 280 // this is the check for liability shift - if the merchant does not want to accept, redirect to checkout with message 281 $this->load->language('extension/payment/globalpay_remote'); 282 283 $message = $this->language->get('error_3d_unsuccessful'); 284 $message .= '<br /><strong>' . $this->language->get('text_eci') . ':</strong> (' . $eci . ') ' . $this->language->get('text_3d_s' . (int)$eci_ref); 285 $message .= '<br /><strong>' . $this->language->get('text_timestamp') . ':</strong> ' . (string)strftime("%Y%m%d%H%M%S"); 286 $message .= '<br /><strong>' . $this->language->get('text_order_ref') . ':</strong> ' . (string)$md['order_ref']; 287 288 if ($this->config->get('payment_globalpay_remote_card_data_status') == 1) { 289 $message .= '<br /><strong>' . $this->language->get('entry_cc_type') . ':</strong> ' . (string)$md['cc_type']; 290 $message .= '<br /><strong>' . $this->language->get('text_last_digits') . ':</strong> ' . (string)substr($md['cc_number'], -4); 291 $message .= '<br /><strong>' . $this->language->get('entry_cc_expire_date') . ':</strong> ' . (string)$md['cc_expire']; 292 $message .= '<br /><strong>' . $this->language->get('entry_cc_name') . ':</strong> ' . (string)$md['cc_name']; 293 } 294 295 $this->model_extension_payment_globalpay_remote->addHistory($md['order_id'], $this->config->get('payment_globalpay_remote_order_status_decline_id'), $message); 296 297 $this->session->data['error'] = $this->language->get('error_3d_unsuccessful'); 298 299 $this->response->redirect($this->url->link('checkout/checkout', '', true)); 300 die(); 301 } 302 } 303 304 $capture_result = $this->model_extension_payment_globalpay_remote->capturePayment( 305 $md['account'], 306 $md['amount'], 307 $md['currency'], 308 $md['order_id'], 309 $md['order_ref'], 310 $md['cc_number'], 311 $md['cc_expire'], 312 $md['cc_name'], 313 $md['cc_type'], 314 $md['cc_cvv2'], 315 $md['cc_issue'], 316 $eci_ref, 317 $eci, 318 $cavv, 319 $xid 320 ); 321 322 $this->model_extension_payment_globalpay_remote->logger('Capture result:\r\n' . print_r($capture_result, 1)); 323 324 if ($capture_result->result != '00') { 325 $this->session->data['error'] = (string)$capture_result->message . ' (' . (int)$capture_result->result . ')'; 326 327 $this->response->redirect($this->url->link('checkout/checkout', '', true)); 328 } else { 329 $this->response->redirect($this->url->link('checkout/success')); 330 } 331 } else { 332 $this->response->redirect($this->url->link('account/login', '', true)); 333 } 334 } 335 }