Hello,
I'm attempting to set up the facility to enable people to purchase downloads from my site, I have found this may be possible with my PayPAl account using IPN (Instant Payment Notification).
However when clicking there link to supply me with example PERL code I was shown this
Now I'm no PERL expert as you all know but even to me this looks like invalid (non-compliant) code. where is the 'use strict', where are the variable definitions (our,my etc..) the STDIN is being arbitarily read without passing it through CGI or validation, surely this cant be right.
Any chance someone can help me re-write this correctly, will passing it through CGI to get value pairs effect the way this works?
All help is appreciated, as I don't want to plough ahead until i'm sure I have valid and strong paypal PERL code.
Regards
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
I'm attempting to set up the facility to enable people to purchase downloads from my site, I have found this may be possible with my PayPAl account using IPN (Instant Payment Notification).
However when clicking there link to supply me with example PERL code I was shown this
Code:
#!/usr/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','[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);
$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
$item_name = $variable{'item_name'};
$item_number = $variable{'item_number'};
$payment_status = $variable{'payment_status'};
$payment_amount = $variable{'mc_gross'};
$payment_currency = $variable{'mc_currency'};
$txn_id = $variable{'txn_id'};
$receiver_email = $variable{'receiver_email'};
$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 your Primary PayPal email
# check that $payment_amount/$payment_currency are correct
# process payment
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
}
else {
# error
}
print "content-type: text/plain\n\n";
Any chance someone can help me re-write this correctly, will passing it through CGI to get value pairs effect the way this works?
All help is appreciated, as I don't want to plough ahead until i'm sure I have valid and strong paypal PERL code.
Regards
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.