Jump to content

Paypal Order Failed on return to cube cart FIX !!!!�


Guest foto-time

Recommended Posts

Guest estelle

I highly advise using IPN.

THIS is how you fix any issues with PayPal IPN at your store:

http://www.cubecartforums.org/docs/CubeCar...d-with-ipn.html

@SibeSpace - If using my module there is a known bug in it, the fix is explained within the forum thread. Or you can just use the standard PayPal module and follow the instructions at the link I just mentioned.

Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

I have customers who have occasionally complained about the 'order failed' error, but the order does go through and the status does get set to 'processing' and an a CubeCart confirmation email is sent to the customer too.

With this fix resolve this? I'm thinking the problem I am seeing is a timing issue too.

Link to comment
Share on other sites

Guest estelle

@aris1234 - Thats a timing issue and can't be fixed (as far as I know). Sometimes the customer will get back to your store before PayPal has notified the store about the successful payment.

Link to comment
Share on other sites

  • 3 weeks later...
  • 5 weeks later...

FINALLY! After hours following these and other tutorials, it was still NOT working. And it was just a simple thing - check it if you're using a brand-new Paypal account (as I was):

- Your Paypal email MUST be verified! If it is not, it WON'T work!

Registered in this forum just to give this simple hint.

Cheers!

Link to comment
Share on other sites

  • 4 weeks later...
Guest Under the Mooch

If this has been a problem since 2006, why wasn't it fixed on any subsequent versions of Cube Cart? Furthermore, has it been fixed on version 4? I'm using the version 3.0.19 to determine if my web store will be lucrative enough to justify purchasing version 4, but I've spent the day trying to fix a simple problem that's existed for three years! It doesn't leave me with much faith in the program.

Link to comment
Share on other sites

  • 4 weeks later...
Guest cathyg

Hi

I have having this same problem but it is with Direct payments Paypal pro - does nayone know if this fix works with that?

Thanks in advance

Cathy x

Link to comment
Share on other sites

  • 1 month later...

As Estelle says - this seems to be due to paypal not notifying the store before the customer gets back the store.

I'm wondering if it might be a good idea to put a 10 or 15 second delay at the beginning of 'confirmed.php' to give Paypal a chance to update the cart.

Does anyone know the best way to achieve this?

Would this be OK?

<?php

// sleep for 10 seconds

sleep(10);

?>

Link to comment
Share on other sites

Guest christy12345

As Estelle says - this seems to be due to paypal not notifying the store before the customer gets back the store.

I'm wondering if it might be a good idea to put a 10 or 15 second delay at the beginning of 'confirmed.php' to give Paypal a chance to update the cart.

Does anyone know the best way to achieve this?

Would this be OK?

<?php

// sleep for 10 seconds

sleep(10);

?>

I have now re installed cube cart 4 times now, tried endless attempts at fixing the papal issues, it works ok for a while and then it just goes tits up...i get the "order has failed" i get the screen where the totals dont add up, including the one attached.....why has this been released? i have spent the last week going through the hundreds of posts regarding this an other issues, is it not possible to release a working version? i have gone grey haired trying to sort what should be a pretty simple thing.....

Link to comment
Share on other sites

Guest jiu-chan

mine doesn't have the confirmed.php

i don't have it at all

is there somewhere i can dl it or something?

or someone give me the codes that i can copy and paste and save as confirmed.php

Link to comment
Share on other sites

Hi guys,

I am using CubeCart Version: 3.0.20, I went through this helpful thread and was able to fix all the errors I was previously getting, now I get re-directed to the shop after doing the 0.01 test transaction, and see the

"Sorry, your order failed!

You can attempt to purchase your basket contents again below"

The transaction happens , however the IPN doesn't seem to work as pointed earlier in this discussion by some one, coz the order in the store admin remains on pending and never moves to processing.

Here's the log file:

"[2009/Dec/13, 4:32:47]

[2009/Dec/13, 4:32:47] Using PDT to check order status for tx:2xxxxxxxxxxxxxxxN

[2009/Dec/13, 4:32:49] Verify Failed, Paypal response follows:

[2009/Dec/13, 4:32:49] Amount =

[2009/Dec/13, 4:32:49] Invoice = 091213-043137-4573

