Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PAYPAL IPN RETURNS TO EMPTY CART ON SUCCESS?


seanpatrick

Recommended Posts

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!

Link to comment
Share on other sites

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/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Link to comment
Share on other sites

  • 1 month later...

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?

Link to comment
Share on other sites

"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/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Link to comment
Share on other sites

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

 

it is ipn.php in catalog folder.

 

Satish

Ask/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Link to comment
Share on other sites

  • 2 weeks later...

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??

Link to comment
Share on other sites

  • 1 year later...

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');
?>

Link to comment
Share on other sites

  • 11 months later...

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...