Hi. I'm trying to write a validation script for PayPal processing. I am getting a weird error though, related to HTTP::Headers. My code is;
eval {
use strict;
use lib '/home/virtual/site2/fst/var/www/cgi-bin/links/admin';
use Links qw/$IN $DB $CFG $USER/;
use GT::SQL;
use Links::SiteHTML;
use Links::Plugins;
use HTTP::Headers;
use HTTP::Request;
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
};
if ($@) { print "Content-type: text/html \n\n"; print "ERROR: $@"; exit; }
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/home/virtual/site2/fst/var/www/cgi-bin/links/admin');
Links::init_user();
# set all the 'my's up...
my ($query,$ua, $req, $res, @pairs, $count,$pair,$name,$value,$variable,$name,$count,%variable, $user_links);
# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
# get everything into a hash...
my $in = $IN->get_hash;
# Grab everything from $IN...
$query = join '&', map { "$_=@{ [ $IN->param($_) ] }" } ($IN->param());
# Here we are reading any parameters passed from paypal and sending back a request to validate it.
$query .= '&cmd=_notify-validate';
$ua = new LWP::UserAgent( agent => 'AcePPC/1.0', timeout => 30 );
$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);
# assign posted variables to local variables
# note: additional IPN variables also available -- see IPN documentation
my $item_name = $in->{'item_name'};
my $receiver_email = $in->{'receiver_email'};
my $item_number = $in->{'item_number'};
my $invoice = $in->{'invoice'};
my $payment_status = $in->{'payment_status'};
my $payment_gross = $in->{'payment_gross'};
my $txn_id = $in->{'txn_id'};
my $payer_email = $in->{'payer_email'};
# decide if the purchase made is valid or not :)
if ($res->is_error) {
&error("Error: " . $res->error);
} elsif ($res->content eq 'VERIFIED') {
&set_cookie($item_name);
} elsif ($res->content eq 'INVALID') {
&error("You don't seem to have been correctly referred to this site");
} else {
print $res->content;
&error("INVALID CODE RETURNED");
}
#############
# set a cookie, which can then be used at a later time via add.cgi (to show the actual add form)
sub set_cookie {
if ($_[0] =~ /platinum/i) {
my $cookie = $IN->cookie( -name => 'ADDTYPE', -value => "platinum" );
print $IN->header( -cookie => $cookie );
} elsif ($_[0] =~ /gold/i) {
my $cookie = $IN->cookie( -name => 'ADDTYPE', -value => "gold" );
print $IN->header( -cookie => $cookie );
} else {
&error("Invalid link type selected....");
}
my $url = "http://www.domain.com/cgi-bin/links/add.cgi";
print $IN->redirect($url);
}
##############
# in case we have problems,we got this sub!
sub error {
my $error = shift;
print $IN->header();
print Links::SiteHTML::display('error', { error => $error });
exit;
}
......and the error is;
Can't locate object method "error" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 17) line 1.
Please enable debugging in setup for more details.
Stack Trace
======================================
Links (30647): Links::environment called at /home/virtual/site2/fst/var/www/cgi-bin/links/admin/Links.pm line 431 with no arguments.
Links (30647): Links::fatal called at (eval 17) line 1 with arguments
(Can't locate object method "error" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 17) line 1.
).
Links (30647): HTTP::Message::__ANON__ called at paypal.cgi line 69 with arguments
(HTTP::Response=HASH(0x8533bcc)).
Anyone got any ideas?
I've been racking my head on this for a couple of days now...
TIA
Andy (mod)
andy@ultranerds.co.uk
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Code:
#!/usr/bin/perl eval {
use strict;
use lib '/home/virtual/site2/fst/var/www/cgi-bin/links/admin';
use Links qw/$IN $DB $CFG $USER/;
use GT::SQL;
use Links::SiteHTML;
use Links::Plugins;
use HTTP::Headers;
use HTTP::Request;
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
};
if ($@) { print "Content-type: text/html \n\n"; print "ERROR: $@"; exit; }
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/home/virtual/site2/fst/var/www/cgi-bin/links/admin');
Links::init_user();
# set all the 'my's up...
my ($query,$ua, $req, $res, @pairs, $count,$pair,$name,$value,$variable,$name,$count,%variable, $user_links);
# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
# get everything into a hash...
my $in = $IN->get_hash;
# Grab everything from $IN...
$query = join '&', map { "$_=@{ [ $IN->param($_) ] }" } ($IN->param());
# Here we are reading any parameters passed from paypal and sending back a request to validate it.
$query .= '&cmd=_notify-validate';
$ua = new LWP::UserAgent( agent => 'AcePPC/1.0', timeout => 30 );
$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);
# assign posted variables to local variables
# note: additional IPN variables also available -- see IPN documentation
my $item_name = $in->{'item_name'};
my $receiver_email = $in->{'receiver_email'};
my $item_number = $in->{'item_number'};
my $invoice = $in->{'invoice'};
my $payment_status = $in->{'payment_status'};
my $payment_gross = $in->{'payment_gross'};
my $txn_id = $in->{'txn_id'};
my $payer_email = $in->{'payer_email'};
# decide if the purchase made is valid or not :)
if ($res->is_error) {
&error("Error: " . $res->error);
} elsif ($res->content eq 'VERIFIED') {
&set_cookie($item_name);
} elsif ($res->content eq 'INVALID') {
&error("You don't seem to have been correctly referred to this site");
} else {
print $res->content;
&error("INVALID CODE RETURNED");
}
#############
# set a cookie, which can then be used at a later time via add.cgi (to show the actual add form)
sub set_cookie {
if ($_[0] =~ /platinum/i) {
my $cookie = $IN->cookie( -name => 'ADDTYPE', -value => "platinum" );
print $IN->header( -cookie => $cookie );
} elsif ($_[0] =~ /gold/i) {
my $cookie = $IN->cookie( -name => 'ADDTYPE', -value => "gold" );
print $IN->header( -cookie => $cookie );
} else {
&error("Invalid link type selected....");
}
my $url = "http://www.domain.com/cgi-bin/links/add.cgi";
print $IN->redirect($url);
}
##############
# in case we have problems,we got this sub!
sub error {
my $error = shift;
print $IN->header();
print Links::SiteHTML::display('error', { error => $error });
exit;
}
......and the error is;
Quote:
A fatal error has occured: Can't locate object method "error" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 17) line 1.
Please enable debugging in setup for more details.
Stack Trace
======================================
Links (30647): Links::environment called at /home/virtual/site2/fst/var/www/cgi-bin/links/admin/Links.pm line 431 with no arguments.
Links (30647): Links::fatal called at (eval 17) line 1 with arguments
(Can't locate object method "error" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 17) line 1.
).
Links (30647): HTTP::Message::__ANON__ called at paypal.cgi line 69 with arguments
(HTTP::Response=HASH(0x8533bcc)).
Anyone got any ideas?
TIA
Andy (mod)
andy@ultranerds.co.uk
IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

