NYCPHP Meetup

NYPHP.org

[nycphp-talk] Posting data to PayPal from a script using sockets

William E. Fisher wefisher at open-world.com
Thu Jun 10 13:01:47 EDT 2004


Dear Susan, Jose, Joel:

Thank you for your fast and intelligent replies.

Jose, I have been trying to avoid using curl (which I have never used and
don't really understand), but I'll give it a try if it comes to that.

Joel, I'm still working through your links.

I'm unavailable for a few days but I'll respond again on Monday.

(Meanwhile, if anyone has any specific comments about using sockets, I would
still be interested in learning more about what I must have left out of my
code (below).)

Thanks, and cheers,

Bill


----- Original Message ----- 
From: "Joel De Gan" <joel at tagword.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Wednesday, June 09, 2004 8:26 PM
Subject: Re: [nycphp-talk] Posting data to PayPal from a script using sockets


> I wrote a tutorial on this for zend.com:
> here: http://www.zend.com/zend/tut/tutorial-paypal.php
> or plaintext: http://www.zend.com/zend/tut/tutorial-paypal.php?print=1
>
> Or for "sending" money through paypal.. here:
> http://lucifer.intercosmos.net/?view=SNIP&item=52
>
> I also did http://ipn.joihost.com which is an IPN logger/reposter and is
> listed on the official Paypal website under IPN logging services. It
> really does not do a lot of traffic right now, so if you needed pieces
> let me know.
>
> Cheers
> -joel
>
> On Wed, 2004-06-09 at 15:35, William E. Fisher wrote:
> > Here is a question from someone (me) who is in way over his head.
> >
> > I am in search of some help in posting form variables to a third party
> > server from a script. The third party server is PayPal (sandbox) and
> > the post would be the initial variables that are needed to initiate an
> > IPN transaction.
> >
> > I am trying sockets to connect to the paypal server. I had some
> > success but not yet a complete transaction.
> >
> > The following code is able to open a socket on the sandbox server and
> > write the post header and data to the server. And I am able to get and
> > read a response from the the sandbox server.
> >
> > However, I am not able to complete the transaction.
> >
> > Despite being logged into developer central, I receive the message "To
> > access the PayPal Sandbox, please log in to PayPal Developer Central.
> > " rather than the payment details page. No activity is recorded in the
> > seller's account, and my ipn script at the notify_url is not hit.
> >
> > Is someone familiar enough with either using sockets or using paypal
> > that he/she might be able to provide some direction or a solution?
> >
> > Any help will be much, much, much appreciated.
> >
> > Thank you.
> >
> > Bill
> > Here is the code:
> > //First I define the variables as key/value pairs in an
> > //array called $PayPal_Vars
> >
> > //Next we need to provide the parameters for the
> > //fsockopen() and fputs() functions
> > foreach ($PayPal_Vars as $key => $value)
> > {
> >     $value = stripslashes($value);
> >     $value = urlencode($value);
> >     if (!$req)
> >     {
> >         $req .= "$key=$value";
> >     }
> >     else
> >     {
> >         $req .= "&";
> >         $req .= "$key=$value";
> >     }
> >     $req .= "\r\n\r\n";
> > }
> >
> > $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
> > $header .= "Host: www.sandbox.paypal.com\r\n";
> > $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
> > $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
> >
> >
> > //Finally we need to script the call to the PayPal server
> > //and the posting of the data
> > if ($PayPal_Vars[test_ipn] == 1)
> > {
> >     $fp = fsockopen ("www.sandbox.paypal.com", 80, $errno, $errstr,
> > 30);
> > }
> > else
> > {
> >     $fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);
> > }
> >
> > if (!$fp)
> > {
> >     return "ERROR";
> > }
> > else
> > {
> >     $fout = fputs ($fp, $header . $req);
> >     echo "<br>fout = $fout";
> >
> >     $tmp_headers = "";
> >     while ($str = trim(fgets($fp, 4096)))
> >     {
> >         $tmp_headers .= $str."\n";
> >     }
> >     $tmp_body = "";
> >     while ($str = trim(fgets($fp, 4096)))
> >     {
> >         $tmp_body .= $str."\n";
> >     }
> >
> >     fclose($fp);
> > }
> >
> >
> > ______________________________________________________________________
> > _______________________________________________
> > talk mailing list
> > talk at lists.nyphp.org
> > http://lists.nyphp.org/mailman/listinfo/talk
> -- 
> joeldg - developer, Intercosmos media group.
> http://lucifer.intercosmos.net
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk





More information about the talk mailing list