[2009/Dec/13, 4:32:49] Receiver Email = [email protected]

[2009/Dec/13, 5:05:43]

[2009/Dec/13, 5:05:43] Using PDT to check order status for tx:2xxxxxxxxxxxxxxxxF

[2009/Dec/13, 5:05:45] Verify Failed, Paypal response follows:

[2009/Dec/13, 5:05:45] Amount =

[2009/Dec/13, 5:05:45] Invoice = 091213-050403-7449

[2009/Dec/13, 5:05:45] Receiver Email = [email protected]

[2009/Dec/13, 5:30:45]

[2009/Dec/13, 5:30:45] Using PDT to check order status for tx:8xxxxxxxxxxxxxxxxT

[2009/Dec/13, 5:30:47] Verify Failed, Paypal response follows:

[2009/Dec/13, 5:30:47] Amount =

[2009/Dec/13, 5:30:47] Invoice = 091213-052946-4894

[2009/Dec/13, 5:30:47] Receiver Email = [email protected]

[2009/Dec/13, 5:38:39]

[2009/Dec/13, 5:38:39] Using PDT to check order status for tx:7xxxxxxxxxxxxxxxx8

[2009/Dec/13, 5:38:40] Verify Failed, Paypal response follows:

[2009/Dec/13, 5:38:40] Amount =

[2009/Dec/13, 5:38:40] Invoice = 091213-053708-2439

[2009/Dec/13, 5:38:40] Receiver Email = [email protected]

Can anyone point out what I am doing wrong ?

Cheers,

Link to comment
Share on other sites

  • 3 months later...
Guest sheister

Hello, Thanks for your fix it seems to have resolved issues that I have posted about regarding returning customers keep getting the same order #. I am having a problem on the return page it gives me an error "failed to open stream: No such file or directory" , this is for the log directory that you stated to just make a directory in your store and give it a cryptic name. I did this and updated the confirmed.inc file. But I have a novices question that if answered will resolve this. Oh and I did give that log directory listing full 777 permissions.

Here is the line as to where to add the new log location.

$today = date("Y-M-d");

$myFile = "/ add log location here/".date("Y-M-d").".log";

$fh = fopen($myFile, 'a') or die("can't open file");

should i just put the folder name here or do i put the direct URL I.E. www.mystore/cart/log_directory

I tried just adding the folder name inside the root folder of my store and it gives me the error message. I also tried adding the direct URL and still received the error. Can you help with this??

One last thing. When I check the order in the Admin/Orders screen the order even though it was paid still shows pending.

Thanks for posting this great fix. Up to this point my post for assistance has gone unanswered so finding this was a great relief.

Regards

As many of you paypal standard/IPN users, I have experienced the same infamous "your oder failed" error when customer is redirected back to my store. The root cause i found out is the timming - sometimes paypal calls IPN.php after paypal redirects customer to the confirmed.php. Another problem is, if customer pay it via echeck, even if ipn.php is called first, the order status will still be pending, thus customer will see "your order failed" too.

Long story in short, I have found a solution for it.

Here is how to:

you only need to modify confirmed.inc.php in includes/content directory.

find:

$cart = new cart();




after that, add:




///////////////////////////

// Added by paypal auto return fix

///////////////////////////

$logflag = TRUE;

///////////////////////////

// End

///////////////////////////




find:




################################################################################

############

