Jump to content


Corporate Sponsors


Latest News: (loading..)

PAYPAL IPN RETURNS TO EMPTY CART ON SUCCESS?


12 replies to this topic

#1 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 18 November 2009, 20:14

I am running Paypal IPN on an an MS2 OSC store. I have used the EXACT same code on the same host for another site successfully, but for some reason I am having a problem on this particular install.

When a customer pays via Paypal (my only option) and complete the transaction successful on Paypal.com, they are shown a "click to return to" button. When that button is clicked, they are momentarily sent to checkout_success.php but are redirected to shopping_cart.php with a "Your Shopping Cart is empty!" message displayed. On the administrative side of things, the order doesn't process completely and is set to Pending, not displaying the IPN data nor deducting the product from inventory (thus the main issue with this problem).

I've tried changing the Paypal Module settings from GET to POST to NO IPN with no difference in the problem. I've also hardcoded the checkout_success.php URL into modules/payment/paypal.php but nothing changed. It seems the session ID isn't being passed back correctly?

Any help would be greatly appreciated!

Also: can I bypass the "click to return to" button in Paypal with an auto-return? If so, where is that setting? In OSC I don't see it so it's in Paypal?

Thanks!

#2 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 20 November 2009, 00:41

Anyone?

#3 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 23 November 2009, 04:17

Help? Please?

#4 satish

  • Community Member
  • 5,315 posts
  • Real Name:Satish Mantri
  • Gender:Male
  • Location:Nagpur(India)

Posted 29 November 2009, 11:55

When a customer returns from paypal after payment if sesion id is lost (paypal post the session id and code needs to handle it for session creation) then this will happen.

Satish
Ask for osCommerce value addon suggestion tips for your site.
Check My About US For who am I and what My company does.


#5 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 01 December 2009, 04:49

View Postsatish, on 29 November 2009, 11:55, said:

When a customer returns from paypal after payment if sesion id is lost (paypal post the session id and code needs to handle it for session creation) then this will happen.

Satish

So how would I go about making sure it sends the session ID back to the store? Thanks Satish for the help!

#6 satish

  • Community Member
  • 5,315 posts
  • Real Name:Satish Mantri
  • Gender:Male
  • Location:Nagpur(India)

Posted 01 December 2009, 10:20

First thing is you make sure that 'Auto Return' is ON in your PayPal Merchant Account Profile.
So a customer does not have to click on return to site button.

Once that is achieved then You need to collect the post and get variables(probably once the auto return is fixed the error will be gone) and check which variable has session id.
Now thru code modification You start that session


Satish
Ask for osCommerce value addon suggestion tips for your site.
Check My About US For who am I and what My company does.


#7 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 12 January 2010, 03:42

Not sure if this is related, but I've noticed on stores that aren't handling IPN notifications properly I'm also seeing code like this added to URLs as customers browse the store:

&osCsid=1a29ba8806e70988ee729d3abe4d63e3

I've compared the settings under "Sessions" in the Admin between a store doing this and one that isn't and they're both set to "False" for every option... could this be the culprit?

#8 satish

  • Community Member
  • 5,315 posts
  • Real Name:Satish Mantri
  • Gender:Male
  • Location:Nagpur(India)

Posted 17 January 2010, 04:17

"click to return to" button. this should not be there if auto return is set to on.

IPN is not supposed to reach checkout_process.php it is to reach the notify url path.(provide link of the contribution used).


Satish
Ask for osCommerce value addon suggestion tips for your site.
Check My About US For who am I and what My company does.


#9 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 18 January 2010, 01:43

I have auto-return turned on, pointing to checkout_process.php. Is that correct?

I'm using PayPal Shopping Cart IPN v3.1.5. If you could tell me the IPN notification URL, I'd appreciate it.

Thanks!

#10 satish

  • Community Member
  • 5,315 posts
  • Real Name:Satish Mantri
  • Gender:Male
  • Location:Nagpur(India)

Posted 18 January 2010, 02:56

tep_draw_hidden_field('notify_url', tep_href_link(FILENAME_IPN, '', 'SSL',false)) .

it is ipn.php in catalog folder.

Satish
Ask for osCommerce value addon suggestion tips for your site.
Check My About US For who am I and what My company does.


#11 seanpatrick

  • Community Member
  • 82 posts
  • Real Name:Sean Patrick

Posted 27 January 2010, 07:04

I sandbox tested my ipn.php and it's giving a 500 Server Error message. If I test checkout_process.php (which Paypal told me should be used) it gives an "IPN Sent Successfully" message. I REALLY need to resolve this problem as it's now impacting two stores I've installed. Satish, could I give you access to one of them perhaps??

#12 fuzioneer

  • Community Member
  • 136 posts
  • Real Name:Dave
  • Gender:Male

