PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/controller/payment/pp_payflow_iframe.php

https://gitlab.com/shapcy/opencart
PHP | 153 lines | 119 code | 34 blank | 0 comment | 19 complexity | f5f3dd719ae6e5db362dc2a05e73d6fc MD5 | raw file
  1. <?php
  2. class ControllerPaymentPPPayflowIframe extends Controller {
  3. public function index() {
  4. $this->load->model('checkout/order');
  5. $this->load->model('payment/pp_payflow_iframe');
  6. $this->load->model('localisation/country');
  7. $this->load->model('localisation/zone');
  8. $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
  9. if ($this->config->get('pp_payflow_iframe_test')) {
  10. $mode = 'TEST';
  11. } else {
  12. $mode = 'LIVE';
  13. }
  14. $payflow_url = 'https://payflowlink.paypal.com';
  15. if ($this->config->get('pp_payflow_iframe_transaction_method') == 'sale') {
  16. $transaction_type = 'S';
  17. } else {
  18. $transaction_type = 'A';
  19. }
  20. $secure_token_id = md5($this->session->data['order_id'] . mt_rand() . microtime());
  21. $this->model_payment_pp_payflow_iframe->addOrder($order_info['order_id'], $secure_token_id);
  22. $shipping_country = $this->model_localisation_country->getCountry($order_info['shipping_country_id']);
  23. $shipping_zone = $this->model_localisation_zone->getZone($order_info['shipping_zone_id']);
  24. $payment_country = $this->model_localisation_country->getCountry($order_info['payment_country_id']);
  25. $payment_zone = $this->model_localisation_zone->getZone($order_info['payment_zone_id']);
  26. $url_params = array(
  27. 'TENDER' => 'C',
  28. 'TRXTYPE' => $transaction_type,
  29. 'AMT' => $this->currency->format($order_info['total'], $order_info['currency_code'], false, false),
  30. 'CURRENCY' => $order_info['currency_code'],
  31. 'CREATESECURETOKEN' => 'Y',
  32. 'SECURETOKENID' => $secure_token_id,
  33. 'BILLTOFIRSTNAME' => $order_info['payment_firstname'],
  34. 'BILLTOLASTNAME' => $order_info['payment_lastname'],
  35. 'BILLTOSTREET' => trim($order_info['payment_address_1'] . ' ' . $order_info['payment_address_2']),
  36. 'BILLTOCITY' => $order_info['payment_city'],
  37. 'BILLTOSTATE' => $payment_zone['code'],
  38. 'BILLTOZIP' => $order_info['payment_postcode'],
  39. 'BILLTOCOUNTRY' => $payment_country['iso_code_2'],
  40. );
  41. if ($shipping_country) {
  42. $url_params['SHIPTOFIRSTNAME'] = $order_info['shipping_firstname'];
  43. $url_params['SHIPTOLASTNAME'] = $order_info['shipping_lastname'];
  44. $url_params['SHIPTOSTREET'] = trim($order_info['shipping_address_1'] . ' ' . $order_info['shipping_address_2']);
  45. $url_params['SHIPTOCITY'] = $order_info['shipping_city'];
  46. $url_params['SHIPTOSTATE'] = $shipping_zone['code'];
  47. $url_params['SHIPTOZIP'] = $order_info['shipping_postcode'];
  48. $url_params['SHIPTOCOUNTRY'] = $shipping_country['iso_code_2'];
  49. }
  50. $response_params = $this->model_payment_pp_payflow_iframe->call($url_params);
  51. if (isset($response_params['SECURETOKEN'])) {
  52. $secure_token = $response_params['SECURETOKEN'];
  53. } else {
  54. $secure_token = '';
  55. }
  56. $iframe_params = array(
  57. 'MODE' => $mode,
  58. 'SECURETOKENID' => $secure_token_id,
  59. 'SECURETOKEN' => $secure_token,
  60. );
  61. $data['iframe_url'] = $payflow_url . '?' . http_build_query($iframe_params, '', "&");
  62. $data['checkout_method'] = $this->config->get('pp_payflow_iframe_checkout_method');
  63. $data['button_confirm'] = $this->language->get('button_confirm');
  64. return $this->load->view('payment/pp_payflow_iframe', $data);
  65. }
  66. public function paymentReturn() {
  67. $data['url'] = $this->url->link('checkout/success');
  68. $this->response->setOutput($this->load->view('payment/pp_payflow_iframe_return', $data));
  69. }
  70. public function paymentCancel() {
  71. $data['url'] = $this->url->link('checkout/checkout');
  72. $this->response->setOutput($this->load->view('payment/pp_payflow_iframe_return', $data));
  73. }
  74. public function paymentError() {
  75. $data['url'] = $this->url->link('checkout/checkout');
  76. $this->response->setOutput($this->load->view('payment/pp_payflow_iframe_return', $data));
  77. }
  78. public function paymentIpn() {
  79. $this->load->model('payment/pp_payflow_iframe');
  80. $this->load->model('checkout/order');
  81. if ($this->config->get('pp_pro_iframe_debug')) {
  82. $log = new Log('pp_pro_iframe.log');
  83. $log->write('POST: ' . print_r($this->request->post, 1));
  84. }
  85. $order_id = $this->model_payment_pp_payflow_iframe->getOrderId($this->request->post['SECURETOKENID']);
  86. if ($order_id) {
  87. $order_info = $this->model_checkout_order->getOrder($order_id);
  88. $url_params = array(
  89. 'TENDER' => 'C',
  90. 'TRXTYPE' => 'I',
  91. 'ORIGID' => $this->request->post['PNREF'],
  92. );
  93. $response_params = $this->model_payment_pp_payflow_iframe->call($url_params);
  94. if ($order_info['order_status_id'] == 0 && $response_params['RESULT'] == '0' && $this->request->post['RESULT'] == 0) {
  95. $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('pp_payflow_iframe_order_status_id'));
  96. if ($this->request->post['TYPE'] == 'S') {
  97. $complete = 1;
  98. } else {
  99. $complete = 0;
  100. }
  101. $data = array(
  102. 'secure_token_id' => $this->request->post['SECURETOKENID'],
  103. 'transaction_reference' => $this->request->post['PNREF'],
  104. 'transaction_type' => $this->request->post['TYPE'],
  105. 'complete' => $complete,
  106. );
  107. $this->model_payment_pp_payflow_iframe->updateOrder($data);
  108. $data = array(
  109. 'order_id' => $order_id,
  110. 'type' => $this->request->post['TYPE'],
  111. 'transaction_reference' => $this->request->post['PNREF'],
  112. 'amount' => $this->request->post['AMT'],
  113. );
  114. $this->model_payment_pp_payflow_iframe->addTransaction($data);
  115. }
  116. }
  117. $this->response->setOutput('Ok');
  118. }
  119. }