PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/catalog/controller/payment/pp_pro.php

https://gitlab.com/reclamare/mao
PHP | 203 lines | 162 code | 41 blank | 0 comment | 27 complexity | b660456c7e944e7e72926cd64b9a76e8 MD5 | raw file
  1. <?php
  2. class ControllerPaymentPPPro extends Controller {
  3. public function index() {
  4. $this->language->load('payment/pp_pro');
  5. $data['text_credit_card'] = $this->language->get('text_credit_card');
  6. $data['text_start_date'] = $this->language->get('text_start_date');
  7. $data['text_wait'] = $this->language->get('text_wait');
  8. $data['text_loading'] = $this->language->get('text_loading');
  9. $data['entry_cc_type'] = $this->language->get('entry_cc_type');
  10. $data['entry_cc_number'] = $this->language->get('entry_cc_number');
  11. $data['entry_cc_start_date'] = $this->language->get('entry_cc_start_date');
  12. $data['entry_cc_expire_date'] = $this->language->get('entry_cc_expire_date');
  13. $data['entry_cc_cvv2'] = $this->language->get('entry_cc_cvv2');
  14. $data['entry_cc_issue'] = $this->language->get('entry_cc_issue');
  15. $data['help_start_date'] = $this->language->get('help_start_date');
  16. $data['help_issue'] = $this->language->get('help_issue');
  17. $data['button_confirm'] = $this->language->get('button_confirm');
  18. $data['cards'] = array();
  19. $data['cards'][] = array(
  20. 'text' => 'Visa',
  21. 'value' => 'VISA'
  22. );
  23. $data['cards'][] = array(
  24. 'text' => 'MasterCard',
  25. 'value' => 'MASTERCARD'
  26. );
  27. $data['cards'][] = array(
  28. 'text' => 'Discover Card',
  29. 'value' => 'DISCOVER'
  30. );
  31. $data['cards'][] = array(
  32. 'text' => 'American Express',
  33. 'value' => 'AMEX'
  34. );
  35. $data['cards'][] = array(
  36. 'text' => 'Maestro',
  37. 'value' => 'SWITCH'
  38. );
  39. $data['cards'][] = array(
  40. 'text' => 'Solo',
  41. 'value' => 'SOLO'
  42. );
  43. $data['months'] = array();
  44. for ($i = 1; $i <= 12; $i++) {
  45. $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. $data['year_valid'] = array();
  52. for ($i = $today['year'] - 10; $i < $today['year'] + 1; $i++) {
  53. $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. $data['year_expire'] = array();
  59. for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
  60. $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 (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/pp_pro.tpl')) {
  66. return $this->load->view($this->config->get('config_template') . '/template/payment/pp_pro.tpl', $data);
  67. } else {
  68. return $this->load->view('default/template/payment/pp_pro.tpl', $data);
  69. }
  70. }
  71. public function send() {
  72. if (!$this->config->get('pp_pro_transaction')) {
  73. $payment_type = 'Authorization';
  74. } else {
  75. $payment_type = 'Sale';
  76. }
  77. $this->load->model('checkout/order');
  78. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  79. $request = 'METHOD=DoDirectPayment';
  80. $request .= '&VERSION=51.0';
  81. $request .= '&USER=' . urlencode($this->config->get('pp_pro_username'));
  82. $request .= '&PWD=' . urlencode($this->config->get('pp_pro_password'));
  83. $request .= '&SIGNATURE=' . urlencode($this->config->get('pp_pro_signature'));
  84. $request .= '&CUSTREF=' . (int)$order_info['order_id'];
  85. $request .= '&PAYMENTACTION=' . $payment_type;
  86. $request .= '&AMT=' . $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);
  87. $request .= '&CREDITCARDTYPE=' . $this->request->post['cc_type'];
  88. $request .= '&ACCT=' . urlencode(str_replace(' ', '', $this->request->post['cc_number']));
  89. $request .= '&CARDSTART=' . urlencode($this->request->post['cc_start_date_month'] . $this->request->post['cc_start_date_year']);
  90. $request .= '&EXPDATE=' . urlencode($this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year']);
  91. $request .= '&CVV2=' . urlencode($this->request->post['cc_cvv2']);
  92. if ($this->request->post['cc_type'] == 'SWITCH' || $this->request->post['cc_type'] == 'SOLO') {
  93. $request .= '&ISSUENUMBER=' . urlencode($this->request->post['cc_issue']);
  94. }
  95. $request .= '&FIRSTNAME=' . urlencode($order_info['payment_firstname']);
  96. $request .= '&LASTNAME=' . urlencode($order_info['payment_lastname']);
  97. $request .= '&EMAIL=' . urlencode($order_info['email']);
  98. $request .= '&PHONENUM=' . urlencode($order_info['telephone']);
  99. $request .= '&IPADDRESS=' . urlencode($this->request->server['REMOTE_ADDR']);
  100. $request .= '&STREET=' . urlencode($order_info['payment_address_1']);
  101. $request .= '&CITY=' . urlencode($order_info['payment_city']);
  102. $request .= '&STATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']);
  103. $request .= '&ZIP=' . urlencode($order_info['payment_postcode']);
  104. $request .= '&COUNTRYCODE=' . urlencode($order_info['payment_iso_code_2']);
  105. $request .= '&CURRENCYCODE=' . urlencode($order_info['currency_code']);
  106. $request .= '&BUTTONSOURCE=' . urlencode('OpenCart_2.0_WPP');
  107. if ($this->cart->hasShipping()) {
  108. $request .= '&SHIPTONAME=' . urlencode($order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname']);
  109. $request .= '&SHIPTOSTREET=' . urlencode($order_info['shipping_address_1']);
  110. $request .= '&SHIPTOCITY=' . urlencode($order_info['shipping_city']);
  111. $request .= '&SHIPTOSTATE=' . urlencode(($order_info['shipping_iso_code_2'] != 'US') ? $order_info['shipping_zone'] : $order_info['shipping_zone_code']);
  112. $request .= '&SHIPTOCOUNTRYCODE=' . urlencode($order_info['shipping_iso_code_2']);
  113. $request .= '&SHIPTOZIP=' . urlencode($order_info['shipping_postcode']);
  114. } else {
  115. $request .= '&SHIPTONAME=' . urlencode($order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']);
  116. $request .= '&SHIPTOSTREET=' . urlencode($order_info['payment_address_1']);
  117. $request .= '&SHIPTOCITY=' . urlencode($order_info['payment_city']);
  118. $request .= '&SHIPTOSTATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']);
  119. $request .= '&SHIPTOCOUNTRYCODE=' . urlencode($order_info['payment_iso_code_2']);
  120. $request .= '&SHIPTOZIP=' . urlencode($order_info['payment_postcode']);
  121. }
  122. if (!$this->config->get('pp_pro_test')) {
  123. $curl = curl_init('https://api-3t.paypal.com/nvp');
  124. } else {
  125. $curl = curl_init('https://api-3t.sandbox.paypal.com/nvp');
  126. }
  127. curl_setopt($curl, CURLOPT_PORT, 443);
  128. curl_setopt($curl, CURLOPT_HEADER, 0);
  129. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  130. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  131. curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
  132. curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
  133. curl_setopt($curl, CURLOPT_POST, 1);
  134. curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
  135. $response = curl_exec($curl);
  136. curl_close($curl);
  137. if (!$response) {
  138. $this->log->write('DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')');
  139. }
  140. $response_info = array();
  141. parse_str($response, $response_info);
  142. $json = array();
  143. if (($response_info['ACK'] == 'Success') || ($response_info['ACK'] == 'SuccessWithWarning')) {
  144. $message = '';
  145. if (isset($response_info['AVSCODE'])) {
  146. $message .= 'AVSCODE: ' . $response_info['AVSCODE'] . "\n";
  147. }
  148. if (isset($response_info['CVV2MATCH'])) {
  149. $message .= 'CVV2MATCH: ' . $response_info['CVV2MATCH'] . "\n";
  150. }
  151. if (isset($response_info['TRANSACTIONID'])) {
  152. $message .= 'TRANSACTIONID: ' . $response_info['TRANSACTIONID'] . "\n";
  153. }
  154. $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('pp_pro_order_status_id'), $message, false);
  155. $json['success'] = $this->url->link('checkout/success');
  156. } else {
  157. $json['error'] = $response_info['L_LONGMESSAGE0'];
  158. }
  159. $this->response->addHeader('Content-Type: application/json');
  160. $this->response->setOutput(json_encode($json));
  161. }
  162. }