Posted 01 February 2011, 19:56

got exact same issue with same contribution

did some debug work,

in domain logs i just get a simple die with error 500 ( "POST /ipn.php HTTP/1.0" 500 - "-" "-")


I then checked in ipn.php and it had this line in it

if($ipn->uniqueTxnID() && $ipn->isReversal() && strlen($ipn->key['parent_txn_id']) == 17) {

as far as i can tell from the ipn debug emails the parent_txn_id isn't passed, but txn_id is which is 17 chars in length

I have tried changing parent_txn_id to just txn_id but still get error 500.
I even commented out the two dienice function calls to present error 500s but still the same !

any pointers as to help diagnosing would be much appreciated. The orders are generated within the shop but stay as pending with no ipn info (IPN History database table is also empty)

I am receiving IPN info written to ipn.txt so the ipn info is returning back to the right place, but my debug lines to write lines to the ipn.txt log file always end with the last few lines of entry being

mc_currency = GBP
residence_country = GB
transaction_subject = 7430003d447414d424b093fc47ec9040
payment_gross = 
got here ok
and here
txn_id length = 17
txn_id = 9G932957ME342024V
this line 0

<?php
/*
  $Id: ipn.php,v 1.1.1.1 2004/09/22 13:45:11 devosc Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  DevosC, Developing open source Code
  http://www.devosc.com

  Copyright (c) 2003 osCommerce
  Copyright (c) 2004 DevosC.com

  Released under the GNU General Public License
*/


  function debugWriteFile($str,$mode="a") {
    $fp = @fopen("/home/admin/www/ipn.txt",$mode);  @flock($fp, LOCK_EX); @fwrite($fp,$str); @flock($fp, LOCK_UN); @fclose($fp);
  }

  $postString = ''; foreach($_POST as $key => $val) $postString .= $key.' = '.$val."\n";
  if($postString != '') {
  	debugWriteFile("\n\n");
    debugWriteFile($postString);
  }


  require_once('includes/modules/payment/paypal/application_top.inc.php');
  require_once(DIR_WS_MODULES . 'payment/paypal/classes/IPN/IPN.class.php');
  require_once(DIR_WS_MODULES . 'payment/paypal/classes/Debug/Debug.class.php');
  require_once(DIR_WS_MODULES . 'payment/paypal/functions/general.func.php');
  paypal_include_lng(DIR_WS_MODULES . 'payment/paypal/languages/', 'english', 'ipn.lng.php');
  $debug = new PayPal_Debug(MODULE_PAYMENT_PAYPAL_IPN_DEBUG_EMAIL, MODULE_PAYMENT_PAYPAL_IPN_DEBUG);
  $ipn = new PayPal_IPN($_POST);
  $ipn->setTestMode(MODULE_PAYMENT_PAYPAL_IPN_TEST_MODE);
  unset($_POST);
  //post back to PayPal to validate
//  if(!$ipn->authenticate(MODULE_PAYMENT_PAYPAL_DOMAIN) && $ipn->testMode('Off')) $ipn->dienice('500');
  //Check both the receiver_email and business ID fields match
	debugWriteFile("got here ok\n");
//  if (!$ipn->validateReceiverEmail(MODULE_PAYMENT_PAYPAL_ID,MODULE_PAYMENT_PAYPAL_BUSINESS_ID)) $ipn->dienice('500');
	debugWriteFile("and here\n");
	$lengthof = strlen($ipn->key['txn_id']);
	debugWriteFile("txn_id length = ". $lengthof . "\n");
	debugWriteFile("txn_id = ". $ipn->key['txn_id']. "\n");
	debugWriteFile("this line 0\n");
  if($ipn->uniqueTxnID() && $ipn->isReversal() && strlen($ipn->key['txn_id']) == 17) {
debugWriteFile("this line\n");
   //parent_txn_id is the txn_id of the original transaction
   $txn = $ipn->queryTxnID($ipn->key['txn_id']);
debugWriteFile("txid = ". $txn. "\n");
   if(!empty($txn)) {
      $ipn->insert($txn['paypal_id']);
      // update the order's status
      switch ($ipn->reversalType()) {
        case 'Canceled_Reversal':
          $order_status = MODULE_PAYMENT_PAYPAL_ORDER_STATUS_ID;
          break;
        case 'Reversed':
          $order_status = MODULE_PAYMENT_PAYPAL_ORDER_CANCELED_STATUS_ID;
          break;
        case 'Refunded':
          $order_status = MODULE_PAYMENT_PAYPAL_ORDER_REFUNDED_STATUS_ID;
          break;
      }
      $ipn->updateOrderStatus($txn['paypal_id'],$order_status);
    }
  } elseif ($ipn->isCartPayment() && !empty($PayPal_osC_Order->orderID)) {
  	debugWriteFile("this loop instead\n");
    //actually not essential since 'orders_status_name' is not required
    $languages_id = $PayPal_osC_Order->languageID;
    include(DIR_WS_CLASSES . 'order.php');
    debugWriteFile("this line 1\n");
    $order = new order($PayPal_osC_Order->orderID);
    //Check that txn_id has not been previously processed
    if ($ipn->uniqueTxnID()) { //Payment is either Completed, Pending or Failed
    	debugWriteFile("this line 2\n");
      $ipn->insert();
      $PayPal_osC_Order->setOrderPaymentID($ipn->ID());
      $PayPal_osC_Order->removeCustomersBasket($order->customer['id']);
      switch ($ipn->paymentStatus()) {
        case 'Completed':
          if ($ipn->validPayment($PayPal_osC_Order->payment_amount,$PayPal_osC_Order->payment_currency)) {
            include(DIR_WS_MODULES . 'payment/paypal/catalog/checkout_update.inc.php');
          } else {
            $ipn->updateOrderStatus($ipn->ID(),MODULE_PAYMENT_PAYPAL_ORDER_ONHOLD_STATUS_ID);
          }
          break;
        case 'Failed':
          $ipn->updateOrderStatus($ipn->ID(),MODULE_PAYMENT_PAYPAL_ORDER_CANCELED_STATUS_ID);
          break;
        case 'Pending':
          //Assumed to do nothing since the order is initially in a Pending ORDER Status
          break;
      }//end switch
    } else { // not a unique transaction => Pending Payment
    	debugWriteFile("this line 3\n");
      //Assumes there is only one previous IPN transaction
      $pendingTxn = $ipn->queryPendingStatus($ipn->txnID());
      if ($pendingTxn['payment_status'] === 'Pending') {
        $ipn->updateStatus($pendingTxn['paypal_id']);
        switch ($ipn->paymentStatus()) {
          case 'Completed':
           if ($ipn->validPayment($PayPal_osC_Order->payment_amount,$PayPal_osC_Order->payment_currency)) {
            include(DIR_WS_MODULES . 'payment/paypal/catalog/checkout_update.inc.php');
           } else {
            $ipn->updateOrderStatus($pendingTxn['paypal_id'],MODULE_PAYMENT_PAYPAL_ORDER_ONHOLD_STATUS_ID);
           }
           break;
          case 'Denied':
            $ipn->updateOrderStatus($pendingTxn['paypal_id'],MODULE_PAYMENT_PAYPAL_ORDER_CANCELED_STATUS_ID);
            break;
        }//end switch
      }//end if Pending Payment
    }
  } elseif ($ipn->isAuction()) {
    if ($ipn->uniqueTxnID()) $ipn->insert();
    if ($debug->enabled) $debug->add(PAYPAL_AUCTION,sprintf(PAYPAL_AUCTION_MSG));
  } elseif ($ipn->txnType('send_money')) {
    if ($ipn->uniqueTxnID()) $ipn->insert();
    if ($debug->enabled) $debug->add(PAYMENT_SEND_MONEY_DESCRIPTION,sprintf(PAYMENT_SEND_MONEY_DESCRIPTION_MSG,number_format($ipn->key['mc_gross'],2),$ipn->key['mc_currency']));
  } elseif ($debug->enabled && $ipn->testMode('On')) {
    $debug->raiseError(TEST_INCOMPLETE,sprintf(TEST_INCOMPLETE_MSG),true);
  }
  if ($ipn->testMode('On') &&  $ipn->validDigest()) {
    include(DIR_WS_MODULES . 'payment/paypal/classes/Page/Page.class.php');
    $page = new PayPal_Page();
    $page->setBaseDirectory(DIR_WS_MODULES . 'payment/paypal/');
    $page->setBaseURL(DIR_WS_MODULES . 'payment/paypal/');
    $page->includeLanguageFile('admin/languages','english','paypal.lng.php');
    $page->setTitle(HEADING_ITP_RESULTS_TITLE);
    $page->setContentFile(DIR_WS_MODULES . 'payment/paypal/admin/TestPanel/Results.inc.php');
    $page->addCSS($page->baseURL . 'templates/css/general.css');
    $page->addCSS($page->baseURL . 'templates/css/stylesheet.css');
    $page->setTemplate('default');
    include($page->template());
  }
  require(DIR_WS_MODULES . 'payment/paypal/application_bottom.inc.php');
?>


#13 ErichStauffer

  • Community Member
  • 2 posts

Posted 04 January 2012, 18:59

I fixed this issue by changing the HTTPS to "on" in the /includes/application_top.php file.

I had changed the HTTPS to "off" instead of "on". I found where I changed it in the /includes/application_top.php file and changed it back.

Paypal now redirects back to the shopping cart to allow the checkout process to continue.