learntogoogle
Programmer
I have not used Google's IPN before and I am sort of stuck. The code below is from paypal itself and it prints GOOD if I load it in my browser. I don't order anything and the script says GOOD when it's loaded.
Does anyone have experience with this and could give me a hand?
Does anyone have experience with this and could give me a hand?
Code:
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use warnings;
use strict;
use CGI qw/:standard/;
# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
my $query .= '&cmd=_notify-validate';
# post back to PayPal system to validate
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request 'POST','[URL unfurl="true"]http://www.paypal.com/cgi-bin/webscr';[/URL]
$req->content_type('application/x-[URL unfurl="true"]www-form-urlencoded');[/URL]
$req->content($query);
my $res = $ua->request($req);
my $item_name = $variable{'item_name'};
my $item_number = $variable{'item_number'};
my $payment_status = $variable{'payment_status'};
my $payment_amount = $variable{'mc_gross'};
my $payment_currency = $variable{'mc_currency'};
my $txn_id = $variable{'txn_id'};
my $receiver_email = $variable{'receiver_email'};
my $payer_email = $variable{'payer_email'};
print header, start_html();
if ($res->is_error) {
print "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 your Primary PayPal email
# check that $payment_amount/$payment_currency are correct
# process payment
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
}
else {
print "1";
}
print "good";