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