Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Google IPN

Status
Not open for further replies.

learntogoogle

Programmer
Nov 25, 2005
2
US
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?

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";
 
I can't see how this would even compile. You've got "use strict" but you're refering to %variable on many lines without ever having declared it, which would trigger a fatal compile-time exception. Is this actually the code you are trying?

Use strict in your code (and not just your post) would highlight the problem with %variable never having been declared, let alone initialised.

You say it prints "good". Because it doesn't first print "error" or "1", your code is going down one of the two other branches of the big if statement, both of which do nothing because they're simply comments.

What exactly do you expect this code to do that it isn't doing?

Yours,

fish

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top