views:

47

answers:

2

THE BACKGROUND DETAILS:

I have a custom shopping cart that uses PayPal for payment processing. I have an intermediary page between the cart and PayPal that adds the order to a database and sends confirmation emails.

Until now, I had the intermediary page set up to include all the necessary data as hidden form fields and submit the form to PayPal onload.

Now I'm experimenting with using cURL in PHP to send the POST data to PayPal.

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
//curl_setopt($ch, CURLOPT_URL, 'http://localhost/postecho.php');

   // ^ this one is a simple page that echoes all POST data using print_r

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $poststring);

// Some options that didn't seem to help
//curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);

// User agent spoofing which also didn't seem to help
//$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
//curl_setopt($ch, CURLOPT_USERAGENT, $agent);

$result=curl_exec($ch);
curl_close($ch);

$poststring contains all the POST data that I had previously been passing in param1=value&param2=value format. Running this through test page postecho.php reveals that POST data seems to be alright.

THE PROBLEM:

"Sorry — your last action could not be completed"

This is what PayPal tells me when I try to do things the cURL way. It doesn't really give me any helpful information concerning the resolution of this problem. I figure there's gotta be something in the headers or something that it doesn't like. How do I make PayPal and cURL work together?

+1  A: 

most likely you are missing cookie/session data. if i were you i would capture the raw http message that goes from your browser to paypal.com. some of it's info isn't going to be needed for the request to work, but at least it's going to contain all info you need. then try to emulate it with curl.

long answer short: first capture raw http message, then emulate it with curl.

kgb
I really shouldn't have posted this just as I was getting ready to leave work. I'll get back to you on this. +1 for a great suggestion though.
DLH
A: 

Have you checked the API docs for PHP?

https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/library_code

Byron Whitlock
DLH