[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * ipn_main_handler.php callback handler for paypal IPN payment method 4 * 5 * @package paymentMethod 6 * @copyright Copyright 2003-2007 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 6528 2007-06-25 23:25:27Z drbyte $ 10 */ 11 12 /** 13 * handle Express Checkout processing: 14 */ 15 if (isset($_GET['type']) && $_GET['type'] == 'ec') { 16 // this is an EC handler request 17 require ('includes/application_top.php'); 18 require(DIR_WS_CLASSES . 'payment.php'); 19 // See if we were sent a request to clear the session for PayPal. 20 if (isset($_GET['clearSess']) || isset($_GET['ec_cancel'])) { 21 // Unset the PayPal EC information. 22 unset($_SESSION['paypal_ec_temp']); 23 unset($_SESSION['paypal_ec_token']); 24 unset($_SESSION['paypal_ec_payer_id']); 25 unset($_SESSION['paypal_ec_payer_info']); 26 } 27 // See if the paypalwpp module is enabled. 28 if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') { 29 $paypalwpp_module = 'paypalwpp'; 30 // init the payment object 31 $payment_modules = new payment($paypalwpp_module); 32 // set the payment, if they're hitting us here then we know 33 // the payment method selected right now. 34 $_SESSION['payment'] = $paypalwpp_module; 35 // check to see if we have a token sent back from PayPal. 36 if (!isset($_SESSION['paypal_ec_token']) || empty($_SESSION['paypal_ec_token'])) { 37 // We have not gone to PayPal's website yet in order to grab 38 // a token at this time. This will send the user over to PayPal's 39 // website to login and return a token 40 $$paypalwpp_module->ec_step1(); 41 } else { 42 // This will push on the second step of the paypalwpp payment 43 // module, as we already have a PayPal express checkout token 44 // at this point. 45 $$paypalwpp_module->ec_step2(); 46 } 47 } 48 ?> 49 <html> 50 Processing... 51 </html> 52 <?php 53 54 /** 55 * If we got here, we are an IPN transaction: 56 */ 57 58 } else { 59 $isECtransaction = ($_POST['txn_type']=='express_checkout' || $_POST['txn_type']=='cart'); 60 /** 61 * require general paypal functions 62 */ 63 require ('includes/modules/payment/paypal/paypal_functions.php'); 64 /** 65 * require custom paypal application_top.php 66 */ 67 require ('includes/modules/payment/paypal/ipn_application_top.php'); 68 /** 69 * require language defines 70 */ 71 if (!isset($_SESSION['language'])) $_SESSION['language'] = 'english'; 72 if (file_exists(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . $template_dir_select . 'checkout_process.php')) { 73 require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/' . $template_dir_select . 'checkout_process.php'); 74 } else { 75 require(DIR_WS_LANGUAGES . $_SESSION['language'] . '/checkout_process.php'); 76 } 77 //require('includes/languages/english/checkout_process.php'); 78 $extraDebug = (defined('IPN_EXTRA_DEBUG_DETAILS') && IPN_EXTRA_DEBUG_DETAILS == 'All'); 79 /** 80 * do confirmation post-back to PayPal and extract the results for subsequent use 81 */ 82 $ipnData = ipn_postback(); 83 $postdata = $ipnData['postdata']; 84 $info = $ipnData['info']; 85 $new_status = 1; 86 ipn_debug_email('Breakpoint: 1 - Collected data from PayPal notification'); 87 88 /** 89 * validate transaction -- email address, matching txn record, etc 90 */ 91 if (!ipn_validate_transaction($info, $_POST) === true) { 92 if (!$isECtransaction && $_POST['txn_type'] != '') { 93 ipn_debug_email('IPN FATAL ERROR :: Transaction did not validate'); 94 die(); 95 } 96 } 97 ipn_debug_email('Breakpoint: 2 - Validated transaction components'); 98 /** 99 * is this a sandbox transaction? 100 */ 101 if (isset($_POST['test_ipn']) && $_POST['test_ipn'] == 1) { 102 ipn_debug_email('IPN NOTICE :: Processing SANDBOX transaction.'); 103 } 104 if (isset($_POST['test_internal']) && $_POST['test_internal'] == 1) { 105 ipn_debug_email('IPN NOTICE :: Processing INTERNAL TESTING transaction.'); 106 } 107 if (isset($_POST['pending_reason']) && $_POST['pending_reason'] == 'unilateral') { 108 ipn_debug_email('*** NOTE: TRANSACTION IS IN *unilateral* STATUS pending creation of a PayPal account for this receiver_email address.' . "\n" . 'Please create the account, or make sure the PayPal account is *Verified*.'); 109 } 110 111 ipn_debug_email('Breakpoint: 3 - Communication method verified'); 112 /** 113 * Lookup transaction history information in preparation for matching and relevant updates 114 */ 115 $lookupData = ipn_lookup_transaction($_POST); 116 $ordersID = $lookupData['zen_order_id']; 117 $paypalipnID = $lookupData['paypal_ipn_id']; 118 $txn_type = $lookupData['txn_type']; 119 120 ipn_debug_email('Breakpoint: 4 - ' . 'Details: txn_type=' . $txn_type . ' ordersID = '. $ordersID . ' IPN_id=' . $paypalipnID . "\n\n" . ' Relevant data from POST:' . "\n " . 'txn_type = ' . $txn_type . "\n " . 'parent_txn_id = ' . ($_POST['parent_txn_id'] =='' ? 'None' : $_POST['parent_txn_id']) . "\n " . 'txn_id = ' . $_POST['txn_id']); 121 122 // this is used to determine whether a record needs insertion. ie: original echeck notice failed, but now we have cleared, so need parent record established: 123 $new_record_needed = ($txn_type == 'unique' ? true : false); 124 /** 125 * evaluate what type of transaction we're processing 126 */ 127 $txn_type = ipn_determine_txn_type($_POST, $txn_type); 128 ipn_debug_email('Breakpoint: 5 - Transaction type (txn_type) = ' . $txn_type); 129 130 /** 131 * take action based on transaction type and corresponding requirements 132 */ 133 switch ($txn_type) { 134 case ($_POST['txn_type'] == 'send_money'): 135 case ($_POST['txn_type'] == 'merch_payment'): 136 case ($_POST['txn_type'] == 'new_case'): 137 // these types are irrelevant to ZC transactions 138 ipn_debug_email('IPN NOTICE :: Transaction txn_type not relevant to Zen Cart processing. IPN handler aborted.'); 139 die(); 140 break; 141 case (substr($_POST['txn_type'],0,7) == 'subscr_'): 142 // For now we filter out subscription payments 143 ipn_debug_email('IPN NOTICE :: Subscription payment - Not currently supported by Zen Cart. IPN handler aborted.'); 144 die(); 145 break; 146 147 case 'pending-unilateral': 148 // cannot process this order because the merchant's PayPal account isn't valid yet 149 ipn_debug_email('IPN NOTICE :: Please create a valid PayPal account and follow the steps to *Verify* it. IPN handler aborted.'); 150 die(); 151 break; 152 case 'pending-address': 153 case 'pending-intl': 154 case 'pending-multicurrency': 155 case 'pending-verify': 156 if (!isECtransaction) { 157 ipn_debug_email('IPN NOTICE :: '.$txn_type.' transaction -- inserting initial record for reference purposes'); 158 $paypal_order = ipn_create_order_array($ordersID, $txn_type); 159 zen_db_perform(TABLE_PAYPAL, $paypal_order); 160 $paypal_order_history = ipn_create_order_history_array($paypalipnID); 161 zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $paypal_order_history); 162 die(); 163 break; 164 } 165 case 'cart': 166 case 'express_checkout': 167 // This is an express-checkout transaction -- IPN serves no needed purpose 168 if ($_POST['payment_status'] == 'Completed') { 169 ipn_debug_email('IPN NOTICE :: Express Checkout payment notice on completed order -- IPN Ignored'); 170 die(); 171 } 172 if (!(substr($txn_type,0,8) == 'pending-' && (int)$ordersID <= 0) && !($new_record_needed && $txn_type == 'echeck-cleared') && $txn_type != 'unique') break; 173 174 case (substr($txn_type,0,8) == 'pending-' && (int)$ordersID <= 0): 175 case ($new_record_needed && $txn_type == 'echeck-cleared'): 176 case 'unique': 177 /** 178 * require shipping class 179 */ 180 require(DIR_WS_CLASSES . 'shipping.php'); 181 /** 182 * require payment class 183 */ 184 require(DIR_WS_CLASSES . 'payment.php'); 185 $payment_modules = new payment($_SESSION['payment']); 186 $shipping_modules = new shipping($_SESSION['shipping']); 187 /** 188 * require order class 189 */ 190 require(DIR_WS_CLASSES . 'order.php'); 191 $order = new order(); 192 /** 193 * require order_total class 194 */ 195 require(DIR_WS_CLASSES . 'order_total.php'); 196 $order_total_modules = new order_total(); 197 $order_totals = $order_total_modules->process(); 198 199 if (valid_payment($order->info['total'], $_SESSION['currency']) === false) { 200 die(); 201 } 202 if ($ipnFoundSession === false) { 203 ipn_debug_email('IPN NOTICE :: Unique but no session - Assumed to be a personal payment, rather than an IPN transaction. Ignoring.'); 204 die(); 205 } 206 $insert_id = $order->create($order_totals); 207 if ($extraDebug) ipn_debug_email('Breakpoint: 5a - built order -- OID:' . $insert_id); 208 $paypal_order = ipn_create_order_array($insert_id, $txn_type); 209 if ($extraDebug) ipn_debug_email('Breakpoint: 5b - PP table OID:' . print_r($paypal_order, true)); 210 zen_db_perform(TABLE_PAYPAL, $paypal_order); 211 if ($extraDebug) ipn_debug_email('Breakpoint: 5c - PP table OID saved'); 212 $pp_hist_id = $db->Insert_ID(); 213 if ($extraDebug) ipn_debug_email('Breakpoint: 5d - PP hist ID:' . $pp_hist_id); 214 $paypal_order_history = ipn_create_order_history_array($pp_hist_id); 215 if ($extraDebug) ipn_debug_email('Breakpoint: 5e - PP hist_data:' . print_r($paypal_order_history, true)); 216 zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $paypal_order_history); 217 if ($extraDebug) ipn_debug_email('Breakpoint: 5f - PP hist saved'); 218 $new_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; 219 if ($extraDebug) ipn_debug_email('Breakpoint: 5g - new status code' . $new_status); 220 if ($_POST['payment_status'] =='Pending') { 221 $new_status = MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID; 222 if ($extraDebug) ipn_debug_email('Breakpoint: 5h - newer status code' . $new_status); 223 $db->Execute("update " . TABLE_ORDERS . " 224 set orders_status = " . MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID . " 225 where orders_id = '" . $insert_id . "'"); 226 if ($extraDebug) ipn_debug_email('Breakpoint: 5i - order table updated'); 227 } 228 $sql_data_array = array('orders_id' => $insert_id, 229 'orders_status_id' => $new_status, 230 'date_added' => 'now()', 231 'comments' => 'PayPal status: ' . $_POST['payment_status'] . ' ' . $_POST['pending_reason']. ' @ '.$_POST['payment_date'] . (($_POST['parent_txn_id'] !='') ? "\n" . ' Parent Trans ID:' . $_POST['parent_txn_id'] : '') . "\n" . ' Trans ID:' . $_POST['txn_id'] . "\n" . ' Amount: ' . $_POST['mc_gross'] . ' ' . $_POST['mc_currency'], 232 'customer_notified' => false 233 ); 234 if ($extraDebug) ipn_debug_email('Breakpoint: 5j - order stat hist update:' . print_r($sql_data_array, true)); 235 zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array); 236 if ($extraDebug) ipn_debug_email('Breakpoint: 5k - OSH update done'); 237 $order->create_add_products($insert_id, 2); 238 if ($extraDebug) ipn_debug_email('Breakpoint: 5L - adding products'); 239 $order->send_order_email($insert_id, 2); 240 if ($extraDebug) ipn_debug_email('Breakpoint: 5m - emailing customer'); 241 $_SESSION['cart']->reset(true); 242 if ($extraDebug) ipn_debug_email('Breakpoint: 5n - emptying cart'); 243 $ordersID = $insert_id; 244 $paypalipnID = $pp_hist_id; 245 ipn_debug_email('Breakpoint: 6 - Completed IPN order add.' . ' ordersID = '. $ordersID . ' IPN_id =' . $paypalipnID); 246 if (!($new_record_needed && $txn_type == 'echeck-cleared')) break; 247 248 case 'parent': 249 case 'cleared-address': 250 case 'cleared-multicurrency': 251 case 'cleared-echeck': 252 case 'cleared-authorization': 253 case 'cleared-verify': 254 case 'cleared-intl': 255 case 'echeck-denied': 256 case 'echeck-cleared': 257 case 'denied-address': 258 case 'denied-multicurrency': 259 case 'denied-echeck': 260 case 'failed-echeck': 261 case 'denied-intl': 262 case 'denied': 263 case 'express-checkout-cleared': 264 if ($txn_type == 'parent') { 265 $paypal_order = ipn_create_order_array($ordersID, $txn_type); 266 zen_db_perform(TABLE_PAYPAL, $paypal_order); 267 } else { 268 $paypal_order = ipn_create_order_update_array($txn_type); 269 zen_db_perform(TABLE_PAYPAL, $paypal_order, 'update', "txn_id='" . $_POST['txn_id'] . "'"); 270 } 271 $paypal_order_history = ipn_create_order_history_array($paypalipnID); 272 zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $paypal_order_history); 273 ipn_debug_email('IPN NOTICE :: Updating PP table record status for order #' . $ordersID . ' txn_id: ' . $_POST['txn_id'] . ' PP IPN ID: ' . $paypalipnID); 274 275 switch ($txn_type) { 276 case ($_POST['payment_status'] == 'Refunded' || $_POST['payment_status'] == 'Reversed'): 277 //payment_status=Refunded 278 $new_status = MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID; 279 if (defined('MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID') && (int)MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID > 0 && !$isECtransaction) $new_status = MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID; 280 break; 281 case 'echeck-denied': 282 case 'denied-echeck': 283 case 'failed-echeck': 284 //payment_status=Denied or failed 285 $new_status = ($isECtransaction ? MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID : MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID); 286 break; 287 case 'echeck-cleared': 288 //echeck-cleared 289 $new_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID; 290 break; 291 case ($txn_type=='express-checkout-cleared' || substr($txn_type,0,8) == 'cleared-'): 292 //express-checkout-cleared 293 $new_status = MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID; 294 break; 295 case 'pending-auth': 296 // pending authorization 297 $new_status = ($isECtransaction ? MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID : MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID); 298 break; 299 case (substr($txn_type,0,7) == 'denied-'): 300 // denied for any other reason - treat as pending for now 301 case (substr($txn_type,0,8) == 'pending-'): 302 // pending anything 303 $new_status = ($isECtransaction ? MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID : MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID); 304 break; 305 } 306 // update order status history with new information 307 ipn_debug_email('IPN NOTICE :: Set new status ' . $new_status . " for order ID = " . $ordersID . ($_POST['pending_reason'] != '' ? '. Reason_code = ' . $_POST['pending_reason'] : '') ); 308 if (in_array($_POST['payment_status'], array('Refunded', 'Reversed', 'Denied', 'Failed')) 309 || substr($txn_type,0,8) == 'cleared-' || $txn_type=='echeck-cleared' || $txn_type == 'express-checkout-cleared') { 310 if ((int)$new_status == 0) $new_status = 1; 311 ipn_update_orders_status_and_history($ordersID, $new_status, $txn_type); 312 } 313 break; 314 case ($txn_type == 'pending-echeck' && (int)$ordersID > 0): 315 ipn_debug_email('IPN NOTICE :: Pending echeck transaction for existing order. No action required. Waiting for echeck to clear.'); 316 break; 317 case ($txn_type == 'pending-multicurrency' && (int)$ordersID > 0): 318 ipn_debug_email('IPN NOTICE :: Pending multicurrency transaction for existing order. No action required. Waiting for merchant to "accept" the order via PayPal account console.'); 319 break; 320 case ($txn_type == 'pending-address' && (int)$ordersID > 0): 321 ipn_debug_email('IPN NOTICE :: "Pending address" transaction for existing order. No action required. Waiting for address approval by store owner via PayPal account console.'); 322 break; 323 default: 324 // can't understand result found. Thus, logging and aborting. 325 ipn_debug_email('IPN WARNING :: Could not process for txn type: ' . $txn_type . "\n" . ' postdata=' . str_replace('&', " \n&", urldecode($postdata))); 326 } 327 } 328 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 16:45:43 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |