Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal 400 Bad Request, more specific?

Is there any way to get a more specific PayPal error than 400 bad request? I saw someone doing something like this:

if (ex.InnerException is ConnectionException)
{
    Response.Write(((ConnectionException) ex.InnerException).Response);
}
else
{
    Response.Write(ex.Message);
}

But that doesn't seem to do anything different for me, all the error says is: "The remote server returned an error: (400) Bad Request."

I've read that it could have something to do with some sort of validation error, but I've tried changing the data I'm sending to PayPal, but all with no luck so far.

I hope you can help me, thank you!

EDIT:

Thanks to Aydin I managed to find this error-message in one of the HTTP requests through Fiddler:

{"name":"VALIDATION_ERROR","details":[{"field":"payer.funding_instruments[0].credit_card.number","issue":"Value is invalid"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"dd5f11f6e9c98"}
like image 270
Mikkel Avatar asked May 30 '15 00:05

Mikkel


People also ask

What does bad request mean on PayPal?

PayPal Checkout: Bad request (/payment-paypal-createOrder) - The value of a field is either too short or too long.

How do I fix Error 400 on Payfast?

This error happens when you try to place an order using the same email as the one you used to create your Payfast account, as Payfast does not allow this. To test the payment, you would just need to use a different email address.

What is a PayPal debug ID?

The Debug ID is a comma separated list of the debug IDs received from PayPal. To troubleshoot the payment, you can contact PayPal support and they can use the Debug ID information to identify the problem. When the problem is resolved, you can make the payment manually.

What is the PayPal request ID?

To enforce idempotency on REST API POST calls, use the PayPal-Request-Id request header, which contains a unique user-generated ID that the server stores for a period of time. Note: Not all APIs support this header.


2 Answers

You can save yourself time by installing Fiddler, by doing so you can see the exact HTTP Web Requests that you send, and the responses that you receive before it even begins to be processed by your application.

Here's an example of me browsing to, example.com. You can see the requests sent from my browser on the right top half, and the response in the bottom right half including all the headers and everything... Attempting to debug HTTP traffic using exception management alone will drive you insane.

image of FiddlerDirect Link

like image 87
Aydin Avatar answered Sep 23 '22 14:09

Aydin


Along with using Fiddler (which I highly advise using, as it's a fantastic tool), you can also change your catch logic to the following to get the response body details:

try
{
    var payment = Payment.Create(...);
}
catch(PayPalException ex)
{
    if(ex is ConnectionException)
    {
        // ex.Response contains the response body details.
    }
    else
    {
        // ...
    }
}

... or ...

try
{
    var payment = Payment.Create(...);
}
catch(ConnectionException ex)
{
    // ex.Response contains the response body details.
}
catch(PayPalException ex)
{
    // ...
}

Also, if you're using version 1.4.3 (or later) of the PayPal .NET SDK, you can access the details of the previous request and response via the following public static properties:

  • PayPalResource.LastRequestDetails.Value
  • PayPalResource.LastResponseDetails.Value

Each of these properties are set whenever the SDK makes a new call to the API.

like image 28
Jason Z Avatar answered Sep 24 '22 14:09

Jason Z