tdavis has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for help in fixing my script that will be used for integration with Paypal, specifically, the IPN (instant payment notification) script. My scripts works, except for one thing. I am supposed to acknowledge their repsonse, and I am using example code from one of the Paypal forums. My scripts runs OK, but the POST is apparently not working. I am looking for either specific help with the following, or some general knowledge of this concerning paypal IPN. Thanks!!! T.Davis

Replies are listed 'Best First'.
Re: Question about LWP::UserAgent
by Old_Gray_Bear (Bishop) on Dec 20, 2004 at 16:36 UTC
    Since you are asking for 'specific help', you do need to post the failing code fragment so we can all have sonething to be specific about.

    ----
    I Go Back to Sleep, Now.

    OGB

      Yes, you are right. Here is the suspect code:
      read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); $query .= '&cmd=_notify-validate'; # post back to PayPal system to validate use LWP::UserAgent; $ua = new LWP::UserAgent; $req = new HTTP::Request 'POST','http://www.paypal.com/cgi-bin/webscr' +; $req->content_type('application/x-www-form-urlencoded'); $req->content($query); $res = $ua->request($req);
      Everything else works OK. I am sending the buyer an email, the seller an email, and writing a record to a sales header file, and record(s) to a sales detail file. All of that works. The log records no errors. Thanks for your help! T.Davis
Re: Question about LWP::UserAgent
by jk2addict (Chaplain) on Dec 20, 2004 at 18:50 UTC
Re: Question about LWP::UserAgent
by bradcathey (Prior) on Dec 20, 2004 at 18:19 UTC

    Though I have not worked directly with Paypal, here is a chunk of code I use in working with one of the bigger gateways, FWIW:

    use HTTP::Request::Common; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = POST 'http://www.somegateway.com/cgi-bin/somedir', [ somevariable1 => 'foo', somevariable2 => 'bar', ]; my $reply; my $response = $ua->request($req); if ($response->is_success) { $reply = $response->content; } else { print STDERR $response->status_line, "\n"; } ...do something with $reply...

    Usually there are parameters that I send (like credit card info) and then I get a reponse code that I parse (such as 'approved', 'declined').


    —Brad
    "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton