|
Rank: Starting Member
Groups: Registered
Joined: 2/11/2004 Posts: 5 Location: ,
|
I have created the following perl program using the paypal example:
#!/usr/local/bin/perl
# more header stuff not shown
$pfile=$datapath."paypal.log";
$oline="PAYPALCK TOP $nicedate $nicetime";
open PFILE, ">>$pfile";
print PFILE "$oline $br \n";
close PFILE;
$query="";
$lockok = 0;
$lockuser = "";
$lockmeth = "lock";
$lockfile = "lockpay.pal";
&tiptop;
exit;
sub tiptop
{
# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
&makeit;
$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);
}
sub makeit
{
# 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
$receiver_email = $variable{'receiver_email'};
$item_name = $variable{'item_name'};
$item_number = $variable{'item_number'};
$custom = $variable{'custom'};
$payment_status = $variable{'payment_status'};
$payment_date = $variable{'payment_date'};
$payment_gross = $variable{'mc_gross'};
$mc_fee = $variable{'mc_fee'};
$txn_id = $variable{'txn_id'};
$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'};
$payer_email = $variable{'payer_email'};
$newline="$nicedate\t$nicetime\t$receiver_email\t$item_name\t$item_number\t$custom\t$payment_status\t$payment_date\t$mc_gross\t$mc_fee\t$txn_id\t$first_name\t$last_name\t$address_street\t$address_city\t$address_state\t$address_zip\t$address_country\t$payer_email";
$lockuser=$payer_email;
if (length($lockuser)<5)
{ $lockuser=$msgto;
}
# NEW PALFORM
if ($res->is_error)
{ $newline="ERROR".$newline;
} elsif ($res->content eq 'INVALID')
{ $newline="INVALID".$newline;
}
$valcnt=1;
if ($res->content eq 'VERIFIED')
{
# check the payment_status=Completed
if ($payment_status eq "Completed")
{ $valcnt=2;
# check that txn_id has not been previously processed
# someday write the code to open the file, search for txn etc.
$valcnt=3;
# check that receiver_email is your Primary PayPal email
$rm=$receiver_email;
if (index($allaccts, $rm)>-1)
{ $valcnt=4;
}
}
}
$newline=$valcnt.$newline;
# process payment (LOG EVERYTHING)
# &lockdb;
open OFILE, ">>$pfile";
print OFILE "$newline\n";
close OFILE;
# &unlockdb;
&sendmsg
}
and everytime a payment comes in I get nothing...
zero..
so I wonder HOW do we test this LOOP or does someone have to buy $1.00 items and we pay PayPal so I can make this go around and around and test it?
eduhosting.org
free websites for teachers
|
|
Rank: Starting Member
Groups: Registered
Joined: 12/21/2002 Posts: 17 Location: ,
|
Hello, You can test your script using this free tool: http://www.eliteweaver.co.uk/testing/ipntest.php
Just make sure you change the https://www.paypal.com/cgi-bin/webscr
URL to http://www.eliteweaver.co.uk/testing/ipntest.php
when testing. If your script works fine with this tool but doesn't with PayPal, try changing https://www.paypal.com/cgi-bin/webscr
to http://www.paypal.com/cgi-bin/webscr
(note that https:// becomes http:// ...) Hope this helps! Regards, Klemen Stirn YOURsoft affiliate software http://www.yoursoft-tm.com
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/13/2004 Posts: 109 Location: ,
|
If you would like to test your script with the live PayPal system, you may want to change the price of some items to $0.01 and buy them from yourself for purposes of testing. But no matter if you are paying a dollar or a penny, when you are done with your testing you can refund the payments and any PayPal fees will also be refunded.
I like to keep two PayPal accounts, one personal and one business, so I can buy with the personal from the business for testing purposes. At the end of the day I just log in to the business account and refund each payment.
Dave Burchell PayPal Technical Support PayPal, an eBay company
|