Jump to content

Recommended Posts

It's fairly straightforward to submit to paypal with a GET. Something like:

 

$data = http_build_query($fields);

 

$final_url = $url . "?" . $data;

header( 'Location: $final_url');

 

Takes you to paypal where you can put in credit card info and pay.

BTW $url = https://www.sandbox.paypal.com/cgi-bin/webscr and

$fields is an assoc array with customer contact and purchase information. cmd needs to be _cart.

 

The problem is GET has a size limit that's not huge. It would be better to use POST. It has to be possible since forms do it all the time. Does anyone know how to do this programmatically? In other words, how do you set up the header info as a post and zip someone off to paypal? I have found a few things on the net but nothing actually works. Any help would be REAL help.

That's a good idea but there are problems. The default user agent from curl tells paypal the request came from a script. I suppose I could pass the visitors user agent. But that's not all.

 

Here is some code I adapted (stole) from the php.net site:

 

$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";

$data = http_build_query($fields);

 

$alternate_opts = array(

  'http'=>array(

    'method'=>"POST",

    'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .

              "Content-length: " . strlen($data),

    'content'=>$data

  )

);

 

$alternate = stream_context_create($alternate_opts);

 

readfile($url, false, $alternate);

 

This got me to the login to the sand box page. Since I was already logged in I'm guessing paypal is not seeing the login cookie. Assuming the code I swiped is bulletproof and I didn't mess something up.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.