NYCPHP Meetup

NYPHP.org

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

Joel De Gan joel at tagword.com
Wed Jun 9 20:26:26 EDT 2004


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




More information about the talk mailing list