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"}
PayPal Checkout: Bad request (/payment-paypal-createOrder) - The value of a field is either too short or too long.
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.
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.
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.
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.
Direct Link
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With