Microsoft
Software
Hardware
Network
Question : PayPal IPN Stuff
Okay, here's the thing. I'm really not that good at perl programming, so if I can get a little help here I would really appreciate it. PayPal lets you set up a script on your site that processes information and sends nonsense back to their site. I get the basics of perl programming. I can store things in a database and print dynamic html files, but that's as far as I go. So I need some help in getting this script to work. I want to, obviously, process the stuff, but also send an email to the user with a custom message. This is the sample code they give:
#!/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','
https://www.paypal
.com/cgi-b
in/webscr'
;
$req->content_type('applic
ation/x-ww
w-form-url
encoded');
$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 documentation
$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";
...And the rest of the details are in the IPN section of the PayPal web site. Any any ANY help would be appreciated.
Thanks!
-Brian
Answer : PayPal IPN Stuff
Script is really straight forward with enough comments.
if ($res->is_error) {
#### When you come here that means, your script wasnt able to communicate with server. So write appropriate message like
print "Unable to communicate with Payment system.Please try again later.";
}
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
## Payment is verified. Check variable named $payment_status.
if($payment_status eq 'Completed')
{
show_success();
}
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
# print Something wrong related to payment.
print "Unable to process your request. Make sure your payment information is correct.";
}
else {
# error
print "Unable to process your payment. Try again later.";
}
sub show_success
{
#Display appropriate message.
#include code which can send mail.
}
print "content-type: text/plain\n\nOK\n";
That is it !!!
JD
Random Solutions
Adjust text leading/tracking Acrobat 6 Pro
Divide by Zero error in sql server
Choosing between Windows XP Pro and 2003 Server
Domino API - Need to get document Author
Ruby csv column sort
Microsoft, Exchange Standard & Outlook, 2003 (SP2), Unable to Open the free/busy information
Vista and CSA
How to disable NTLM in Windows 2003 server
Macros not working properly in Excel sheet
embed an Access report inside an email