Forum Moderators: coopster
Everything works fine in Production (I'm able to see the variables posted in the Paypal checkout page -> amount, item name, shipping, etc). But if I try to test in the Sandbox, I always end up at the "Please login to Developer Central" even if I'm logged in (I click on that link, and I'm already logged in).
I guess this has something to do with using fsockopen() and then outputting the HTML response from the browser.
Has anyone else tried this? Is there some sort of session code that has to happen? I'm new to HTTP but an old hat to PHP and what not.
Here's a snippet of code that opens the connection and outputs the HTML response:
//open socket to [sandbox.paypal.com...]
$socket = fsockopen($host,80,$errno,$errstr,30);
//just some error code
if (!$socket)
{
$result["errno"] = $errno; $result["errstr"] = $errstr;
return $result;
}
//$reqheader is the string of "hidden" vars I'm posting to the Paypal checkout page (amount, mc_gross, cmd, etc)
fputs($socket, $reqheader);
//get server result into array
while(!feof($socket))
{
$result[] = fgets($socket, 4096);
}
//close connection
fclose($socket);
//iterate through array, find element where html output starts by examining content type of header
for($i=0;$i< count($result); $i++)
{
if(strstr($result[$i], "Content-Type: text/html;")!= FALSE)
{
$counter = $i + 1;
break;
}
} //end foreach()
//start at counter where html output starts and echo output to page
while($counter < count($result))
{
echo $result[$counter];$counter++;
}
This code I believe is very valuable to users like me who have a 3rd party shopping cart where the users can potentially "hang out" during the checkout process where product availability can be compromised if you don't check one last time before leaving Paypal (i.e. I do a product inventory check and insert my temporary order right before calling the fsockopen and redirecting the user to Paypal checkout -> results in cleaner inventory and less temporary orders).
Like I said, this code works perfectly for Production Paypal so what am I missing from a Sandbox standpoint for the server to recognize that I AM logged in?