Jump to content


Photo

getting 'Premature end' error message for IPN


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

#1 paullam71

paullam71

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 19 March 2003 - 01:46 PM

HI. I am new to paypal and IPN so I am hoping someone can help. All is working until I click continue and it tries to execute the script. Here is the script the error in the error log is 'Premature end of script headers' Not sure what that means. Anyone? Please help. Thanks!

#!/usr/bin/perl
############################################################
# Process IPN
############################################################
# 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','http://www.paypal.com/cgi-bin/webscr';
# note: if you have SSL encryption Enabled, use <https://www.paypal.c...cgi-bin/webscr> above
$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'};
$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";

paullam71

#2 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 19 March 2003 - 02:23 PM

The sample code needs to be modified into a functioning script.

Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn

#3 paullam71

paullam71

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 19 March 2003 - 02:28 PM

OK.....since I am very new to perl can someone help or point me in the right direction of making this work?

paullam71

#4 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 24 March 2003 - 03:49 PM

See: http://www.paypal.co...ns-code-outside

Patrick Breitenbach
PayPal, Inc.
Dev Net: https://www.paypal.com/pdn




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users