| [ PHPXref.com ] | [ Generated: Sun Jul 20 21:14:02 2008 ] | [ Zen Cart 1.3.0.1 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * ipn_main_handler.php callback handler for paypal IPN payment method 4 * 5 * @package paymentMethod 6 * @copyright Copyright 2003-2005 Zen Cart Development Team 7 * @copyright Portions Copyright 2003 osCommerce 8 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 9 * @version $Id: ipn_main_handler.php 3475 2006-04-22 04:35:09Z ajeh $ 10 */ 11 /** 12 * require general paypal functions 13 */ 14 require ('includes/modules/payment/paypal/paypal_functions.php'); 15 /** 16 * require custom paypal application_top.php 17 */ 18 require ('includes/modules/payment/paypal/ipn_application_top.php'); 19 /** 20 * require language defines 21 */ 22 if (!isset($_SESSION['language'])) $_SESSION['language'] = 'english'; 23 if (file_exists(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . $template_dir_select . 'checkout_process.php')) { 24 require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . $template_dir_select . 'checkout_process.php'); 25 } else { 26 require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/checkout_process.php'); 27 } 28 //require('includes/languages/english/checkout_process.php'); 29 30 $scheme = 'http://'; 31 if (ENABLE_SSL == 'true') $scheme = 'http://'; 32 //Parse url 33 $web = parse_url($scheme . MODULE_PAYMENT_PAYPAL_HANDLER); 34 35 //build post string 36 foreach($_POST as $i=>$v) { 37 $postdata .= $i . "=" . urlencode(stripslashes($v)) . "&"; 38 } 39 40 $postdata .= "cmd=_notify-validate"; 41 42 if (MODULE_PAYMENT_PAYPAL_TESTING == 'Test') { 43 $info = "VERIFIED"; 44 } else { 45 //Set the port number 46 if($web['scheme'] == "https") { 47 $web['port']="443"; $ssl="ssl://"; 48 } else { 49 $web['port']="80"; 50 } 51 52 //Create paypal connection 53 $fp=@fsockopen($ssl . $web['host'],$web['port'],$errnum,$errstr,30); 54 55 if(!$fp) { 56 ipn_debug_email('IPN FATAL ERROR::Could not establish fsockopen. Host Details = ' . $ssl . $web['host'] . ':' . $web['port']); 57 die(); 58 } 59 60 61 //Post Data 62 63 fputs($fp, "POST $web[path] HTTP/1.1\r\n"); 64 fputs($fp, "Host: $web[host]\r\n"); 65 fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 66 fputs($fp, "Content-length: ".strlen($postdata)."\r\n"); 67 fputs($fp, "Connection: close\r\n\r\n"); 68 fputs($fp, $postdata . "\r\n\r\n"); 69 70 //loop through the response from the server 71 while(!feof($fp)) { 72 $info[]=@fgets($fp, 1024); 73 } 74 75 //close fp - we are done with it 76 fclose($fp); 77 78 //break up results into a string 79 $info = implode(",",$info); 80 } 81 82 ipn_debug_email('IPN INFO - POST VARS ' . "\n" . $postdata); 83 ipn_debug_email('IPN INFO - CURL INFO ' . "\n" . $info); 84 85 86 if (SEND_PAYPAL_TRANS_DETAILS == 'Yes') ipn_debug_email('IPN INFO::Transaction Details # ' . $info, '', true); 87 88 if (!ipn_validate_transaction($info, $_POST) === true) { 89 ipn_debug_email('IPN FATAL ERROR::Transaction did not validate'); 90 die(); 91 } 92 /** 93 * reaquire shipping class 94 */ 95 require(DIR_WS_CLASSES . 'shipping.php'); 96 /** 97 * require payment class 98 */ 99 require(DIR_WS_CLASSES . 'payment.php'); 100 $payment_modules = new payment($_SESSION['payment']); 101 $shipping_modules = new shipping($_SESSION['shipping']); 102 /** 103 * require order class 104 */ 105 require(DIR_WS_CLASSES . 'order.php'); 106 $order = new order(); 107 /** 108 * require order_total class 109 */ 110 require(DIR_WS_CLASSES . 'order_total.php'); 111 $order_total_modules = new order_total(); 112 $order_totals = $order_total_modules->process(); 113 114 $txn_type = ipn_test_txn_uniqueness(); 115 ipn_debug_email('IPN NOTICE:set transaction type ' . $txn_type . ' postdata=' . $postdata); 116 // For now we filter out subscription payments 117 if ($_POST['txn_type'] == 'subcr_payment') { 118 ipn_debug_email('IPN NOTICE: Subscription payemnt - Filter for now'); 119 die(); 120 } 121 switch ($txn_type) { 122 case 'unique': 123 if (valid_payment($info, $order->info['total'], $_SESSION['currency']) === false) { 124 die(); 125 } 126 if ($ipnFoundSession === false) { 127 ipn_debug_email('IPN NOTICE: Unique but no session - Must be a one of personal payment'); 128 die(); 129 } 130 $new_order_id = $order->create($order_totals); 131 $paypal_order = ipn_create_order_array($new_order_id, $txn_type); 132 zen_db_perform(TABLE_PAYPAL, $paypal_order); 133 $insert_id = $db->Insert_ID(); 134 $paypal_order_history = ipn_create_order_history_array($insert_id); 135 zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $paypal_order_history); 136 $new_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; 137 if ($_POST['payment_status'] =='Pending') { 138 $new_status = MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID; 139 $db->Execute("update " . TABLE_ORDERS . " 140 set orders_status = " . MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID . " 141 where orders_id = '" . $new_order_id . "'"); 142 } 143 $sql_data_array = array('orders_id' => $new_order_id, 144 'orders_status_id' => $new_status, 145 'date_added' => 'now()', 146 'comments' => 'PayPal status: ' . $_POST['payment_status'] . ' ' . $_POST['pending_reason']. ' @ '.$_POST['payment_date'] . ' Parent Trans ID:' . $_POST['parent_txn_id'] . ' Trans ID:' . $_POST['txn_id'] . ' Amount: ' . $_POST['mc_gross'], 147 'customer_notified' => false 148 ); 149 150 zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); 151 $order->create_add_products($new_order_id, 2); 152 $order->send_order_email($new_order_id, 2); 153 $_SESSION['cart']->reset(true); 154 break; 155 case 'parent': 156 case 'echeck-denied': 157 case 'echeck-cleared': 158 if ($txn_type == 'parent') { 159 $ipn_id = $db->Execute("select zen_order_id, paypal_ipn_id 160 from " . TABLE_PAYPAL . " 161 where txn_id = '" . $_POST['parent_txn_id'] . "'"); 162 } else { 163 $ipn_id = $db->Execute("select zen_order_id, paypal_ipn_id 164 from " . TABLE_PAYPAL . " 165 where txn_id = '" . $_POST['txn_id'] . "'"); 166 } 167 if ($txn_type == 'parent') { 168 $paypal_order = ipn_create_order_array($ipn_id->fields['zen_order_id'], $txn_type); 169 zen_db_perform(TABLE_PAYPAL, $paypal_order); 170 } else { 171 $paypal_order = ipn_create_order_update_array($txn_type); 172 zen_db_perform(TABLE_PAYPAL, $paypal_order, 'update', "txn_id='" . $_POST['txn_id'] . "'"); 173 } 174 $paypal_order_history = ipn_create_order_history_array($ipn_id->fields['paypal_ipn_id']); 175 //payment_status=Refunded 176 if ($_POST['payment_status'] == 'Refunded' || $_POST['payment_status'] == 'Denied') { 177 $new_status = MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID; 178 } elseif ($txn_type=='echeck-cleared') { 179 $new_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; 180 } 181 ipn_debug_email('IPN NOTICE:set new status ' . $new_status . ' for reason_code = ' . $_POST['pending_reason'] . " order id = " . $ipn_id->fields['zen_order_id']); 182 183 if ($_POST['payment_status'] == 'Refunded' || $_POST['payment_status'] == 'Denied' || $txn_type=='echeck-cleared') { 184 $db->Execute("update " . TABLE_ORDERS . " 185 set orders_status = '" . $new_status . "' 186 where orders_id = '" . $ipn_id->fields['zen_order_id'] . "'"); 187 188 $sql_data_array = array('orders_id' => $ipn_id->fields['zen_order_id'], 189 'orders_status_id' => $new_status, 190 'date_added' => 'now()', 191 'comments' => 'PayPal status: ' . $_POST['payment_status'] . ' ' . ' @ '.$_POST['payment_date'] . ' Parent Trans ID:' . $_POST['parent_txn_id'] . ' Trans ID:' . $_POST['txn_id'] . ' Amount: ' . $_POST['mc_gross'], 192 'customer_notified' => false 193 ); 194 195 zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); 196 } 197 break; 198 default: 199 ipn_debug_email('IPN WARNING:Could not establish txn type ' . $txn_type . ' postdata=' . $postdata); 200 } 201 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |