Jump to content


Photo

LWP::UserAgent


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

#1 Guest2003

Guest2003

    Member

  • Members
  • PipPip
  • 15 posts

Posted 21 January 2003 - 04:34 PM

I am trying to write the IPN code for my website using the paypal sample code provided on the paypal website.

Is LWP::UserAgent a standard perl package. Do I need to make
any other changes to the code ?

I am just trying to send an e-mail back to me with the transaction
details or save some transaction info if the payment is verified.
i am using the notify_url in my payment button and i have changed
the profile at the paypal website to use ipn. does it take some
time to activate IPN. It is not working ?

The code i am using is as follows: It has some simple modifications
to the paypal code. Please let me know the solution.

Thanks.

###################
#!/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','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'};
$quantity = $variable{'quantity'};
$payment_date = $variable{'payment_date'};



if ($res->is_error) {
# HTTP error
open (OUTPUT, "> ipn_HtEr") || die "ipn_HtEr: $!\n";
print OUTPUT "$item_name:$payer_email:$item_number:\n";
close (OUTPUT);
}
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

open (OUTPUT, "> ipn_Spok") || die "ipn_Spok: $!\n";
print OUTPUT "$item_name:$payer_email:$item_number:\n";
close (OUTPUT);
#send info
&send_info;
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
open (OUTPUT, "> ipn_Ival") || die "ipn_Ival: $!\n";
print OUTPUT "$item_name:$payer_email:$item_number:\n";
close (OUTPUT);
}
else {
# error
open (OUTPUT, "> ipn_Er") || die "ipn_Er: $!\n";
print OUTPUT "$item_name:$payer_email:$item_number:\n";
close (OUTPUT);
}
print "content-type: text/plain\n\nOK\n";

sub send_pininfo { ......

}



#2 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 21 January 2003 - 07:11 PM

LWP::UserAgent is fairly common but not standard. You might try running a script like PerlDiver on your server to confirm LWP::UserAgent's presence.

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

#3 DSD_David

DSD_David

    Junior Member

  • Members
  • 125 posts

Posted 23 January 2003 - 01:03 PM

Hey,

Let me just suggest that you make sure that when you declare the email address, you need a '\' in front of the @ in your email. i.e. Judge\@joebrown.com. I've seen it before in other Perl PayPal scripts. So, check it out.

-David

#4 mike0323

mike0323

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 27 January 2003 - 08:05 PM

I know my server doesn't have LWP now, and there is no certainty they will add it. Is there something I can substitute for LWP, or work around this?

#5 paypal_pb

paypal_pb

    Advanced Member

  • Members
  • 2,960 posts

Posted 30 January 2003 - 05:56 PM

There is no substitute. It's possible to skip the step that requires LWP which opens up a very tiny hole where someone could gain access without paying.

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

#6 Guest2003

Guest2003

    Member

  • Members
  • PipPip
  • 15 posts

Posted 03 February 2003 - 04:29 PM

Hi,

I have verified that LWP:UserAgent is installed.
The script has a slight modification to the one
provided by paypal (I am using above script to just
writes some data received to the disk if IPN works.

The error I am geeting in the error log is :

Can't locate object method "above" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 4) line 1.

Please let me know what the above error means.

Thanks.


#7 Guest2003

Guest2003

    Member

  • Members
  • PipPip
  • 15 posts

Posted 06 February 2003 - 01:04 AM

Never mind. Figured it out.
LWP::UserAgent is installed on the server
and the IPN WORKS !!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users