pp_standard.php (7913B)
1 <?php 2 class ControllerExtensionPaymentPPStandard extends Controller { 3 public function index() { 4 $this->load->language('extension/payment/pp_standard'); 5 6 $data['text_testmode'] = $this->language->get('text_testmode'); 7 $data['button_confirm'] = $this->language->get('button_confirm'); 8 9 $data['testmode'] = $this->config->get('payment_pp_standard_test'); 10 11 if (!$this->config->get('payment_pp_standard_test')) { 12 $data['action'] = 'https://www.paypal.com/cgi-bin/webscr&pal=V4T754QB63XXL'; 13 } else { 14 $data['action'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr&pal=V4T754QB63XXL'; 15 } 16 17 $this->load->model('checkout/order'); 18 19 $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); 20 21 if ($order_info) { 22 $data['business'] = $this->config->get('payment_pp_standard_email'); 23 $data['item_name'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'); 24 25 $data['products'] = array(); 26 27 foreach ($this->cart->getProducts() as $product) { 28 $option_data = array(); 29 30 foreach ($product['option'] as $option) { 31 if ($option['type'] != 'file') { 32 $value = $option['value']; 33 } else { 34 $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); 35 36 if ($upload_info) { 37 $value = $upload_info['name']; 38 } else { 39 $value = ''; 40 } 41 } 42 43 $option_data[] = array( 44 'name' => $option['name'], 45 'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) 46 ); 47 } 48 49 $data['products'][] = array( 50 'name' => htmlspecialchars($product['name']), 51 'model' => htmlspecialchars($product['model']), 52 'price' => $this->currency->format($product['price'], $order_info['currency_code'], false, false), 53 'quantity' => $product['quantity'], 54 'option' => $option_data, 55 'weight' => $product['weight'] 56 ); 57 } 58 59 $data['discount_amount_cart'] = 0; 60 61 $total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false); 62 63 if ($total > 0) { 64 $data['products'][] = array( 65 'name' => $this->language->get('text_total'), 66 'model' => '', 67 'price' => $total, 68 'quantity' => 1, 69 'option' => array(), 70 'weight' => 0 71 ); 72 } else { 73 $data['discount_amount_cart'] -= $total; 74 } 75 76 $data['currency_code'] = $order_info['currency_code']; 77 $data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8'); 78 $data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8'); 79 $data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8'); 80 $data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8'); 81 $data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8'); 82 $data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8'); 83 $data['country'] = $order_info['payment_iso_code_2']; 84 $data['email'] = $order_info['email']; 85 $data['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8'); 86 $data['lc'] = $this->session->data['language']; 87 $data['return'] = $this->url->link('checkout/success'); 88 $data['notify_url'] = $this->url->link('extension/payment/pp_standard/callback', '', true); 89 $data['cancel_return'] = $this->url->link('checkout/checkout', '', true); 90 91 if (!$this->config->get('payment_pp_standard_transaction')) { 92 $data['paymentaction'] = 'authorization'; 93 } else { 94 $data['paymentaction'] = 'sale'; 95 } 96 97 $data['custom'] = $this->session->data['order_id']; 98 99 return $this->load->view('extension/payment/pp_standard', $data); 100 } 101 } 102 103 public function callback() { 104 if (isset($this->request->post['custom'])) { 105 $order_id = $this->request->post['custom']; 106 } else { 107 $order_id = 0; 108 } 109 110 $this->load->model('checkout/order'); 111 112 $order_info = $this->model_checkout_order->getOrder($order_id); 113 114 if ($order_info) { 115 $request = 'cmd=_notify-validate'; 116 117 foreach ($this->request->post as $key => $value) { 118 $request .= '&' . $key . '=' . urlencode(html_entity_decode($value, ENT_QUOTES, 'UTF-8')); 119 } 120 121 if (!$this->config->get('payment_pp_standard_test')) { 122 $curl = curl_init('https://www.paypal.com/cgi-bin/webscr'); 123 } else { 124 $curl = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); 125 } 126 127 curl_setopt($curl, CURLOPT_POST, true); 128 curl_setopt($curl, CURLOPT_POSTFIELDS, $request); 129 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 130 curl_setopt($curl, CURLOPT_HEADER, false); 131 curl_setopt($curl, CURLOPT_TIMEOUT, 30); 132 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 133 134 $response = curl_exec($curl); 135 136 if (!$response) { 137 $this->log->write('PP_STANDARD :: CURL failed ' . curl_error($curl) . '(' . curl_errno($curl) . ')'); 138 } 139 140 if ($this->config->get('payment_pp_standard_debug')) { 141 $this->log->write('PP_STANDARD :: IPN REQUEST: ' . $request); 142 $this->log->write('PP_STANDARD :: IPN RESPONSE: ' . $response); 143 } 144 145 if ((strcmp($response, 'VERIFIED') == 0 || strcmp($response, 'UNVERIFIED') == 0) && isset($this->request->post['payment_status'])) { 146 $order_status_id = $this->config->get('config_order_status_id'); 147 148 switch($this->request->post['payment_status']) { 149 case 'Canceled_Reversal': 150 $order_status_id = $this->config->get('payment_pp_standard_canceled_reversal_status_id'); 151 break; 152 case 'Completed': 153 $receiver_match = (strtolower($this->request->post['receiver_email']) == strtolower($this->config->get('payment_pp_standard_email'))); 154 155 $total_paid_match = ((float)$this->request->post['mc_gross'] == $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false)); 156 157 if ($receiver_match && $total_paid_match) { 158 $order_status_id = $this->config->get('payment_pp_standard_completed_status_id'); 159 } 160 161 if (!$receiver_match) { 162 $this->log->write('PP_STANDARD :: RECEIVER EMAIL MISMATCH! ' . strtolower($this->request->post['receiver_email'])); 163 } 164 165 if (!$total_paid_match) { 166 $this->log->write('PP_STANDARD :: TOTAL PAID MISMATCH! ' . $this->request->post['mc_gross']); 167 } 168 break; 169 case 'Denied': 170 $order_status_id = $this->config->get('payment_pp_standard_denied_status_id'); 171 break; 172 case 'Expired': 173 $order_status_id = $this->config->get('payment_pp_standard_expired_status_id'); 174 break; 175 case 'Failed': 176 $order_status_id = $this->config->get('payment_pp_standard_failed_status_id'); 177 break; 178 case 'Pending': 179 $order_status_id = $this->config->get('payment_pp_standard_pending_status_id'); 180 break; 181 case 'Processed': 182 $order_status_id = $this->config->get('payment_pp_standard_processed_status_id'); 183 break; 184 case 'Refunded': 185 $order_status_id = $this->config->get('payment_pp_standard_refunded_status_id'); 186 break; 187 case 'Reversed': 188 $order_status_id = $this->config->get('payment_pp_standard_reversed_status_id'); 189 break; 190 case 'Voided': 191 $order_status_id = $this->config->get('payment_pp_standard_voided_status_id'); 192 break; 193 } 194 195 $this->model_checkout_order->addOrderHistory($order_id, $order_status_id); 196 } else { 197 $this->model_checkout_order->addOrderHistory($order_id, $this->config->get('config_order_status_id')); 198 } 199 200 curl_close($curl); 201 } 202 } 203 }