Jump to content


Photo

Perl newbie needing IPN help


  • This topic is locked This topic is locked
No replies to this topic

#1 angeljs

angeljs

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 04 April 2011 - 01:50 PM

Okay, I have a perl IPN script, and I don't know anything at all about Perl, so I can't figure out why the IPN isn't working. This is part of the IPN script:

# 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-bin/webscr';
$req->content_type('application/x-www-form-urlencoded');
$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'};
$user = $variable{'custom'};
$invoice = $variable{'invoice'};
$payment_status = $variable{'payment_status'};
$mc_gross = $variable{'mc_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

and here is the return code:

#!/usr/bin/perl

# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});

# 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
$receiver_email = $variable{'receiver_email'};
$item_name = $variable{'item_name'};
$item_number = $variable{'item_number'};
$quantity = $variable{'quantity'};
$invoice = $variable{'invoice'};
$custom = $variable{'custom'};
$option_name1 = $variable{'option_name1'};
$option_selection1 = $variable{'option_selection1'};
$option_name2 = $variable{'option_name2'};
$option_selection2 = $variable{'option_selection2'};
$num_cart_items = $variable{'num_cart_items'};
$payment_status = $variable{'payment_status'};
$pending_reason = $variable{'pending_reason'};
$payment_date = $variable{'payment_date'};
$settle_amount = $variable{'settle_amount'};
$settle_currency = $variable{'settle_currency'};
$exchange_rate = $variable{'exchange_rate'};
$mc_gross = $variable{'mc_gross'};
$mc_fee = $variable{'mc_fee'};
$mc_currency = $variable{'mc_currency'};
$txn_id = $variable{'txn_id'};
$txn_type = $variable{'txn_type'};
$first_name = $variable{'first_name'};
$last_name = $variable{'last_name'};
$address_street = $variable{'address_street'};
$address_city = $variable{'address_city'};
$address_state = $variable{'address_state'};
$address_zip = $variable{'address_zip'};
$address_country = $variable{'address_country'};
$address_status = $variable{'address_status'};
$payer_email = $variable{'payer_email'};
$payer_id = $variable{'payer_id'};
$payer_status = $variable{'payer_status'};
$payment_type = $variable{'payment_type'};
$notify_version = $variable{'notify_version'};
$verify_sign = $variable{'verify_sign'};
$payment_gross = $variable{'payment_gross'};
$payment_fee = $variable{'payment_fee'};

$user = ucfirst(lc($custom));

print "content-type: text/plain\n\n";

if ($payment_status eq "Completed") {

print "<html>
<head>

<title>Auction Payment Received</title>

</head>
<body>

$user, your payment has been received.<br><br>

You made a payment in the amount of: \$$mc_gross<br>
Transaction ID: $txn_id<br>

<br>

This payment may now be viewed in your auction account.<br><br>

<a href=http://$ENV{'HTTP_HOST'}/>Click here to go back to the auction site</a><br>

</body>
</html>";

}
else {

print "<html>
<head>

<title>Auction Payment Pending</title>

</head>
<body>

$user, your payment is pending.<br><br>

Your pending payment is in the amount of: \$$mc_gross<br>
Transaction ID: $txn_id<br>

<br>


This payment may be pending because it was made by a check, and it has not yet cleared.<br><br>

<a href=http://$ENV{'HTTP_HOST'}/>Click here to go back to the auction site</a><br>

</body>
</html>";

}

any help would be very much appreciated as the return always shows the payment as pending, and not completed. :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users