// Following lines added for Sir William's PayPal AutoReturn Fix

} elseif(isset($_GET['tx']) && isset($_GET['st'])) {

 $basket['gateway'] = "PayPal";

################################################################################

############




after that, add:




///////////////////////////

// Added by paypal auto return fix

///////////////////////////

$module = fetchDbConfig("PayPal");

///////////////////////////

// End

///////////////////////////






find:




$success = success();




after that, add:




///////////////////////////

// Added by paypal auto return fix

///////////////////////////

if ( ( $success == FALSE ) && (isset($_GET['tx']) && isset($_GET['st'])) )

{

	$success = pdtcheck();

}

////////////////////////////////

// End

////////////////////////////////




finally, add the following 2 methods at the end of the file (just before the 
?>
):




////////////////////////////////

// Added by paypal auto return fix

////////////////////////////////

function pdtcheck()

{

	global $db, $glob, $module, $basket;

	// read the post from PayPal system and add 'cmd'

	$req = 'cmd=_notify-synch';



	$tx_token = $_GET['tx'];

	logMsg( "" );

	logMsg( "Using PDT to check order status for tx:".$tx_token );

	$auth_token = "this is provied by paypal - check your paypal PDT config";

	$req .= "&tx=$tx_token&at=$auth_token";



	// post back to PayPal system to validate

	$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";

	$header .= "Content-Type: application/x-www-form-urlencoded\r\n";

	$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

	$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

	// If possible, securely post back to paypal using HTTPS

	// Your PHP server will need to be SSL enabled

	// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);



	if (!$fp)

	{

		// HTTP ERROR

		logMsg ("HTTP ERROR");

	}

	else

	{

		fputs ($fp, $header . $req);

		// read the body data

		$res = '';

		$headerdone = false;

		while (!feof($fp))

		{

			$line = fgets ($fp, 1024);

				if (strcmp($line, "\r\n") == 0)

				{

					// read the header

					$headerdone = true;

				}

				else if ($headerdone)

				{

					// header has been read. now read the contents

					$res .= $line;

				}

		}



		// parse the data

		$lines = explode("\n", $res);

		$keyarray = array();

		if (strcmp ($lines[0], "SUCCESS") == 0)

		{

			for ($i=1; $i<count($lines);$i++)

			{

				list($key,$val) = explode("=", $lines[$i]);

				$keyarray[urldecode($key)] = urldecode($val);

			}



			/**

			 * Check invoie, amount and receiver_email are correct

			 */

			$amount = $keyarray['payment_gross'];

			$invoiceId = $keyarray['invoice'];

			$receiver_email = $keyarray['receiver_email'];

			$sqlstat = "SELECT * FROM ".$glob['dbprefix']."CubeCart_order_sum WHERE cart_order_id = ".$db->mySQLSafe($invoiceId);

			$result = $db->select( $sqlstat );

			if ( ($result[0]['prod_total'] == $amount ) && ( strcmp( $module['email'], $receiver_email ) == 0 ) )

			{

				logMsg ("Verify Success");

				return TRUE;

			}

			else

			{

				logMsg ( "Verify Failed, Paypal response follows:" );

				logMsg ( "		Amount = " . $amount );

			  logMsg ( "	   Invoice = " . $invoiceId );

			  logMsg ( "Receiver Email = " . $receiver_email );

				return FALSE;

			}

		}

		else

		{

			logMsg ( "Payment Failed, Paypal response follows:" );

			logMsg ( $res );

			return FALSE;

		}

	}

	fclose ($fp);

}



function logmsg( $msg )

{

	global $logflag;

	if ( $logflag == FALSE )

	{

		return;

	}

	$today = date("Y-M-d");

	$myFile = "/location for my log files/".date("Y-M-d").".log";

	$fh = fopen($myFile, 'a') or die("can't open file");

	$stringData = date("[Y/M/d, G:i:s] ").$msg."\n";

	fwrite($fh, $stringData);

	fclose($fh);

}

////////////////////////////////

// End

////////////////////////////////






Let me explain how it works:



when user is transferred back to the confirmed.php, success() method is called first.  If IPN is called first, and if the status becomes "process", success() will return TRUE, then the payment is successful.



If IPN is not called yet, or customer sent an echeck, the status is pending, success() returns FALSE, then checkPDT() is called.



checkPDT() sends a request to paypal server with tx id received when paypal calls confirmed.php, then paypal sends back the transcation details, including invoice number, totoal amount and more.  So, in checkPDT() method, we do a db query, by using the invoice id, amount received from paypal and check wheter they matches, if everything is ok, return TRUE, otherwise, return FALSE.



If you add the above two methods to your file, make sure to replace the auth_token with the ones provided by paypal.  Also, you need to change the log location.  You can just create a directoy inside your store, give it a wired name, such as 
.$ba_ufdkj

, and give it a 777. The reason for a wired name is, people cannot guess it. oh, also password protect the log directory...it will block all http accesses.

I hope this helps :-)

now i can get to work on the rest of the site WAHOO!

