pp_pro.php (7038B)
1 <?php 2 class ControllerExtensionPaymentPPPro extends Controller { 3 public function index() { 4 $this->load->language('extension/payment/pp_pro'); 5 6 $data['cards'] = array(); 7 8 $data['cards'][] = array( 9 'text' => 'Visa', 10 'value' => 'VISA' 11 ); 12 13 $data['cards'][] = array( 14 'text' => 'MasterCard', 15 'value' => 'MASTERCARD' 16 ); 17 18 $data['cards'][] = array( 19 'text' => 'Discover Card', 20 'value' => 'DISCOVER' 21 ); 22 23 $data['cards'][] = array( 24 'text' => 'American Express', 25 'value' => 'AMEX' 26 ); 27 28 $data['cards'][] = array( 29 'text' => 'Maestro', 30 'value' => 'SWITCH' 31 ); 32 33 $data['cards'][] = array( 34 'text' => 'Solo', 35 'value' => 'SOLO' 36 ); 37 38 $data['months'] = array(); 39 40 for ($i = 1; $i <= 12; $i++) { 41 $data['months'][] = array( 42 'text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)), 43 'value' => sprintf('%02d', $i) 44 ); 45 } 46 47 $today = getdate(); 48 49 $data['year_valid'] = array(); 50 51 for ($i = $today['year'] - 10; $i < $today['year'] + 1; $i++) { 52 $data['year_valid'][] = array( 53 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)), 54 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)) 55 ); 56 } 57 58 $data['year_expire'] = array(); 59 60 for ($i = $today['year']; $i < $today['year'] + 11; $i++) { 61 $data['year_expire'][] = array( 62 'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)), 63 'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)) 64 ); 65 } 66 67 return $this->load->view('extension/payment/pp_pro', $data); 68 } 69 70 public function send() { 71 if (!$this->config->get('payment_pp_pro_transaction')) { 72 $payment_type = 'Authorization'; 73 } else { 74 $payment_type = 'Sale'; 75 } 76 77 $this->load->model('checkout/order'); 78 79 $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); 80 81 $request = 'METHOD=DoDirectPayment'; 82 $request .= '&VERSION=51.0'; 83 $request .= '&USER=' . urlencode($this->config->get('payment_pp_pro_username')); 84 $request .= '&PWD=' . urlencode($this->config->get('payment_pp_pro_password')); 85 $request .= '&SIGNATURE=' . urlencode($this->config->get('payment_pp_pro_signature')); 86 $request .= '&CUSTREF=' . (int)$order_info['order_id']; 87 $request .= '&PAYMENTACTION=' . $payment_type; 88 $request .= '&AMT=' . $this->currency->format($order_info['total'], $order_info['currency_code'], false, false); 89 $request .= '&CREDITCARDTYPE=' . $this->request->post['cc_type']; 90 $request .= '&ACCT=' . urlencode(str_replace(' ', '', $this->request->post['cc_number'])); 91 $request .= '&CARDSTART=' . urlencode($this->request->post['cc_start_date_month'] . $this->request->post['cc_start_date_year']); 92 $request .= '&EXPDATE=' . urlencode($this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year']); 93 $request .= '&CVV2=' . urlencode($this->request->post['cc_cvv2']); 94 95 if ($this->request->post['cc_type'] == 'SWITCH' || $this->request->post['cc_type'] == 'SOLO') { 96 $request .= '&ISSUENUMBER=' . urlencode($this->request->post['cc_issue']); 97 } 98 99 $request .= '&FIRSTNAME=' . urlencode($order_info['payment_firstname']); 100 $request .= '&LASTNAME=' . urlencode($order_info['payment_lastname']); 101 $request .= '&EMAIL=' . urlencode($order_info['email']); 102 $request .= '&PHONENUM=' . urlencode($order_info['telephone']); 103 $request .= '&IPADDRESS=' . urlencode($this->request->server['REMOTE_ADDR']); 104 $request .= '&STREET=' . urlencode($order_info['payment_address_1']); 105 $request .= '&CITY=' . urlencode($order_info['payment_city']); 106 $request .= '&STATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']); 107 $request .= '&ZIP=' . urlencode($order_info['payment_postcode']); 108 $request .= '&COUNTRYCODE=' . urlencode($order_info['payment_iso_code_2']); 109 $request .= '&CURRENCYCODE=' . urlencode($order_info['currency_code']); 110 $request .= '&BUTTONSOURCE=' . urlencode('OpenCart_2.0_WPP'); 111 112 if ($this->cart->hasShipping()) { 113 $request .= '&SHIPTONAME=' . urlencode($order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname']); 114 $request .= '&SHIPTOSTREET=' . urlencode($order_info['shipping_address_1']); 115 $request .= '&SHIPTOCITY=' . urlencode($order_info['shipping_city']); 116 $request .= '&SHIPTOSTATE=' . urlencode(($order_info['shipping_iso_code_2'] != 'US') ? $order_info['shipping_zone'] : $order_info['shipping_zone_code']); 117 $request .= '&SHIPTOCOUNTRYCODE=' . urlencode($order_info['shipping_iso_code_2']); 118 $request .= '&SHIPTOZIP=' . urlencode($order_info['shipping_postcode']); 119 } else { 120 $request .= '&SHIPTONAME=' . urlencode($order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']); 121 $request .= '&SHIPTOSTREET=' . urlencode($order_info['payment_address_1']); 122 $request .= '&SHIPTOCITY=' . urlencode($order_info['payment_city']); 123 $request .= '&SHIPTOSTATE=' . urlencode(($order_info['payment_iso_code_2'] != 'US') ? $order_info['payment_zone'] : $order_info['payment_zone_code']); 124 $request .= '&SHIPTOCOUNTRYCODE=' . urlencode($order_info['payment_iso_code_2']); 125 $request .= '&SHIPTOZIP=' . urlencode($order_info['payment_postcode']); 126 } 127 128 if (!$this->config->get('payment_pp_pro_test')) { 129 $curl = curl_init('https://api-3t.paypal.com/nvp'); 130 } else { 131 $curl = curl_init('https://api-3t.sandbox.paypal.com/nvp'); 132 } 133 134 curl_setopt($curl, CURLOPT_PORT, 443); 135 curl_setopt($curl, CURLOPT_HEADER, 0); 136 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 137 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 138 curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); 139 curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); 140 curl_setopt($curl, CURLOPT_POST, 1); 141 curl_setopt($curl, CURLOPT_POSTFIELDS, $request); 142 143 $response = curl_exec($curl); 144 145 curl_close($curl); 146 147 if (!$response) { 148 $this->log->write('DoDirectPayment failed: ' . curl_error($curl) . '(' . curl_errno($curl) . ')'); 149 } 150 151 $response_info = array(); 152 153 parse_str($response, $response_info); 154 155 $json = array(); 156 157 if (($response_info['ACK'] == 'Success') || ($response_info['ACK'] == 'SuccessWithWarning')) { 158 $message = ''; 159 160 if (isset($response_info['AVSCODE'])) { 161 $message .= 'AVSCODE: ' . $response_info['AVSCODE'] . "\n"; 162 } 163 164 if (isset($response_info['CVV2MATCH'])) { 165 $message .= 'CVV2MATCH: ' . $response_info['CVV2MATCH'] . "\n"; 166 } 167 168 if (isset($response_info['TRANSACTIONID'])) { 169 $message .= 'TRANSACTIONID: ' . $response_info['TRANSACTIONID'] . "\n"; 170 } 171 172 $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_pp_pro_order_status_id'), $message, false); 173 174 $json['success'] = $this->url->link('checkout/success'); 175 } else { 176 $json['error'] = $response_info['L_LONGMESSAGE0']; 177 } 178 179 $this->response->addHeader('Content-Type: application/json'); 180 $this->response->setOutput(json_encode($json)); 181 } 182 }