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

Hello Monks!

Do any of you have any experience with PayPal's IPN?

If so, can you please answer me this question....

In there example Perl Script to use, it ends this way:
print "content-type: text/plain\n\nOK\n";

Do I just leave that? OR do I have it parse all the information, after it verifies payment from PayPal, then if there is an error, do I have the script PRINT the error?

Or since this is posted from PayPal, where the customer cannot see it, do I just leave the code above?


Thank you Monks, for any wisdom you may share in this regard!

thx,
Richard

Replies are listed 'Best First'.
Re: PayPal IPN and Perl
by poj (Abbot) on Jan 02, 2003 at 13:09 UTC
    Are you referring to this script from http://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/pp-solutions-ipn-outside ?.
    PERL (requires LWP::UserAgent SSL encryption requires Crypt::SSLeay) #!/usr/local/bin/perl # read post from PayPal system and add 'cmd' 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' +; # note: if you have SSL encryption Enabled, use <https://www.paypal.com/cgi-bin/webscr> above $req->content_type('application/x-www-form-urlencoded'); $req->content($query); $res = $ua->request($req); # split posted variables into pairs @pairs = split(/&/, $query); $count = 0; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $variable{$name} = $value; $count++; } # assign posted variables to local variables # note: additional IPN variables also available -- see IPN documentati +on $item_name = $variable{'item_name'}; $receiver_email = $variable{'receiver_email'}; $item_number = $variable{'item_number'}; $invoice = $variable{'invoice'}; $payment_status = $variable{'payment_status'}; $payment_gross = $variable{'payment_gross'}; $txn_id = $variable{'txn_id'}; $payer_email = $variable{'payer_email'}; if ($res->is_error) { # HTTP error } elsif ($res->content eq 'VERIFIED') { # check the payment_status=Completed # check that txn_id has not been previously processed # check that receiver_email is an email address in your PayPal account # process payment } elsif ($res->content eq 'INVALID') { # log for manual investigation } else { # error } print "content-type: text/plain\n\nOK\n";
    From reading the IPN manual and watching the demo it looks to me like this script does several things.
    1. It receives form data from IPN with details of the purchase
    2. It posts back a validation to IPN using LWP::UserAgent
    3. It receives back from the IPN server the response to the post which is captured in $res. This will have the word VERIFIED or INVALID in it
    The idea then is that you use this response to update your records usually your own sales database. The # comments are suggestion on code you need write. The ->is_error method tells you if the response is good and you can proceed to check whether the response is VERIFIED or INVALID.
    The last line I guess is just to keep the IPN server happy with a response.
    So after all that, the question is "Do you want to keep your own records of the transactions that have been made ?". If No, then use the script as it is.
    If Yes, then maybe take look at this site http://gotany.com/cgi/paypalipn.html for some more ideas.
    poj
Re: PayPal IPN and Perl
by fokat (Deacon) on Jan 02, 2003 at 17:50 UTC

    Well, apart from other answers, by all means please consider to use CGI;. Most likely this will shrink the size of the script you need to parse the IPN query / response and make it more robust.

    Happy new year to all monks!

    -lem, but some call me fokat
Re: PayPal IPN and Perl
by initself (Monk) on Sep 12, 2006 at 21:50 UTC
    Try out the Business::PayPal::IPN module. Make sure you read my annotations in AnnoCPAN. To save you the trouble, after retrieving all of the IPN information from the Paypal servers, you are going to need to send them a response to let them know that all is well:
    print $ipn->cgi->header('text/plain');
    Business::PayPal::IPN doesn't make that entirely clear.