#!/usr/bin/perl
$mailprog = '/usr/sbin/sendmail';
# read the post from PayPal system and add 'cmd'
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$query = $ENV{'QUERY_STRING'};
}
else {
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
}
# 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 . '&cmd=_notify-validate');
$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
$receiver_email = $variable{'receiver_email'};
$item_name = $variable{'item_name'};
open(MAIL,"|$mailprog -t");
print MAIL "To: vwaytech\@yahoo.com\n";
print MAIL "Cc: $variable{'receiver_email'}\n";
print MAIL "From: vwaytech\@yahoo.com\n";
print MAIL "Subject: Test: $item_name\n\n";
print MAIL localtime() . "\n\n";
print MAIL "$query\n\n";
print "Content-Type: text/html\n\n";
print "<html><body>" . localtime() . "<p>";
print "$query\n\n<p>";
if ($res->is_error) {
print MAIL "HTTP ERROR\n\n";
print "HTTP ERROR<p></body></html>";
}
elsif ($res->content eq 'VERIFIED') {
print MAIL "VERIFIED\n\n";
print "VERIFIED<p></body></html>";
}
elsif ($res->content eq 'INVALID') {
print MAIL "INVALID\n\n";
print "INVALID<p></body></html>";
}
else {
print MAIL "ERROR\n\n";
print "ERROR<p></body></html>";
}
close(MAIL);
Patrick Breitenbach
PayPal, Inc.
Dev Net:
https://www.paypal.com/pdn