Forum Moderators: coopster

Message Too Old, No Replies

Simulating POST (fsockopen) for Paypal Checkout - Sandbox Login Issue

         

uask

2:39 pm on Nov 16, 2005 (gmt 0)

10+ Year Member



All,
I am using a script page on my site to "make a stop" at my site to check product availability one last time before going to the Paypal checkout page. It's basically a mimick of the same PHP code used to post back the IPN variables the my notify_url script.

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?

dreamcatcher

4:29 pm on Nov 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I assume you have logged in? Check the sandbox forums, you may see something there. I tend to find using sockets is never 100%. Try looking into the CURL options.

dc

uask

1:59 am on Nov 17, 2005 (gmt 0)

10+ Year Member



Yes, I have logged in. My old method of just a direct form POST works fine with the Sandbox. As for the PP Developer forums, I've found them useless for anything beyond basic coding.

Hvaen't gotten into cURL yet. Any tutorials you know of out there or reference guides?