IPN logs user out of my website

FrankHarris
Contributor
Contributor

As the title says when the user clicks on "return to merchant" they are logged out of my site. This is an issue since the return url does some processing not to mention its not what should be happening.   I DID have a working paypal IPN until maybe 2 months ago when this started to occur.
I have recreated the entire payment/ipn system and for a short time it seemed to be working correctly while I was testing, but now it is again back to logging users out of my site.  
I am verifying the payment in my IPN and it does result in "verified".  
The ipn seems to take a lot longer than it should but it does work as expected.
Paypal does return ($_POST['payment_status']=="Completed) along with payment details to my Return Page.

I am just logged out of my site.

 

Here is my current IPN which was adapted from the documentation here

<?php


chdir("../../"); /* It just makes life easier */

/* Includes */
require_once("includes/helpers.php");
require_once("includes/config.inc.php");
require_once("includes/functions.php");
require_once("includes/lib_remote.php");
require_once("includes/lang.php");
require_once("modules/config_games/server_config_parser.php");
$db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
$panel_settings	= $db->getSettings();
$debug =  $settings['debug'];
$paypal_email = $settings['paypal_email'];  // your paypal email address

if ( $settings['sandbox'] == 1) {
        $paypal_url = "www.sandbox.paypal.com/cgi-bin/webscr";
        $paypal_ipn_url = "ipnpb.sandbox.paypal.com";
}
else {
        $paypal_url = "www.paypal.com/cgi-bin/webscr";
        $paypal_ipn_url = "ipnpb.paypal.com";
}

// assign posted variables to local variables
$item_name = $_REQUEST['item_name'];
$item_number = $_REQUEST['item_number'];
$cart_id= $_REQUEST['item_number'];
$payment_status = $_REQUEST['payment_status'];
$payment_amount = $_REQUEST['mc_gross'];
$payment_currency = $_REQUEST['mc_currency'];
$txn_id = $_REQUEST['txn_id'];
$receiver_email = $_REQUEST['business'];
$payer_email = $_REQUEST['payer_email'];
$discount_amount = 0;




	$fpx = fopen('modules/billing/ipnlog.txt', 'a');
	$header = "====================== CART ID " . $cart_id . " ========================\n";
	fwrite($fpx, $header);
	
	$ipn_log .= $header;
	


// STEP 1: read POST data
// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
// Instead, read raw POST data from the input stream.
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
    $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if (function_exists('get_magic_quotes_gpc')) {
  $get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
  if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
    $value = urlencode(stripslashes($value));
  } else {
    $value = urlencode($value);
  }
  $req .= "&$key=$value";
  fwrite($fpx, "&$key=$value\n");

}

// Step 2: POST IPN data back to PayPal to validate
$ch = curl_init('https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
// In wamp-like environments that do not come bundled with root authority certificates,
// please download 'cacert.pem' from "https://curl.haxx.se/docs/caextract.html" and set
// the directory path of the certificate as shown below:
// curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
if ( !($res = curl_exec($ch)) ) {
  // error_log("Got " . curl_error($ch) . " when processing IPN data");
  curl_close($ch);
  exit;
}
curl_close($ch);


//----------------UPDATE DATABASES -----------------------------------------------
	
/*
The processIpn() method returned true if the IPN was "VERIFIED" and false if it
was "INVALID".
*/
if ($payment_status =="Completed") 
{
	
	$db->query("UPDATE OGP_DB_PREFIXbilling_carts
				  SET paid=1
				  WHERE cart_id=".$db->realEscapeSingle($cart_id));	
	
	
	
// SEND EMAIL HERE
}
// ---------------------------------------------------END DB UPDATES --------------------------------------------------
// inspect IPN validation result and act accordingly
if (strcmp ($res, "VERIFIED") == 0) {
		fwrite($fpx, "VERIFIED\n");

  // The IPN is verified, process it
} else if (strcmp ($res, "INVALID") == 0) {
  // IPN invalid, log for manual investigation
  	fwrite($fpx,"invalid\n");

}


	fclose($fpx);
?>



I have tried with both SSL and non-ssl pages .. just to test.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.