0

I have been trying for some time to get a simple PayPal IPN module working but keep getting a 400 Bad Request error from LWP::UserAgent. I am not sure why this is happening. PayPal pings me fine (I'm using the IPN simulator) and I can see the process in my app logs. I can call the PayPal validation URL via LWP::UserAgent without form content and that works fine, but once I include the request content for validation I get error 400. If anyone knows about this please let me know.

-$self->{'_req'} is of type Plack::Request

my $url     = $test ? $VERIFY_URL_DEV : $VERIFY_URL;
my $ua      = new LWP::UserAgent();
my $req     = new HTTP::Request('POST', $url);
my $query   = 'cmd=_notify-validate&' . $self->{'_req'}->raw_body;

$req->content_type('application/x-www-form-urlencoded');
$req->content( $query );

my $res = $ua->request($req);

if ($res->is_error)
{
    # HTTP error, indicate an invalid notification.
    warn "There was an error validating this IPN.";
    warn $res->message;
    warn $res->error_as_HTML;
    return 0;
}
MadHacker
  • 608
  • 5
  • 18
  • Set up a working and failing request object each and provide dumps with [as_string](http://p3rl.org/HTTP::Request#r-as_string). Redact any non-public data. – daxim Mar 11 '13 at 06:44
  • 1
    There was a PayPal issue that provided an HTTP 400 error for Sandbox IPNs up until Monday night. Could you advise if the error is still occurring or if all is well? – PP_MTS_Matt Mar 13 '13 at 14:46

1 Answers1

0

The problem was on the PayPal side. When I tested in sandbox, not the IPN simulator, it worked fine. That was very frustrating.

MadHacker
  • 608
  • 5
  • 18