PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/opencart/trunk/upload/catalog/controller/payment/pp_direct_uk.php

http://coderstalk.googlecode.com/
PHP | 202 lines | 158 code | 44 blank | 0 comment | 15 complexity | 30ec2ccb4372dc0a5867ce985ee92bd8 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-3.0
  1. <?php
  2. class ControllerPaymentPPDirectUK extends Controller {
  3. protected function index() {
  4. $this->language->load('payment/pp_direct_uk');
  5. $this->data['text_credit_card'] = $this->language->get('text_credit_card');
  6. $this->data['text_start_date'] = $this->language->get('text_start_date');
  7. $this->data['text_issue'] = $this->language->get('text_issue');
  8. $this->data['text_wait'] = $this->language->get('text_wait');
  9. $this->data['entry_cc_owner'] = $this->language->get('entry_cc_owner');
  10. $this->data['entry_cc_type'] = $this->language->get('entry_cc_type');
  11. $this->data['entry_cc_number'] = $this->language->get('entry_cc_number');
  12. $this->data['entry_cc_start_date'] = $this->language->get('entry_cc_start_date');
  13. $this->data['entry_cc_expire_date'] = $this->language->get('entry_cc_expire_date');
  14. $this->data['entry_cc_cvv2'] = $this->language->get('entry_cc_cvv2');
  15. $this->data['entry_cc_issue'] = $this->language->get('entry_cc_issue');
  16. $this->data['button_confirm'] = $this->language->get('button_confirm');
  17. $this->data['button_back'] = $this->language->get('button_back');
  18. $this->load->model('checkout/order');
  19. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  20. $this->data['owner'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'];
  21. $this->data['cards'] = array();
  22. $this->data['cards'][] = array(
  23. 'text' => 'Visa',
  24. 'value' => '0'
  25. );
  26. $this->data['cards'][] = array(
  27. 'text' => 'MasterCard',
  28. 'value' => '1'
  29. );
  30. $this->data['cards'][] = array(
  31. 'text' => 'Maestro',
  32. 'value' => '9'
  33. );
  34. $this->data['cards'][] = array(
  35. 'text' => 'Solo',
  36. 'value' => 'S'
  37. );
  38. $this->data['months'] = array();
  39. for ($i = 1; $i <= 12; $i++) {
  40. $this->data['months'][] = array(
  41. 'text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)),
  42. 'value' => sprintf('%02d', $i)
  43. );
  44. }
  45. $today = getdate();
  46. $this->data['year_valid'] = array();
  47. for ($i = $today['year'] - 10; $i < $today['year'] + 1; $i++) {
  48. $this->data['year_valid'][] = array(
  49. 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
  50. 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
  51. );
  52. }
  53. $this->data['year_expire'] = array();
  54. for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
  55. $this->data['year_expire'][] = array(
  56. 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
  57. 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
  58. );
  59. }
  60. $this->data['back'] = $this->url->https('checkout/payment');
  61. $this->id = 'payment';
  62. $this->template = $this->config->get('config_template') . 'payment/pp_direct_uk.tpl';
  63. $this->render();
  64. }
  65. public function send() {
  66. $this->language->load('payment/pp_direct_uk');
  67. if (!$this->config->get('pp_direct_uk_test')) {
  68. $api_url = 'https://payflowpro.verisign.com/transaction';
  69. } else {
  70. $api_url = 'https://pilot-payflowpro.verisign.com/transaction';
  71. }
  72. if (!$this->config->get('pp_direct_uk_transaction')) {
  73. $payment_type = 'A';
  74. } else {
  75. $payment_type = 'S';
  76. }
  77. $this->load->model('checkout/order');
  78. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  79. $payment_address = $this->customer->getAddress($this->session->data['payment_address_id']);
  80. $payment_data = array(
  81. 'USER' => $this->config->get('pp_direct_uk_user'),
  82. 'VENDOR' => $this->config->get('pp_direct_uk_vendor'),
  83. 'PARTNER' => $this->config->get('pp_direct_uk_partner'),
  84. 'PWD' => $this->config->get('pp_direct_uk_password'),
  85. 'TENDER' => 'C',
  86. 'TRXTYPE' => $payment_type,
  87. 'AMT' => $this->currency->format($order_info['total'], $order_info['currency'], 1.00000, FALSE),
  88. 'CURRENCY' => $order_info['currency'],
  89. 'NAME' => $this->request->post['cc_owner'],
  90. 'STREET' => $order_info['payment_address_1'],
  91. 'CITY' => $order_info['payment_city'],
  92. 'STATE' => ($payment_address['iso_code_2'] != 'US') ? $order_info['payment_zone'] : $payment_address['code'],
  93. 'COUNTRY' => $payment_address['iso_code_2'],
  94. 'ZIP' => $order_info['payment_postcode'],
  95. 'CLIENTIP' => $this->request->server['REMOTE_ADDR'],
  96. 'EMAIL' => $order_info['email'],
  97. 'ACCT' => str_replace(' ', '', $this->request->post['cc_number']),
  98. 'ACCTTYPE' => $this->request->post['cc_type'],
  99. 'CARDSTART' => $this->request->post['cc_start_date_month'] . $this->request->post['cc_start_date_year'],
  100. 'EXPDATE' => $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'],
  101. 'CVV2' => $this->request->post['cc_cvv2'],
  102. 'CARDISSUE' => $this->request->post['cc_issue']
  103. );
  104. $curl = curl_init($api_url);
  105. curl_setopt($curl, CURLOPT_PORT, 443);
  106. curl_setopt($curl, CURLOPT_HEADER, 0);
  107. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  108. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  109. curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
  110. curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
  111. curl_setopt($curl, CURLOPT_POST, 1);
  112. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
  113. curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-VPS-REQUEST-ID: ' . md5($this->session->data['order_id'] . rand())));
  114. $response = curl_exec($curl);
  115. curl_close($curl);
  116. $response_data = array();
  117. parse_str($response, $response_data);
  118. $json = array();
  119. if ($response_data['RESULT'] == '0') {
  120. $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
  121. $message = '';
  122. if (isset($response_data['AVSCODE'])) {
  123. $message .= 'AVSCODE: ' . $response_data['AVSCODE'] . "\n";
  124. }
  125. if (isset($response_data['CVV2MATCH'])) {
  126. $message .= 'CVV2MATCH: ' . $response_data['CVV2MATCH'] . "\n";
  127. }
  128. if (isset($response_data['TRANSACTIONID'])) {
  129. $message .= 'TRANSACTIONID: ' . $response_data['TRANSACTIONID'] . "\n";
  130. }
  131. $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('pp_direct_uk_order_status_id'), $message, FALSE);
  132. $json['success'] = TRUE;
  133. } else {
  134. switch ($response_data['RESULT']) {
  135. case '1':
  136. case '26':
  137. $json['error'] = $this->language->get('error_config');
  138. break;
  139. case '7':
  140. $json['error'] = $this->language->get('error_address');
  141. break;
  142. case '12':
  143. $json['error'] = $this->language->get('error_declined');
  144. break;
  145. case '23':
  146. case '24':
  147. $json['error'] = $this->language->get('error_invalid');
  148. break;
  149. default:
  150. $json['error'] = $this->language->get('error_general');
  151. break;
  152. }
  153. }
  154. $this->load->library('json');
  155. $this->response->setOutput(Json::encode($json));
  156. }
  157. }
  158. ?>