PayPal 400 Bad Request, more specific?

旧城冷巷雨未停 提交于 2019-12-22 07:20:14

问题


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"}

回答1:


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


回答2:


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.




回答3:


I appreciated @JasonZ's suggestion of using PayPalResource.LastResponseDetails.Value but found that the response body was always empty. The only way I've found to get the error explanation without fiddler is this:

catch (PayPal.PaymentsException ex)
{
    context.Response.Write(ex.Response);
}

With result:

{"name":"VALIDATION_ERROR","details":[{"field":"start_date","issue":"Agreement start date is required, should be valid and greater than the current date. Should be consistent with ISO 8601 Format"}],"message":"Invalid request. See details.","information_link":"https://developer.paypal.com/docs/api/payments.billing-agreements#errors","debug_id":"8c56c13fccd49"}



回答4:


I had gone through the same issue. In my case it was Credit Card issue which might be over used. So I have taken new Credit card Number from this site Testing Credit card and replaced with the old one. Here is Credit Card Information that I used

credit_card = new CreditCard()
                    {
                        billing_address = new Address()
                        {
                            city = "Johnstown",
                            country_code = "US",
                            line1 = "52 N Main ST",
                            postal_code = "43210",
                            state = "OH"
                        },
                        cvv2 = "874",
                        expire_month = 11,
                        expire_year = 2018,
                        first_name = "Joe",
                        last_name = "Shopper",
                        number = "4024007185826731", //New Credit card Number, Only Card type should match other details does not matter
                        type = "visa"
                    }

Note: All the Credit Card mentioned in PayPal site are not working, giving same issue for me. If it working for you then it's good otherwise use new testing Credit Card Number. Hope this will help for someone.

Enjoy Coding!



来源:https://stackoverflow.com/questions/30540859/paypal-400-bad-request-more-specific

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!