Jump to content

Call to a member function on a non-object in confirmed.inc.php, line 2


Guest jt007

Recommended Posts

Hi folks

I'm using CC 3.0.13 and Firefox as a development browser.

I'm getting near to 'finishing' the store - you can check it out at www.magicmagic.co.uk/store.

I've just gone through the pinned instructions for activating PayPal IPN and, although the first transaction came back saying it had failed (even though payment was processed) all since then SEEM to be working.

BUT...

Occasionally (particularly if I click the link from PayPal to return to the merchant, rather than waiting for it to get there itself) I am greeted with the error:

Fatal error: Call to a member function on a non-object in magicmagic.co.uk/store/includes/content/confirmed.inc.php on line 246

It does not happen every time. It seems to happen more often when I 'race' through the payment stage quickly. Any ideas?

I have included my confirmed.inc.php file below:

<?php

/*

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

| CubeCart v3.0.13

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

| 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: Tuesday, 17th October 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 (eregi(".inc.php",$HTTP_SERVER_VARS['PHP_SELF']) || eregi(".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 = preg_replace('/[^a-zA-Z0-9_\-\+]/', '',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");

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

// 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->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'];

$auth_token = "LzZqFwUSfjI2H5I3V58uVmm8LIMdeTzYNk-iBnXtHpleTx2Mj_hzl1WoX-O";

$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 ) )

{

$confirmation->assign("LANG_PAYMENT_GROSS", "success: ".$res);

return TRUE;

}

else

{

$confirmation->assign("LANG_PAYMENT_GROSS", "failure: ".$res);

return FALSE;

}

}

else

{

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

// logMsg ( $res );

$confirmation->assign("LANG_PAYMENT_GROSS", "Payment Failed, Paypal response follows: ".$res);

return FALSE;

}

}

fclose ($fp);

}

function logmsg( $msg )

{

global $logflag;

if ( $logflag == FALSE )

{

return;

}

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

$myFile = ".$/q09logz/".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

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

?>

Link to comment
Share on other sites

Despite of NON standard cubecart code (this forum unsuported) you cannot use following code in pdtcheck() function:

$confirmation->assign(.........

$confirmation is an unknown object in this function :)

I suggest you to use orriginal code posted in this forum a year ago (if you are NOT a php familar guy).

Link to comment
Share on other sites

Despite of NON standard cubecart code (this forum unsuported) you cannot use following code in pdtcheck() function:

$confirmation->assign(.........

$confirmation is an unknown object in this function :)

I suggest you to use orriginal code posted in this forum a year ago (if you are NOT a php familar guy).

THANKS!

I completely forgot about making changes to the confirmed.inc.php file. I took your advice, re-did the mod of the IPN fix, and all now seems to be working well :D

... Oh, as is pretty evident, I'm not really a PHP familiar guy :)

Now I just want to see if I can send greater product info to PayPal so the payment page is a bit more informative. Anyone ? ...

Cheers

John

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