lehieuit

bank

Jul 22nd, 2013
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. <?php
  2. class ControllerPaymentAuthorizeNetAim extends Controller {
  3. protected function index() {
  4. $this->language->load('payment/authorizenet_aim');
  5.  
  6. $this->data['text_credit_card'] = $this->language->get('text_credit_card');
  7. $this->data['text_wait'] = $this->language->get('text_wait');
  8.  
  9. $this->data['entry_cc_owner'] = $this->language->get('entry_cc_owner');
  10. $this->data['entry_cc_number'] = $this->language->get('entry_cc_number');
  11. $this->data['entry_cc_expire_date'] = $this->language->get('entry_cc_expire_date');
  12. $this->data['entry_cc_cvv2'] = $this->language->get('entry_cc_cvv2');
  13.  
  14. $this->data['button_confirm'] = $this->language->get('button_confirm');
  15. $this->data['button_back'] = $this->language->get('button_back');
  16.  
  17. $this->data['months'] = array();
  18.  
  19. for ($i = 1; $i <= 12; $i++) {
  20. $this->data['months'][] = array(
  21. 'text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)),
  22. 'value' => sprintf('%02d', $i)
  23. );
  24. }
  25.  
  26. $today = getdate();
  27.  
  28. $this->data['year_expire'] = array();
  29.  
  30. for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
  31. $this->data['year_expire'][] = array(
  32. 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
  33. 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
  34. );
  35. }
  36.  
  37. if ($this->request->get['route'] != 'checkout/guest_step_3') {
  38. $this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/payment';
  39. } else {
  40. $this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/guest_step_2';
  41. }
  42.  
  43. $this->id = 'payment';
  44.  
  45. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/authorizenet_aim.tpl')) {
  46. $this->template = $this->config->get('config_template') . '/template/payment/authorizenet_aim.tpl';
  47. } else {
  48. $this->template = 'default/template/payment/authorizenet_aim.tpl';
  49. }
  50.  
  51. $this->render();
  52. }
  53.  
  54. public function send() {
  55. if ($this->config->get('authorizenet_aim_server') == 'live') {
  56. $url = 'https://secure.authorize.net/gateway/transact.dll';
  57. } elseif ($this->config->get('authorizenet_aim_server') == 'test') {
  58. $url = 'https://test.authorize.net/gateway/transact.dll';
  59. }
  60.  
  61. $this->load->model('checkout/order');
  62.  
  63. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  64.  
  65. $data = array();
  66.  
  67. $data['x_login'] = $this->config->get('authorizenet_aim_login');
  68. $data['x_tran_key'] = $this->config->get('authorizenet_aim_key');
  69. $data['x_version'] = '3.1';
  70. $data['x_delim_data'] = 'TRUE';
  71. $data['x_delim_char'] = ',';
  72. $data['x_encap_char'] = '"';
  73. $data['x_relay_response'] = 'FALSE';
  74. $data['x_first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
  75. $data['x_last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
  76. $data['x_company'] = html_entity_decode($order_info['payment_company'], ENT_QUOTES, 'UTF-8');
  77. $data['x_address'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
  78. $data['x_city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
  79. $data['x_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
  80. $data['x_zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
  81. $data['x_country'] = html_entity_decode($order_info['payment_country'], ENT_QUOTES, 'UTF-8');
  82. $data['x_phone'] = $order_info['telephone'];
  83. $data['x_customer_ip'] = $this->request->server['REMOTE_ADDR'];
  84. $data['x_email'] = $order_info['email'];
  85. $data['x_description'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
  86. $data['x_amount'] = $this->currency->format($order_info['total'], $order_info['currency'], 1.00000, FALSE);
  87. $data['x_currency_code'] = $this->currency->getCode();
  88. $data['x_method'] = 'CC';
  89. $data['x_type'] = ($this->config->get('authorizenet_aim_method') == 'capture') ? 'AUTH_CAPTURE' : 'AUTH_ONLY';
  90. $data['x_card_num'] = str_replace(' ', '', $this->request->post['cc_number']);
  91. $data['x_exp_date'] = $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'];
  92. $data['x_card_code'] = $this->request->post['cc_cvv2'];
  93. $data['x_invoice_num'] = $this->session->data['order_id'];
  94.  
  95. if ($this->config->get('authorizenet_aim_mode') == 'test') {
  96. $data['x_test_request'] = 'TRUE';
  97. }
  98.  
  99. $curl = curl_init($url);
  100.  
  101. curl_setopt($curl, CURLOPT_PORT, 443);
  102. curl_setopt($curl, CURLOPT_HEADER, 0);
  103. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  104. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  105. curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
  106. curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
  107. curl_setopt($curl, CURLOPT_POST, 1);
  108. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  109.  
  110. $response = curl_exec($curl);
  111.  
  112. curl_close($curl);
  113.  
  114. $i = 1;
  115.  
  116. $response_data = array();
  117.  
  118. $results = explode(',', $response);
  119.  
  120. foreach ($results as $result) {
  121. $response_data[$i] = trim($result, '"');
  122.  
  123. $i++;
  124. }
  125.  
  126. $json = array();
  127.  
  128. if ($response_data[1] == '1') {
  129.  
  130. if ($this->config->get('authorizenet_aim_hash')) {
  131. $checksum = strtoupper(md5($this->config->get('authorizenet_aim_hash') . $this->config->get('authorizenet_aim_login') . $response_data[6] . $this->currency->format($order_info['total'], $order_info['currency'], 1.00000, FALSE)));
  132. } else {
  133. $checksum = strtoupper(md5($this->config->get('authorizenet_aim_login') . $response_data[6] . $this->currency->format($order_info['total'], $order_info['currency'], 1.00000, FALSE)));
  134. }
  135.  
  136. if (strtoupper($response_data[38]) != $checksum) {
  137. $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
  138.  
  139. $message = '';
  140.  
  141. if (isset($response_data['5'])) {
  142. $message .= 'Authorization Code: ' . $response_data['5'] . "\n";
  143. }
  144.  
  145. if (isset($response_data['6'])) {
  146. $message .= 'AVS Response: ' . $response_data['6'] . "\n";
  147. }
  148.  
  149. if (isset($response_data['7'])) {
  150. $message .= 'Transaction ID: ' . $response_data['7'] . "\n";
  151. }
  152.  
  153. if (isset($response_data['39'])) {
  154. $message .= 'Card Code Response: ' . $response_data['39'] . "\n";
  155. }
  156.  
  157. if (isset($response_data['40'])) {
  158. $message .= 'Cardholder Authentication Verification Response: ' . $response_data['40'] . "\n";
  159. }
  160.  
  161. $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('authorizenet_aim_order_status_id'), $message, FALSE);
  162. }
  163.  
  164. $json['success'] = HTTPS_SERVER . 'index.php?route=checkout/success';
  165. } else {
  166. $json['error'] = $response_data[4];
  167. }
  168.  
  169. $this->load->library('json');
  170.  
  171. $this->response->setOutput(Json::encode($json));
  172. }
  173. }
  174. ?>
Add Comment
Please, Sign In to add comment