authorizenet_sim.php (4934B)
1 <?php 2 class ControllerExtensionPaymentAuthorizeNetSim extends Controller { 3 public function index() { 4 $this->load->language('extension/payment/authorizenet_sim'); 5 6 $data['button_confirm'] = $this->language->get('button_confirm'); 7 8 $this->load->model('checkout/order'); 9 10 $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); 11 12 $data['x_login'] = $this->config->get('payment_authorizenet_sim_merchant'); 13 $data['x_fp_sequence'] = $this->session->data['order_id']; 14 $data['x_fp_timestamp'] = time(); 15 $data['x_amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false); 16 $data['x_fp_hash'] = null; // calculated later, once all fields are populated 17 $data['x_show_form'] = 'PAYMENT_FORM'; 18 $data['x_test_request'] = $this->config->get('authorizenet_sim_mode'); 19 $data['x_type'] = 'AUTH_CAPTURE'; 20 $data['x_currency_code'] = $this->session->data['currency']; 21 $data['x_invoice_num'] = $this->session->data['order_id']; 22 $data['x_description'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); 23 $data['x_first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8'); 24 $data['x_last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8'); 25 $data['x_company'] = html_entity_decode($order_info['payment_company'], ENT_QUOTES, 'UTF-8'); 26 $data['x_address'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8'); 27 $data['x_city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8'); 28 $data['x_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8'); 29 $data['x_zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8'); 30 $data['x_country'] = html_entity_decode($order_info['payment_country'], ENT_QUOTES, 'UTF-8'); 31 $data['x_phone'] = $order_info['telephone']; 32 $data['x_ship_to_first_name'] = html_entity_decode($order_info['shipping_firstname'], ENT_QUOTES, 'UTF-8'); 33 $data['x_ship_to_last_name'] = html_entity_decode($order_info['shipping_lastname'], ENT_QUOTES, 'UTF-8'); 34 $data['x_ship_to_company'] = html_entity_decode($order_info['shipping_company'], ENT_QUOTES, 'UTF-8'); 35 $data['x_ship_to_address'] = html_entity_decode($order_info['shipping_address_1'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['shipping_address_2'], ENT_QUOTES, 'UTF-8'); 36 $data['x_ship_to_city'] = html_entity_decode($order_info['shipping_city'], ENT_QUOTES, 'UTF-8'); 37 $data['x_ship_to_state'] = html_entity_decode($order_info['shipping_zone'], ENT_QUOTES, 'UTF-8'); 38 $data['x_ship_to_zip'] = html_entity_decode($order_info['shipping_postcode'], ENT_QUOTES, 'UTF-8'); 39 $data['x_ship_to_country'] = html_entity_decode($order_info['shipping_country'], ENT_QUOTES, 'UTF-8'); 40 $data['x_customer_ip'] = $this->request->server['REMOTE_ADDR']; 41 $data['x_email'] = $order_info['email']; 42 $data['x_relay_response'] = 'true'; 43 44 $data['x_fp_hash'] = hash_hmac('md5', $data['x_login'] . '^' . $data['x_fp_sequence'] . '^' . $data['x_fp_timestamp'] . '^' . $data['x_amount'] . '^' . $data['x_currency_code'], $this->config->get('payment_authorizenet_sim_key')); 45 46 return $this->load->view('extension/payment/authorizenet_sim', $data); 47 } 48 49 public function callback() { 50 if (md5($this->config->get('authorizenet_sim_response_key') . $this->request->post['x_login'] . $this->request->post['x_trans_id'] . $this->request->post['x_amount']) == strtolower($this->request->post['x_MD5_Hash'])) { 51 $this->load->model('checkout/order'); 52 53 $order_info = $this->model_checkout_order->getOrder($details['x_invoice_num']); 54 55 if ($order_info && $this->request->post['x_response_code'] == '1') { 56 $message = ''; 57 58 if (isset($this->request->post['x_response_reason_text'])) { 59 $message .= 'Response Text: ' . $this->request->post['x_response_reason_text'] . "\n"; 60 } 61 62 if (isset($this->request->post['exact_issname'])) { 63 $message .= 'Issuer: ' . $this->request->post['exact_issname'] . "\n"; 64 } 65 66 if (isset($this->request->post['exact_issconf'])) { 67 $message .= 'Confirmation Number: ' . $this->request->post['exact_issconf']; 68 } 69 70 if (isset($this->request->post['exact_ctr'])) { 71 $message .= 'Receipt: ' . $this->request->post['exact_ctr']; 72 } 73 74 $this->model_checkout_order->addOrderHistory($details['x_invoice_num'], $this->config->get('payment_authorizenet_sim_order_status_id'), $message, true); 75 76 $this->response->redirect($this->url->link('checkout/success')); 77 } else { 78 $this->response->redirect($this->url->link('checkout/failure')); 79 } 80 } else { 81 $this->response->redirect($this->url->link('checkout/failure')); 82 } 83 } 84 }