sorry if this is off topic but this needs to be pinned so people can get a fix quickley without going round in circles

Link to comment
Share on other sites

Guest sheister

Hello again , I am disappointed that no body had posted in response to this common problem in a while. At first this fix seemed to have resolved my issues but after further trials , I still got the order failed, no payment gateway set, or Unable to open data stream errors. Tried every way imaginable way to edit the log file location as instructed in the replies to this thread with no success. I am thankful for the effort of posting this fix but I have to offer some kind criticism that the instructions of just how to modify the log location in the file were very unspecific and never fully explained for us non coders. Be that as it may, I still tried every logical way and none ever worked. I since removed the modified confirmed.inc.php file and went back to orig and still got order failed upon return. About to give up, I went to Estelles mod store because I learned they sell paypal gateway mods there and hoped that somehow this may correct these issues. In the description to one of her free paypal mods there was a file containing instructions as to how to correctly set up IPN. Gave it a go and all was fixed just that easy. Got order success upon cart return, basket was empty, and future orders generate unique order #. Orders showed up in cart as processing not pending. I have done this twice in a row with success both times. Though on the second attempt the return gave the dreaded Sorry your order failed message, I refreshed the screen and it changed to Order Success. So it seems there may be some lag between Paypal and cube cart.

If your having the same issues as others in this thread, you may want to try the instructions in this link to correctly set up your IPN. You can thank Estelle for posting these instructions for free and consider her great mod service. I have purchased 3 mods and am extremely happy with them.

Heres the Link

http://cubecart.expandingbrain.com/free/Pa..._by_Estelle.txt

Hello, Thanks for your fix it seems to have resolved issues that I have posted about regarding returning customers keep getting the same order #. I am having a problem on the return page it gives me an error "failed to open stream: No such file or directory" , this is for the log directory that you stated to just make a directory in your store and give it a cryptic name. I did this and updated the confirmed.inc file. But I have a novices question that if answered will resolve this. Oh and I did give that log directory listing full 777 permissions.

Here is the line as to where to add the new log location.

$today = date("Y-M-d");

$myFile = "/ add log location here/".date("Y-M-d").".log";

$fh = fopen($myFile, 'a') or die("can't open file");

should i just put the folder name here or do i put the direct URL I.E. www.mystore/cart/log_directory

I tried just adding the folder name inside the root folder of my store and it gives me the error message. I also tried adding the direct URL and still received the error. Can you help with this??

One last thing. When I check the order in the Admin/Orders screen the order even though it was paid still shows pending.

Thanks for posting this great fix. Up to this point my post for assistance has gone unanswered so finding this was a great relief.

Regards

As many of you paypal standard/IPN users, I have experienced the same infamous "your oder failed" error when customer is redirected back to my store. The root cause i found out is the timming - sometimes paypal calls IPN.php after paypal redirects customer to the confirmed.php. Another problem is, if customer pay it via echeck, even if ipn.php is called first, the order status will still be pending, thus customer will see "your order failed" too.

Long story in short, I have found a solution for it.

Here is how to:

you only need to modify confirmed.inc.php in includes/content directory.

find:

$cart = new cart();




after that, add:




///////////////////////////

// Added by paypal auto return fix

///////////////////////////

$logflag = TRUE;

///////////////////////////

// End

///////////////////////////




find:




################################################################################

############

