Hi,
I'm trying to integrate a paypal ipn and I got the Following error while PayPal is Calling my script here is the code
#!/usr/bin/perl
use strict;
use MyDB;
use warnings;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTPS ();
use Email::Simple ();
use Email::Simple::Creator ();
my $smtpserver = 'smtp.gmail.com';
my $smtpport = '587';
my $smtpuser = 'xxxxx@gmail.com';
my $smtppassword = 'yyyyyyyccccc';
my $transport = Email::Sender::Transport::SMTPS->new({
host => $smtpserver,
port => $smtpport,
ssl => "starttls",
sasl_username => $smtpuser,
sasl_password => $smtppassword,
});
#my $Just_Exit = 0; # if you need it
# Lots of servers will not resolve the IP to a host name
# So variable $ENV{'REMOTE_HOST'} will not have a value.
# If you want any security check if it is a PayPal IP.
#die('Does not match PayPal at IP:'.$ENV{'REMOTE_ADDR'})
# if ($ENV{'REMOTE_ADDR'} ne '173.0.82.66');
# comment the one your not using
my $PP_server = 'ipnpb.sandbox.paypal.com'; # sandbox IP:173.0.82.66
#my $PP_server = 'ipnpb.paypal.com'; # production IP:173.0.88.40
# It is highly recommended that you use version 6 upwards of
# the UserAgent module since it provides for tighter server
# certificate validation
use LWP::UserAgent 6;
# read post from PayPal system and add 'cmd'
use CGI qw(:standard);
my $cgi = CGI->new();
my $db = MyDB->new();
my $query = 'cmd=_notify-validate&';
$query .= join('&', map { $_.'='.$cgi->param($_) } $cgi->param());
# post back to PayPal system to validate
my $ua = LWP::UserAgent->new(ssl_opts => { keep_alive => 1, verify_hos
+tname => 1,SSL_version => 'SSLv23:!TLSv12' });
my $req = HTTP::Request->new('POST', 'https://'.$PP_server.'/cgi-bin/w
+ebscr');
$req->content_type('application/x-www-form-urlencoded');
$req->header(Host => $PP_server);
$req->content($query);
my $res = $ua->request($req);
# make the variable hash
my %variable =
map { split(m'='x, $_, 2) }
grep { m'='x }
split(m'&'x, $query);
# assign posted variables to local variables
my $item_name = $variable{'item_name'};
my $item_number = $variable{'item_number'};
my $payment_status = $variable{'payment_status'};
my $payment_amount = $variable{'mc_gross'};
my $payment_currency = $variable{'mc_currency'};
my $txn_id = $variable{'txn_id'};
my $receiver_email = $variable{'receiver_email'};
my $payer_email = $variable{'payer_email'};
if ($res->is_error) {
# HTTP error
}
elsif ($res->content eq 'VERIFIED') {
# check the $variable{'payment_status'}=Completed
if ($payment_status eq 'Completed') {
my ($tx)=$db->sqlSelect("tx", "article", "id_article = $item_numbe
+r");
if (!$tx eq $txn_id) {
if ($receiver_email eq 'alexjaquet@gmmail.com') {
print "Success";
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtim
+e();
my $date = sprintf "%4d-%02d-%02d",$year+1900,$mon+3,$mday;
my $time = sprintf("%4d:%02d:%02d",$hour,$min,$sec);
+
$db->sqlUpdate("article","id_article = $item_number",(
tx => "$txn_id",
pub => "1".
pub_date_end => "$date $time$item_number"
));
my $email = Email::Simple->create(
header => [
To => 'alexjaquet@gmail.com',
From => 'robot@avant-garde.info',
Subject => 'Vous avez reçu le payement',
],
body => 'Vous avez reçu le payement',);
sendmail($email, { transport => $transport });
}
}
}
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
print "Content-Type: text/html\n\n";
print "Erreur dans le payemeent d\'une publicité";
my $email = Email::Simple->create(
header => [
To => 'alexjaquet@gmail.com',
From => 'robot@avant-garde.info',
Subject => 'Erreur dans le payement' ],
body => 'Erreur dans le payement d\'une publicite
+: $id_article',);
sendmail($email, { transport => $transport });
}
else {
# error
# log for manual investigation
print "Content-Type: text/html\n\n";
print "Erreur dans le payemeenté";}
The log file show me
Tue Nov 26 17:31:58.528979 2019 cgi:error pid 2202 client 173.0.82.126:36191 End of script output before headers: ipn.pl
Hope you can help
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.