[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 ipn_main_handler.php

Zen Cart 源代码 ipn_main_handler.php




下载文件

文件名: ipn_main_handler.php
文件类型: PHP文件
文件大小: 25.32 KiB
MD5: eb0b1551a839e3217caca2b85207a4bc

ipn_main_handler.php - 关闭高亮
  1. <?php
  2. /**
  3.  * ipn_main_handler.php callback handler for PayPal IPN notifications
  4.  *
  5.  * @package paymentMethod
  6.  * @copyright Copyright 2003-2010 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 18014 2010-10-22 03:39:17Z drbyte $
  10.  */
  11. if (!defined('TEXT_RESELECT_SHIPPING')) define('TEXT_RESELECT_SHIPPING', 'You have changed the items in your cart since shipping was last calculated, and costs may have changed. Please verify/re-select your shipping method.');
  12.  
  13. /**
  14.  * handle Express Checkout processing:
  15.  */
  16. if (isset($_GET['type']) && $_GET['type'] == 'ec') {
  17.   // this is an EC handler request
  18.   require('includes/application_top.php');
  19.  
  20. // Validate Cart for checkout
  21.   $_SESSION['valid_to_checkout'] = true;
  22.   $_SESSION['cart']->get_products(true);
  23.   if ($_SESSION['valid_to_checkout'] == false || $_SESSION['cart']->count_contents() <= 0) {
  24.     $messageStack->add_session('shopping_cart', ERROR_CART_UPDATE, 'error');
  25.     zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
  26.   }
  27.  
  28.   // Stock Check to prevent checkout if cart contents rules violations exist
  29.   if ( STOCK_CHECK == 'true' && STOCK_ALLOW_CHECKOUT != 'true' && isset($_SESSION['cart']) ) {
  30.     $products = $_SESSION['cart']->get_products();
  31.     for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  32.       if (zen_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
  33.         zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
  34.         break;
  35.       }
  36.     }
  37.   }
  38.   // if cart contents has changed since last pass, reset
  39.   if (isset($_SESSION['cart']->cartID)) {
  40.     if (isset($_SESSION['cartID'])) {  // This will only be set if customer has been to the checkout_shipping page. Will *not* be set if starting via EC Shortcut button, so don't want to redirect in that case.
  41.       if ($_SESSION['cart']->cartID != $_SESSION['cartID']) {
  42.         if (isset($_SESSION['shipping'])) {
  43.           unset($_SESSION['shipping']);
  44.           $messageStack->add_session('checkout_shipping', TEXT_RESELECT_SHIPPING, 'error');
  45.           zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  46.         }
  47.       }
  48.     }
  49. //  } else {
  50. //    zen_redirect(zen_href_link(FILENAME_TIME_OUT));
  51.   }
  52.  
  53.   require(DIR_WS_CLASSES . 'payment.php');
  54.   // See if we were sent a request to clear the session for PayPal.
  55.   if (isset($_GET['clearSess']) || isset($_GET['amp;clearSess']) || isset($_GET['ec_cancel']) || isset($_GET['amp;ec_cancel'])) {
  56.     // Unset the PayPal EC information.
  57.     unset($_SESSION['paypal_ec_temp']);
  58.     unset($_SESSION['paypal_ec_token']);
  59.     unset($_SESSION['paypal_ec_payer_id']);
  60.     unset($_SESSION['paypal_ec_payer_info']);
  61.   }
  62.   // See if the paypalwpp module is enabled.
  63.   if (defined('MODULE_PAYMENT_PAYPALWPP_STATUS') && MODULE_PAYMENT_PAYPALWPP_STATUS == 'True') {
  64.     $paypalwpp_module = 'paypalwpp';
  65.     // init the payment object
  66.     $payment_modules = new payment($paypalwpp_module);
  67.     // set the payment, if they're hitting us here then we know
  68.     // the payment method selected right now.
  69.     $_SESSION['payment'] = $paypalwpp_module;
  70.     // check to see if we have a token sent back from PayPal.
  71.     if (!isset($_SESSION['paypal_ec_token']) || empty($_SESSION['paypal_ec_token'])) {
  72.       // We have not gone to PayPal's website yet in order to grab
  73.       // a token at this time.  This will send the customer over to PayPal's
  74.       // website to login and return a token
  75.       $$paypalwpp_module->ec_step1();
  76.     } else {
  77.       // This will push on the second step of the paypal ec payment
  78.       // module, as we already have a PayPal express checkout token
  79.       // at this point.
  80.       $$paypalwpp_module->ec_step2();
  81.     }
  82.   }
  83. ?>
  84. <html>
  85. Processing...
  86. </html>
  87.   <?php
  88.  
  89.   /**
  90.    * If we got here, we are an IPN transaction (not Express Checkout):
  91.    */
  92.  
  93. } else {
  94.   /**
  95.    * detect odd cases of extra-url-encoded POST data coming back from PayPal
  96.    */
  97.   foreach(array('receiver_email', 'payer_email', 'business', 'txn_type', 'transaction_subject', 'custom', 'payment_date', 'item_number', 'item_name', 'first_name', 'last_name') as $key) {
  98.     if (isset($_POST[$key]) && strstr($_POST[$key], '%')) {
  99.       $_POST[$key] = urldecode($_POST[$key]);
  100.     }
  101.   }
  102.   /**
  103.    * detect type of transaction
  104.    */
  105.   $isECtransaction = ((isset($_POST['txn_type']) && $_POST['txn_type']=='express_checkout') || (isset($_POST['custom']) && in_array(substr($_POST['custom'], 0, 3), array('EC-', 'DP-', 'WPP')))); /*|| $_POST['txn_type']=='cart'*/
  106.   $isDPtransaction = (isset($_POST['custom']) && in_array(substr($_POST['custom'], 0, 3), array('DP-', 'WPP')));
  107.   /**
  108.    * set paypal-specific application_top parameters
  109.    */
  110.   $current_page_base = 'paypalipn';
  111.   $loaderPrefix = 'paypal_ipn';
  112.   $show_all_errors = FALSE;
  113.   require('includes/application_top.php');
  114.  
  115.   $extraDebug = (defined('IPN_EXTRA_DEBUG_DETAILS') && IPN_EXTRA_DEBUG_DETAILS == 'All');
  116.  
  117.   if (  (defined('MODULE_PAYMENT_PAYPALWPP_DEBUGGING') && strstr(MODULE_PAYMENT_PAYPALWPP_DEBUGGING, 'Log')) ||
  118.       (defined('MODULE_PAYMENT_PAYPAL_IPN_DEBUG') && strstr(MODULE_PAYMENT_PAYPAL_IPN_DEBUG, 'Log')) ||
  119.       ($_REQUEST['ppdebug'] == 'on' && strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])) || $extraDebug  ) {
  120.     $show_all_errors = true;
  121.     $debug_logfile_path = ipn_debug_email('Breakpoint: 0 - Initializing debugging.');
  122.     if ($debug_logfile_path == '') $debug_logfile_path = 'includes/modules/payment/paypal/logs/ipn_debug_php_errors-'.time().'.log';
  123.     @ini_set('log_errors', 1);
  124.     @ini_set('log_errors_max_len', 0);
  125.     @ini_set('display_errors', 0); // do not output errors to screen/browser/client (only to log file)
  126.     @ini_set('error_log', DIR_FS_CATALOG . $debug_logfile_path);
  127.     error_reporting(version_compare(PHP_VERSION, 5.3, '>=') ? E_ALL & ~E_DEPRECATED & ~E_NOTICE : version_compare(PHP_VERSION, 6.0, '>=') ? E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT : E_ALL & ~E_NOTICE);
  128.   }
  129.  
  130.   ipn_debug_email('Breakpoint: Flag Status:' . "\nisECtransaction = " . (int)$isECtransaction . "\nisDPtransaction = " . (int)$isDPtransaction);
  131.   /**
  132.    * do confirmation post-back to PayPal and extract the results for subsequent use
  133.    */
  134.   $info  = ipn_postback();
  135.   $new_status = 1;
  136.   ipn_debug_email('Breakpoint: 1 - Collected data from PayPal notification');
  137.  
  138.   /**
  139.    * validate transaction -- email address, matching txn record, etc
  140.    */
  141.   if (!ipn_validate_transaction($info, $_POST, 'IPN') === true) {
  142.     if (!$isECtransaction && $_POST['txn_type'] != '') {
  143.       ipn_debug_email('IPN FATAL ERROR :: Transaction did not validate. ABORTED.');
  144.       die();
  145.     }
  146.   }
  147.  
  148.   if ($isDPtransaction) {
  149.     ipn_debug_email('IPN NOTICE :: This is a Website Payments Pro transaction.  The rest of this log file is INFORMATION ONLY, and is not used for real processing.');
  150.   }
  151.  
  152.   ipn_debug_email('Breakpoint: 2 - Validated transaction components');
  153.   if ($_POST ['exchange_rate'] == '')  $_POST [exchange_rate] = 1;
  154.   if ($_POST ['num_cart_items'] == '') $_POST [num_cart_items] = 1;
  155.   if ($_POST ['settle_amount'] == '')  $_POST [settle_amount] = 0;
  156.  
  157.   /**
  158.    * is this a sandbox transaction?
  159.    */
  160.   if (isset($_POST['test_ipn']) && $_POST['test_ipn'] == 1) {
  161.     ipn_debug_email('IPN NOTICE :: Processing SANDBOX transaction.');
  162.   }
  163.   if (isset($_POST['test_internal']) && $_POST['test_internal'] == 1) {
  164.     ipn_debug_email('IPN NOTICE :: Processing INTERNAL TESTING transaction.');
  165.   }
  166.   if (isset($_POST['pending_reason']) && $_POST['pending_reason'] == 'unilateral') {
  167.     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*.');
  168.   }
  169.  
  170.   ipn_debug_email('Breakpoint: 3 - Communication method verified');
  171.   /**
  172.    * Lookup transaction history information in preparation for matching and relevant updates
  173.    */
  174.   $lookupData  = ipn_lookup_transaction($_POST);
  175.   $ordersID    = $lookupData['order_id'];
  176.   $paypalipnID = $lookupData['paypal_ipn_id'];
  177.   $txn_type    = $lookupData['txn_type'];
  178.   $parentLookup = $txn_type;
  179.  
  180.   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']);
  181.  
  182.   if (!$isECtransaction && !isset($_POST['parent_txn_id']) && $txn_type != 'cleared-echeck') {
  183.     if (defined('MODULE_PAYMENT_PAYPAL_PDTTOKEN') && MODULE_PAYMENT_PAYPAL_PDTTOKEN != '') {
  184.       ipn_debug_email('IPN NOTICE :: IPN pausing: waiting for PDT to process. Sleeping 10 seconds ...');
  185.       sleep(10);
  186.     }
  187.     if (ipn_get_stored_session($session_stuff) === false) {
  188.       ipn_debug_email('IPN ERROR :: No pending Website Payments Standard session data available.  Might be a duplicate transaction already entered via PDT.');
  189.       $ipnFoundSession = false;
  190.     }
  191.   }
  192.  
  193.   if ($ipnFoundSession == FALSE && !$isECtransaction && !$isDPtransaction && $txn_type != 'cleared-echeck') {
  194.     ipn_debug_email('NOTICE: IPN Processing Aborted due to missing matching transaction data, as per earlier debug message. Perhaps this transaction was already entered via PDT? Thus there is no need to process this incoming IPN notification.');
  195.     die();
  196.   }
  197.  
  198.   // 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:
  199.   $new_record_needed = ($txn_type == 'unique' ? true : false);
  200.   /**
  201.    * evaluate what type of transaction we're processing
  202.    */
  203.   $txn_type = ipn_determine_txn_type($_POST, $txn_type);
  204.   ipn_debug_email('Breakpoint: 5 - Transaction type (txn_type) = ' . $txn_type . '   [parentLookup='.$parentLookup.']');
  205.  
  206.   if ($_POST['payment_type'] == 'instant' && $isDPtransaction && ((isset($_POST['auth_status']) && $_POST['auth_status'] == 'Completed') || $_POST['payment_status'] == 'Completed')) {
  207.     ipn_debug_email('IPN NOTICE :: DP/Website Payments Pro notice -- IPN Ignored');
  208.     die();
  209.   }
  210.  
  211.   /**
  212.    * take action based on transaction type and corresponding requirements
  213.    */
  214.   switch ($txn_type) {
  215.     case ($_POST['txn_type'] == 'send_money'):
  216.     case ($_POST['txn_type'] == 'merch_payment'):
  217.     case ($_POST['txn_type'] == 'new_case'):
  218.     case ($_POST['txn_type'] == 'masspay'):
  219.       // these types are irrelevant to ZC transactions
  220.       ipn_debug_email('IPN NOTICE :: Transaction txn_type not relevant to Zen Cart processing. IPN handler aborted.' . $_POST['txn_type']);
  221.       die();
  222.       break;
  223.     case (substr($_POST['txn_type'],0,7) == 'subscr_'):
  224.       // For now we filter out subscription payments
  225.       ipn_debug_email('IPN NOTICE :: Subscription payment - Not currently supported by Zen Cart. IPN handler aborted.');
  226.       die();
  227.       break;
  228.  
  229.     case 'pending-unilateral':
  230.       // cannot process this order because the merchant's PayPal account isn't valid yet
  231.       ipn_debug_email('IPN NOTICE :: Please create a valid PayPal account and follow the steps to *Verify* it. IPN handler aborted.');
  232.       die();
  233.       break;
  234.     case 'pending-address':
  235.     case 'pending-intl':
  236.     case 'pending-multicurrency':
  237.     case 'pending-verify':
  238.       if (!$isECtransaction) {
  239.         ipn_debug_email('IPN NOTICE :: '.$txn_type.' transaction -- inserting initial record for reference purposes');
  240.         $sql_data_array = ipn_create_order_array($ordersID, $txn_type);
  241.         zen_db_perform(TABLE_PAYPAL, $sql_data_array);
  242.         $sql_data_array = ipn_create_order_history_array($paypalipnID);
  243.         zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $sql_data_array);
  244.         die();
  245.         break;
  246.       }
  247.     case (($txn_type == 'express_checkout' || $isECtransaction) && !strstr($txn_type, 'cleared') && $parentLookup != 'parent'):
  248.       if ($_POST['payment_status'] == 'Completed') {
  249.         // This is an express-checkout transaction -- IPN may not be needed
  250.         if (isset($_POST['auth_status']) && $_POST['auth_status'] == 'Completed') {
  251.           ipn_debug_email('IPN NOTICE :: Express Checkout payment notice on completed order -- IPN Ignored');
  252.           die();
  253.         }
  254.       }
  255.       if ($_POST['payment_type'] == 'instant' && isset($_POST['auth_status']) && $_POST['auth_status'] == 'Pending') {
  256.         ipn_debug_email('IPN NOTICE :: EC/DP notice on pre-auth order -- IPN Ignored');
  257.         die();
  258.       }
  259.       ipn_debug_email('Breakpoint: 5 - midstream checkpoint');
  260.       if (!(substr($txn_type,0,8) == 'pending-' && (int)$ordersID <= 0) && !($new_record_needed && $txn_type == 'echeck-cleared') && $txn_type != 'unique' && $txn_type != 'echeck-denied' && $txn_type != 'voided') {
  261.         ipn_debug_email('Breakpoint: 5 - Record does not need to be processed since it is not new and is not an update. See earlier notices. Processing aborted.');
  262.         break;
  263.       }
  264.  
  265.     case ($txn_type == 'cart'):
  266.       ipn_debug_email('IPN NOTICE :: This is a detailed-cart transaction');
  267.  
  268.     case ($txn_type == 'cart' && !$isECtransaction):
  269.       ipn_debug_email('IPN NOTICE :: This is a detailed-cart transaction (i)');
  270.  
  271.     case (substr($txn_type,0,8) == 'pending-' && (int)$ordersID <= 0):
  272.     case ($new_record_needed && $txn_type == 'echeck-cleared'):
  273.     case 'unique':
  274.       /**
  275.        * delete IPN session from PayPal table -- housekeeping
  276.        */
  277.       $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input(str_replace('zenid=', '', $_POST['custom'])) . "'");
  278.       /**
  279.        * require shipping class
  280.        */
  281.       require(DIR_WS_CLASSES . 'shipping.php');
  282.       /**
  283.        * require payment class
  284.        */
  285.       require(DIR_WS_CLASSES . 'payment.php');
  286.       $payment_modules = new payment($_SESSION['payment']);
  287.       $shipping_modules = new shipping($_SESSION['shipping']);
  288.       /**
  289.        * require order class
  290.        */
  291.       require(DIR_WS_CLASSES . 'order.php');
  292.       $order = new order();
  293.       /**
  294.        * require order_total class
  295.        */
  296.       require(DIR_WS_CLASSES . 'order_total.php');
  297.       $order_total_modules = new order_total();
  298.       $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_BEFORE_ORDER_TOTALS_PROCESS');
  299.       $order_totals = $order_total_modules->process();
  300.       $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_TOTALS_PROCESS');
  301.  
  302.       if (valid_payment($order->info['total'], $_SESSION['currency']) === false && !$isECtransaction && !$isDPtransaction) {
  303.         ipn_debug_email('IPN NOTICE :: Failed because of currency mismatch.');
  304.         die();
  305.       }
  306.       if ($ipnFoundSession === false && !$isECtransaction && !$isDPtransaction) {
  307.         ipn_debug_email('IPN NOTICE :: Unique but no session - Assumed to be a personal payment, rather than a new Website Payments Standard transaction. Ignoring.');
  308.         die();
  309.       }
  310.       if (!strstr($txn_type, 'denied') && !strstr($txn_type, 'failed') && !strstr($txn_type, 'voided')) {
  311.         $insert_id = $order->create($order_totals);
  312.         $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE');
  313.         ipn_debug_email('Breakpoint: 5a - built order -- OID: ' . $insert_id);
  314.         $sql_data_array = ipn_create_order_array($insert_id, $txn_type);
  315.         ipn_debug_email('Breakpoint: 5b - PP table OID: ' . print_r($sql_data_array, true));
  316.         zen_db_perform(TABLE_PAYPAL, $sql_data_array);
  317.         ipn_debug_email('Breakpoint: 5c - PP table OID saved');
  318.         $pp_hist_id = $db->Insert_ID();
  319.         $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE');
  320.         ipn_debug_email('Breakpoint: 5d - PP hist ID: ' . $pp_hist_id);
  321.         $sql_data_array = ipn_create_order_history_array($pp_hist_id);
  322.         ipn_debug_email('Breakpoint: 5e - PP hist_data:' . print_r($sql_data_array, true));
  323.         zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $sql_data_array);
  324.         ipn_debug_email('Breakpoint: 5f - PP hist saved');
  325.         $new_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID;
  326.         ipn_debug_email('Breakpoint: 5g - new status code: ' . $new_status);
  327.         if ($_POST['payment_status'] =='Pending') {
  328.           $new_status = (defined('MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID') && (int)MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID > 0 ? (int)MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID : 2);
  329.           ipn_debug_email('Breakpoint: 5h - newer status code: ' . (int)$new_status);
  330.           $sql = "UPDATE " . TABLE_ORDERS  . "
  331.                  SET orders_status = " . (int)$new_status . "
  332.                  WHERE orders_id = '" . (int)$insert_id . "'";
  333.           $db->Execute($sql);
  334.           ipn_debug_email('Breakpoint: 5i - order table updated');
  335.         }
  336.         $sql_data_array = array('orders_id' => (int)$insert_id,
  337.                                 'orders_status_id' => (int)$new_status,
  338.                                 'date_added' => 'now()',
  339.                                 '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'],
  340.                                 'customer_notified' => 0
  341.                                 );
  342.         ipn_debug_email('Breakpoint: 5j - order stat hist update:' . print_r($sql_data_array, true));
  343.         zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
  344.         if (MODULE_PAYMENT_PAYPAL_ADDRESS_OVERRIDE == '1') {
  345.           $sql_data_array['comments'] = '**** ADDRESS OVERRIDE ALERT!!! **** CHECK PAYPAL ORDER DETAILS FOR ACTUAL ADDRESS SELECTED BY CUSTOMER!!';
  346.           $sql_data_array['customer_notified'] = -1;
  347.         }
  348.         zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
  349.         ipn_debug_email('Breakpoint: 5k - OSH update done');
  350.         $order->create_add_products($insert_id, 2);
  351.         ipn_debug_email('Breakpoint: 5L - adding products');
  352.         $_SESSION['order_number_created'] = $insert_id;
  353.         $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS');
  354.         $order->send_order_email($insert_id, 2);
  355.         ipn_debug_email('Breakpoint: 5m - emailing customer');
  356.         $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL');
  357.         /** Prepare sales-tracking data for use by notifier class **/
  358.         $ototal = $order_subtotal = $credits_applied = 0;
  359.         for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
  360.           if ($order_totals[$i]['code'] == 'ot_subtotal') $order_subtotal = $order_totals[$i]['value'];
  361.           if ($$order_totals[$i]['code']->credit_class == true) $credits_applied += $order_totals[$i]['value'];
  362.           if ($order_totals[$i]['code'] == 'ot_total') $ototal = $order_totals[$i]['value'];
  363.         }
  364.         $commissionable_order = ($order_subtotal - $credits_applied);
  365.         $commissionable_order_formatted = $currencies->format($commissionable_order);
  366.         $_SESSION['order_summary']['order_number'] = $insert_id;
  367.         $_SESSION['order_summary']['order_subtotal'] = $order_subtotal;
  368.         $_SESSION['order_summary']['credits_applied'] = $credits_applied;
  369.         $_SESSION['order_summary']['order_total'] = $ototal;
  370.         $_SESSION['order_summary']['commissionable_order'] = $commissionable_order;
  371.         $_SESSION['order_summary']['commissionable_order_formatted'] = $commissionable_order_formatted;
  372.         $_SESSION['order_summary']['coupon_code'] = $order->info['coupon_code'];
  373.         $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_HANDLE_AFFILIATES', 'paypalipn');
  374.         $_SESSION['cart']->reset(true);
  375.         ipn_debug_email('Breakpoint: 5n - emptying cart');
  376.         $ordersID = $insert_id;
  377.         $paypalipnID = $pp_hist_id;
  378.         ipn_debug_email('Breakpoint: 6 - Completed IPN order add.' . '    ordersID = '. $ordersID . '  IPN tracking record = ' . $paypalipnID);
  379.         if (!($new_record_needed && $txn_type == 'echeck-cleared'))  break;
  380.       }
  381.     case 'parent':
  382.     case 'cleared-address':
  383.     case 'cleared-multicurrency':
  384.     case 'cleared-echeck':
  385.     case 'cleared-authorization':
  386.     case 'cleared-verify':
  387.     case 'cleared-intl':
  388.     case 'cleared-review':
  389.     case 'echeck-denied':
  390.     case 'echeck-cleared':
  391.     case 'denied-address':
  392.     case 'denied-multicurrency':
  393.     case 'denied-echeck':
  394.     case 'failed-echeck':
  395.     case 'denied-intl':
  396.     case 'denied':
  397.     case 'voided':
  398.     case 'express-checkout-cleared':
  399.       ipn_debug_email('IPN NOTICE :: Storing order/update details for order #' . $ordersID . ' txn_id: ' . $_POST['txn_id'] . ' PP IPN ID: ' . $paypalipnID);
  400.       if ($txn_type == 'parent') {
  401.         $sql_data_array = ipn_create_order_array($ordersID, $txn_type);
  402.         zen_db_perform(TABLE_PAYPAL, $sql_data_array);
  403.         $paypalipnID = $db->Insert_ID();
  404.       } else {
  405.         $sql_data_array = ipn_create_order_update_array($txn_type);
  406.         zen_db_perform(TABLE_PAYPAL, $sql_data_array, 'update', "txn_id='" . ($txn_type == 'cleared-authorization' ? $_POST['parent_txn_id'] : $_POST['txn_id']) . "'");
  407.         $sql = "select paypal_ipn_id from " . TABLE_PAYPAL . " where txn_id='" . $_POST['txn_id'] . "'";
  408.         $result = $db->Execute($sql);
  409.         $paypalipnID = $result->fields['paypal_ipn_id'];
  410.       }
  411.       $sql_data_array = ipn_create_order_history_array($paypalipnID);
  412.       zen_db_perform(TABLE_PAYPAL_PAYMENT_STATUS_HISTORY, $sql_data_array);
  413.       ipn_debug_email('IPN NOTICE :: Added PP status-history record for order #' . $ordersID . ' txn_id: ' . $_POST['txn_id'] . ' (updated/child) PP IPN ID: ' . $paypalipnID);
  414.  
  415.       switch ($txn_type) {
  416.         case 'voided':
  417.         case ($_POST['payment_status'] == 'Refunded' || $_POST['payment_status'] == 'Reversed' || $_POST['payment_status'] == 'Voided'):
  418.           //payment_status=Refunded or payment_status=Voided
  419.           $new_status = MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID;
  420.           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;
  421.           break;
  422.         case 'echeck-denied':
  423.         case 'denied-echeck':
  424.         case 'failed-echeck':
  425.           //payment_status=Denied or failed
  426.           $new_status = ($isECtransaction ? MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID : MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID);
  427.           break;
  428.         case 'echeck-cleared':
  429.           $new_status = (defined('MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID') ? MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID : 2);
  430.           break;
  431.         case ($txn_type=='express-checkout-cleared' || substr($txn_type,0,8) == 'cleared-'):
  432.           //express-checkout-cleared
  433.           $new_status = ($isECtransaction && defined('MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID') ? MODULE_PAYMENT_PAYPALWPP_ORDER_STATUS_ID : MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID);
  434.           if ((int)$new_status == 0) $new_status = 2;
  435.           break;
  436.         case 'pending-auth':
  437.           // pending authorization
  438.           $new_status = ($isECtransaction ? MODULE_PAYMENT_PAYPALWPP_REFUNDED_STATUS_ID : MODULE_PAYMENT_PAYPAL_REFUND_ORDER_STATUS_ID);
  439.           break;
  440.         case (substr($txn_type,0,7) == 'denied-'):
  441.           // denied for any other reason - treat as pending for now
  442.         case (substr($txn_type,0,8) == 'pending-'):
  443.           // pending anything
  444.           $new_status = ($isECtransaction ? MODULE_PAYMENT_PAYPALWPP_ORDER_PENDING_STATUS_ID : MODULE_PAYMENT_PAYPAL_PROCESSING_STATUS_ID);
  445.           break;
  446.       }
  447.       // update order status history with new information
  448.       ipn_debug_email('IPN NOTICE :: Set new status ' . $new_status . " for order ID = " .  $ordersID . ($_POST['pending_reason'] != '' ? '.   Reason_code = ' . $_POST['pending_reason'] : '') );
  449.       if ((int)$new_status == 0) $new_status = 1;
  450.       if (in_array($_POST['payment_status'], array('Refunded', 'Reversed', 'Denied', 'Failed'))
  451.            || substr($txn_type,0,8) == 'cleared-' || $txn_type=='echeck-cleared' || $txn_type == 'express-checkout-cleared') {
  452.         ipn_update_orders_status_and_history($ordersID, $new_status, $txn_type);
  453.         $zco_notifier->notify('NOTIFY_PAYPALIPN_STATUS_HISTORY_UPDATE', array($ordersID, $new_status, $txn_type));
  454.       }
  455.       break;
  456.     default:
  457.       // can't understand result found. Thus, logging and aborting.
  458.       ipn_debug_email('IPN WARNING :: Could not process for txn type: ' . $txn_type . "\n" . ' postdata=' . str_replace('&', " \n&", urldecode(print_r($_POST, TRUE))));
  459.   }
  460.   // debug info only
  461.   switch (TRUE) {
  462.     case ($txn_type == 'pending-echeck' && (int)$ordersID > 0):
  463.       ipn_debug_email('IPN NOTICE :: Pending echeck transaction for existing order. No action required. Waiting for echeck to clear.');
  464.       break;
  465.     case ($txn_type == 'pending-multicurrency' && (int)$ordersID > 0):
  466.       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.');
  467.       break;
  468.     case ($txn_type == 'pending-address' && (int)$ordersID > 0):
  469.       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.');
  470.       break;
  471.     case ($txn_type == 'pending-paymentreview' && (int)$ordersID > 0):
  472.       ipn_debug_email('IPN NOTICE :: "Pending payment review" transaction for existing order. No action required. Waiting for PayPal to complete their Payment Review. Do not ship order until review is completed.');
  473.       break;
  474.   }
  475. }
  476.  


cron