// Following lines added for Sir William's PayPal AutoReturn Fix

} elseif(isset($_GET['tx']) && isset($_GET['st'])) {

 $basket['gateway'] = "PayPal";

################################################################################

############




after that, add:




///////////////////////////

// Added by paypal auto return fix

///////////////////////////

$module = fetchDbConfig("PayPal");

///////////////////////////

// End

///////////////////////////






find:




$success = success();




after that, add:




///////////////////////////

// Added by paypal auto return fix

///////////////////////////

if ( ( $success == FALSE ) && (isset($_GET['tx']) && isset($_GET['st'])) )

{

	$success = pdtcheck();

}

////////////////////////////////

// End

////////////////////////////////




finally, add the following 2 methods at the end of the file (just before the 
?>
):




////////////////////////////////

// Added by paypal auto return fix

////////////////////////////////

function pdtcheck()

{

	global $db, $glob, $module, $basket;

	// read the post from PayPal system and add 'cmd'

	$req = 'cmd=_notify-synch';



	$tx_token = $_GET['tx'];

	logMsg( "" );

	logMsg( "Using PDT to check order status for tx:".$tx_token );

	$auth_token = "this is provied by paypal - check your paypal PDT config";

	$req .= "&tx=$tx_token&at=$auth_token";



	// post back to PayPal system to validate

	$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";

	$header .= "Content-Type: application/x-www-form-urlencoded\r\n";

	$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

	$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

	// If possible, securely post back to paypal using HTTPS

	// Your PHP server will need to be SSL enabled

	// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);



	if (!$fp)

	{

		// HTTP ERROR

		logMsg ("HTTP ERROR");

	}

	else

	{

		fputs ($fp, $header . $req);

		// read the body data

		$res = '';

		$headerdone = false;

		while (!feof($fp))

		{

			$line = fgets ($fp, 1024);

				if (strcmp($line, "\r\n") == 0)

				{

					// read the header

					$headerdone = true;

				}

				else if ($headerdone)

				{

					// header has been read. now read the contents

					$res .= $line;

				}

		}



		// parse the data

		$lines = explode("\n", $res);

		$keyarray = array();

		if (strcmp ($lines[0], "SUCCESS") == 0)

		{

			for ($i=1; $i<count($lines);$i++)

			{

				list($key,$val) = explode("=", $lines[$i]);

				$keyarray[urldecode($key)] = urldecode($val);

			}



			/**

			 * Check invoie, amount and receiver_email are correct

			 */

			$amount = $keyarray['payment_gross'];

			$invoiceId = $keyarray['invoice'];

			$receiver_email = $keyarray['receiver_email'];

			$sqlstat = "SELECT * FROM ".$glob['dbprefix']."CubeCart_order_sum WHERE cart_order_id = ".$db->mySQLSafe($invoiceId);

			$result = $db->select( $sqlstat );

			if ( ($result[0]['prod_total'] == $amount ) && ( strcmp( $module['email'], $receiver_email ) == 0 ) )

			{

				logMsg ("Verify Success");

				return TRUE;

			}

			else

			{

				logMsg ( "Verify Failed, Paypal response follows:" );

				logMsg ( "		Amount = " . $amount );

			  logMsg ( "	   Invoice = " . $invoiceId );

			  logMsg ( "Receiver Email = " . $receiver_email );

				return FALSE;

			}

		}

		else

		{

			logMsg ( "Payment Failed, Paypal response follows:" );

			logMsg ( $res );

			return FALSE;

		}

	}

	fclose ($fp);

}



function logmsg( $msg )

{

	global $logflag;

	if ( $logflag == FALSE )

	{

		return;

	}

	$today = date("Y-M-d");

	$myFile = "/location for my log files/".date("Y-M-d").".log";

	$fh = fopen($myFile, 'a') or die("can't open file");

	$stringData = date("[Y/M/d, G:i:s] ").$msg."\n";

	fwrite($fh, $stringData);

	fclose($fh);

}

////////////////////////////////

// End

////////////////////////////////






Let me explain how it works:



when user is transferred back to the confirmed.php, success() method is called first.  If IPN is called first, and if the status becomes "process", success() will return TRUE, then the payment is successful.



If IPN is not called yet, or customer sent an echeck, the status is pending, success() returns FALSE, then checkPDT() is called.



checkPDT() sends a request to paypal server with tx id received when paypal calls confirmed.php, then paypal sends back the transcation details, including invoice number, totoal amount and more.  So, in checkPDT() method, we do a db query, by using the invoice id, amount received from paypal and check wheter they matches, if everything is ok, return TRUE, otherwise, return FALSE.



If you add the above two methods to your file, make sure to replace the auth_token with the ones provided by paypal.  Also, you need to change the log location.  You can just create a directoy inside your store, give it a wired name, such as 
.$ba_ufdkj

, and give it a 777. The reason for a wired name is, people cannot guess it. oh, also password protect the log directory...it will block all http accesses.

I hope this helps :-)

now i can get to work on the rest of the site WAHOO!

sorry if this is off topic but this needs to be pinned so people can get a fix quickley without going round in circles

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