PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://coderstalk.googlecode.com/
PHP | 199 lines | 156 code | 43 blank | 0 comment | 22 complexity | 7cf34ffc2ae9a911ba3dd327b4a22bc1 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-3.0
  1. <?php
  2. class ControllerPaymentPPPro extends Controller {
  3. protected function index() {
  4. $this->language->load('payment/pp_pro');
  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->data['cards'] = array();
  19. $this->data['cards'][] = array(
  20. 'text' => 'Visa',
  21. 'value' => 'VISA'
  22. );
  23. $this->data['cards'][] = array(
  24. 'text' => 'MasterCard',
  25. 'value' => 'MASTERCARD'
  26. );
  27. $this->data['cards'][] = array(
  28. 'text' => 'Discover Card',
  29. 'value' => 'DISCOVER'
  30. );
  31. $this->data['cards'][] = array(
  32. 'text' => 'American Express',
  33. 'value' => 'AMEX'
  34. );
  35. $this->data['cards'][] = array(
  36. 'text' => 'Maestro',
  37. 'value' => 'SWITCH'
  38. );
  39. $this->data['cards'][] = array(
  40. 'text' => 'Solo',
  41. 'value' => 'SOLO'
  42. );
  43. $this->data['months'] = array();
  44. for ($i = 1; $i <= 12; $i++) {
  45. $this->data['months'][] = array(
  46. 'text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)),
  47. 'value' => sprintf('%02d', $i)
  48. );
  49. }
  50. $today = getdate();
  51. $this->data['year_valid'] = array();
  52. for ($i = $today['year'] - 10; $i < $today['year'] + 1; $i++) {
  53. $this->data['year_valid'][] = array(
  54. 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
  55. 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
  56. );
  57. }
  58. $this->data['year_expire'] = array();
  59. for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
  60. $this->data['year_expire'][] = array(
  61. 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
  62. 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
  63. );
  64. }
  65. if ($this->request->get['route'] != 'checkout/guest/confirm') {
  66. $this->data['back'] = $this->url->https('checkout/payment');
  67. } else {
  68. $this->data['back'] = $this->url->https('checkout/guest');
  69. }
  70. $this->id = 'payment';
  71. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pp_pro.tpl')) {
  72. $this->template = $this->config->get('config_template') . '/template/payment/pp_pro.tpl';
  73. } else {
  74. $this->template = 'default/template/payment/pp_pro.tpl';
  75. }
  76. $this->render();
  77. }
  78. public function send() {
  79. if (!$this->config->get('pp_pro_test')) {
  80. $api_endpoint = 'https://api-3t.paypal.com/nvp';
  81. } else {
  82. $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
  83. }
  84. if (!$this->config->get('pp_pro_transaction')) {
  85. $payment_type = 'Authorization';
  86. } else {
  87. $payment_type = 'Sale';
  88. }
  89. $this->load->model('checkout/order');
  90. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  91. $payment_data = array(
  92. 'METHOD' => 'DoDirectPayment',
  93. 'VERSION' => '51.0',
  94. 'USER' => html_entity_decode($this->config->get('pp_pro_username'), ENT_QUOTES, 'UTF-8'),
  95. 'PWD' => html_entity_decode($this->config->get('pp_pro_password'), ENT_QUOTES, 'UTF-8'),
  96. 'SIGNATURE' => html_entity_decode($this->config->get('pp_pro_signature'), ENT_QUOTES, 'UTF-8'),
  97. 'CUSTREF' => $order_info['order_id'],
  98. 'PAYMENTACTION' => $payment_type,
  99. 'AMT' => $this->currency->format($order_info['total'], $order_info['currency'], 1.00000, FALSE),
  100. 'CREDITCARDTYPE' => $this->request->post['cc_type'],
  101. 'ACCT' => str_replace(' ', '', $this->request->post['cc_number']),
  102. 'CARDSTART' => $this->request->post['cc_start_date_month'] . $this->request->post['cc_start_date_year'],
  103. 'EXPDATE' => $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'],
  104. 'CVV2' => $this->request->post['cc_cvv2'],
  105. 'CARDISSUE' => $this->request->post['cc_issue'],
  106. 'FIRSTNAME' => $order_info['payment_firstname'],
  107. 'LASTNAME' => $order_info['payment_lastname'],
  108. 'EMAIL' => $order_info['email'],
  109. 'PHONENUM' => $order_info['telephone'],
  110. 'IPADDRESS' => $this->request->server['REMOTE_ADDR'],
  111. 'STREET' => $order_info['payment_address_1'],
  112. 'CITY' => $order_info['payment_city'],
  113. 'STATE' => ($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code'],
  114. 'ZIP' => $order_info['payment_postcode'],
  115. 'COUNTRYCODE' => $order_info['payment_iso_code_2'],
  116. 'CURRENCYCODE' => $order_info['currency']
  117. );
  118. $curl = curl_init($api_endpoint);
  119. curl_setopt($curl, CURLOPT_PORT, 443);
  120. curl_setopt($curl, CURLOPT_HEADER, 0);
  121. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  122. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  123. curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
  124. curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
  125. curl_setopt($curl, CURLOPT_POST, 1);
  126. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
  127. $response = curl_exec($curl);
  128. curl_close($curl);
  129. if (!$response) {
  130. exit('DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')');
  131. }
  132. $response_data = array();
  133. parse_str($response, $response_data);
  134. $json = array();
  135. if (($response_data['ACK'] == 'Success') || ($response_data['ACK'] == 'SuccessWithWarning')) {
  136. $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
  137. $message = '';
  138. if (isset($response_data['AVSCODE'])) {
  139. $message .= 'AVSCODE: ' . $response_data['AVSCODE'] . "\n";
  140. }
  141. if (isset($response_data['CVV2MATCH'])) {
  142. $message .= 'CVV2MATCH: ' . $response_data['CVV2MATCH'] . "\n";
  143. }
  144. if (isset($response_data['TRANSACTIONID'])) {
  145. $message .= 'TRANSACTIONID: ' . $response_data['TRANSACTIONID'] . "\n";
  146. }
  147. $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('pp_pro_order_status_id'), $message, FALSE);
  148. $json['success'] = $this->url->https('checkout/success');
  149. } else {
  150. $json['error'] = $response_data['L_LONGMESSAGE0'];
  151. }
  152. $this->load->library('json');
  153. $this->response->setOutput(Json::encode($json));
  154. }
  155. }
  156. ?>