Jump to content

Paypal IPN error


Guest

Recommended Posts

Hi,

Firstly, Ive followed:

http://www.cubecart.com/site/forums/lofive...php/t15202.html

To fix the problem and it still is throwing up:

Sorry, your order failed!



You can attempt to purchase your basket contents again below:

Try Again




I have added the log directory which says:


[2006/Aug/24, 5:19:35] 

[2006/Aug/24, 5:19:35] Using PDT to check order status for tx:6K571960W01814235

[2006/Aug/24, 5:19:35] Payment Failed, Paypal response follows:

[2006/Aug/24, 5:19:35] FAIL

Error: 4003




I followed, line by line the tutorial. Got the Token Code + the log directory, but its still saying sorry. I tried updating to the latest version of CC but still the same.



My code: (hidden secure buts with #~#~#~#~#~#)




<?php

/*

+--------------------------------------------------------------------------

|   CubeCart v3.0.11

|   ========================================

|   by Alistair Brookbanks

|	CubeCart is a Trade Mark of Devellion Limited

|   Copyright Devellion Limited 2005 - 2006. All rights reserved.

|   Devellion Limited,

|   22 Thomas Heskin Court,

|   Station Road,

|   Bishops Stortford,

|   HERTFORDSHIRE.

|   CM23 3EE

|   UNITED KINGDOM

|   http://www.devellion.com

|	UK Private Limited Company No. 5323904

|   ========================================

|   Web: http://www.cubecart.com

|   Date: Thursday, 27th July 2006

|   Email: sales (at) cubecart (dot) com

|	License Type: CubeCart is NOT Open Source Software and Limitations Apply 

|   Licence Info: http://www.cubecart.com/site/faq/license.php

+--------------------------------------------------------------------------

|	confirmed.inc.php

|   ========================================

|	Order Confirmation

+--------------------------------------------------------------------------

*/



if (ereg(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || ereg(".inc.php",$_SERVER['PHP_SELF'])) {

	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";

	exit;

}



require_once("classes/cart.php");

$cart = new cart();



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

// Added by paypal auto return fix

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

$logflag = TRUE;

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

// End

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



$basket = $cart->cartContents($ccUserData[0]['basket']);



// WORK OUT IS THE ORDER WAS SUCCESSFULL OR NOT;)



// 1. Include gateway file



// Override basket value as fix for some gateways

if(isset($_GET['pg']) && !empty($_GET['pg'])){

	

	$pg = base64_decode($_GET['pg']);

	

	if(ereg("Authorize|WorldPay|Protx|SECPay|BluePay|mals-e",$pg)){

		$basket['gateway'] = $pg;

	}



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

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

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

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

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

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

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



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

// Added by paypal auto return fix

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

$module = fetchDbConfig("PayPal");

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

// End

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



} elseif(!isset($basket['gateway'])){

	echo "Error: No payment gateway variable is set!";

	exit;

}

include("modules/gateway/".$basket['gateway']."/transfer.inc.php");



// 2. Include function which returns ture or false

$success = success();



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

// Added by paypal auto return fix

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

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

{

	$success = pdtcheck();

}

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

// End

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



$confirmation = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/confirmed.tpl");



	$confirmation->assign("LANG_CONFIRMATION_SCREEN",$lang['front']['confirmed']['confirmation_screen']);

	

	$confirmation->assign("LANG_CART",$lang['front']['confirmed']['cart']);

	$confirmation->assign("LANG_ADDRESS",$lang['front']['confirmed']['address']);

	$confirmation->assign("LANG_PAYMENT",$lang['front']['confirmed']['payment']);

	$confirmation->assign("LANG_COMPLETE",$lang['front']['confirmed']['complete']);

	

	if($success == TRUE){

		

		if($stateUpdate == TRUE){

				$cart_order_id = $basket['cart_order_id'];

				include_once("includes/orderSuccess.inc.php");

		}

		

		$confirmation->assign("LANG_ORDER_SUCCESSFUL",$lang['front']['confirmed']['order_success']);

		

		// add affilate tracking code/module

		$affiliateModule = $db->select("SELECT status, folder, `default` FROM ".$glob['dbprefix']."CubeCart_Modules WHERE module='affiliate' AND status = 1");

	

		if($affiliateModule == TRUE) {

		

			for($i=0; $i<count($affiliateModule); $i++){

			

				if($affiliateModule[$i]['status']==1){

					

						include("modules/affiliate/".$affiliateModule[$i]['folder']."/tracker.inc.php");

						// VARS AVAILABLE

						// Order Id Number $basket['cart_order_id']

						// Order Total $order[0]['prod_total']

						$confirmation->assign("AFFILIATE_IMG_TRACK",$affCode);

						$confirmation->parse("confirmation.session_true.order_success.aff_track");

				

				}

			

			}

		

		}

		

		$confirmation->parse("confirmation.session_true.order_success");

		

		// empty basket & other session data

		$basket = $cart->unsetVar("conts");

		$basket = $cart->unsetVar("delInf");

		$basket = $cart->unsetVar("cart_order_id");

		$basket = $cart->unsetVar("shipCost");

		$basket = $cart->unsetVar("subTotal");

		$basket = $cart->unsetVar("tax");

		$basket = $cart->unsetVar("shipCost");

		$basket = $cart->unsetVar("grandTotal");

		$basket = $cart->unsetVar("customer_comments");

		$basket = $cart->unsetVar("counted");

		$basket = $cart->unsetVar("shipMethod");

		$basket = $cart->unsetVar("invArray");

		$basket = $cart->unsetVar("shipKey");

		$basket = $cart->unsetVar("gateway");

		$basket = $cart->unsetVar("currentStep");

		$basket = $cart->unsetVar("stepLimit");



		

	} else {

		

		$confirmation->assign("LANG_ORDER_FAILED",$lang['front']['confirmed']['order_fail']);

		$confirmation->assign("LANG_ORDER_RETRY",$lang['front']['confirmed']['try_again_desc']);

		$confirmation->assign("LANG_RETRY_BUTTON",$lang['front']['confirmed']['try_again']);

		$confirmation->parse("confirmation.session_true.order_failed");

	}

	

	$confirmation->assign("LANG_LOGIN_REQUIRED",$lang['front']['confirmed']['request_login']);

	

	if($ccUserData[0]['customer_id']>0) $confirmation->parse("confirmation.session_true");

	

	else $confirmation->parse("confirmation.session_false");

	

	$confirmation->parse("confirmation");

	

$page_content = $confirmation->text("confirmation");



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

// 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 = "[b]#~#~#~#~#~#[/b]";

	$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.sandbox.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 = "[b]/#~#~#~#~#~#/[/b]".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

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



?>

If you spot anything that I have missed please let me know.

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