Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Monks, I've been using this script with Paypal's instant payment notification and it has worked perfectly. Today Paypal stopped receiving 200 responses from us, and they say it's because this script is sending http 1.0 headers and we need to send http 1.1 headers instead. How do I do that? If paypal calls this script, it replies with a 1.0 response. If I call the script from a browser the logs indicate a version 1.1 response is sent. I'm lost. UPDATE: It looks like all POSTS to the script return http 1.0 responses and all GETS return a http 1.0 response.
#!/usr/bin/perl use LWP::UserAgent; print "Content-type: text/plain\n\n"; # 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 $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 }); # when testing change sandbox url here $req = HTTP::Request->new('POST', ' +cr'); $req->content_type('application/x-www-form-urlencoded'); # and here $req->header(Host => ''); $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 $item_name = $variable{'item_name'}; $item_number = $variable{'item_number'}; $payment_status = $variable{'payment_status'}; $payment_amount = $variable{'mc_gross'}; $payment_currency = $variable{'mc_currency'}; $txn_id = $variable{'txn_id'}; $receiver_email = $variable{'receiver_email'}; $payer_email = $variable{'payer_email'}; $custom = $variable{'custom'}; if ($res->is_error) { # HTTP error # do whatever necessary print "ERROR: http_error! (Not sure what this is)\n"; $ipnerror = "http_error"; &error1; } elsif ($res->content eq 'VERIFIED') { print "PayPal responded VERIFIED.\n"; # check the $payment_status=Completed if ($payment_status ne "Completed") { # do whatever necessary print "Payment status was not Completed.\n"; $ipnerror = "Payment status was not completed."; &error1; } # check that $receiver_email is your Primary PayPal email elsif ($receiver_email ne "info\") { # do whatever necessary print "Receiver email was incorrect.\n"; $ipnerror = "Receiver email was incorrect"; &error1; } # process payment else { # everything ok, update your database # split 4 passthrough variables in "custom", separated by comma (',' +) # change separator char if necessary print "Everything should be ok.\n"; my ($user1, $user2, $user3) = split(/,/, $custom, 3); my $response = $ua->post('', { 'USER1' => $user1, 'USER2' => $user2, 'USER3' => $user3, 'RESULT' => '0' } ); unless ($response->is_success) { print "Posting to failed.\n"; $ipnerror = "Posting to failed."; &error1; # request failed } # parse server response my $resdec = $response->decoded_content; } } elsif ($res->content eq 'INVALID') { # log for manual investigation # do whatever necessary print "PayPal responded INVALID. (Probably means it didn't get called + from Paypal.)\n"; $ipnerror = "PayPal responded INVALID. (Probably means it didn't +get called from Paypal.)"; &error1; } else { # error # do whatever necessary print "Unexpected response from PayPal.\n"; $ipnerror = "Unexpected response from PayPal."; &error1; } sub error1 { $notify_admin2 = "1"; #1=yes, 0=no $mailprog = "/usr/sbin/sendmail"; if ($notify_admin2 eq "1") { # send mail with activate link to admin open (MAIL, "|$mailprog info\") || die "Can't open $ +mailprog!\n"; print MAIL "From: $sitename <admin\>\n"; print MAIL "Reply-to: $sitename <admin\>\n"; print MAIL "To:\n"; print MAIL "Subject: IPN Handler Error\n"; print MAIL "Content-type: text/plain\n"; print MAIL "There was an IPN Handler error.\n\n"; print MAIL "Error: $ipnerror\n\n"; print MAIL "User1: $user1\n"; print MAIL "User2: $user2\n"; print MAIL "User3: $user3\n"; print MAIL "This email sent by \n\n"; close (MAIL); } } #end sub print "Done\n";

In reply to Need help with http 1.1 headers by htmanning

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (6)
    As of 2019-12-10 23:43 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found