PayPal 400 Bad Request,更具体?

是否有任何方法可以获得比400错误请求更具体的PayPal错误? 我看到有人这样做:

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

但这似乎对我没有任何不同,所有错误都说:“远程服务器返回错误:(400)错误请求。”

我已经读到它可能与某种validation错误有关,但我已经尝试更改我发送给PayPal的数据,但到目前为止都没有运气。

我希望你能帮帮我,谢谢!

编辑:

感谢Aydin,我设法通过Fiddler在其中一个HTTP请求中找到此错误消息:

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

您可以通过安装Fiddler来节省自己的时间,这样您就可以看到您发送的确切HTTP Web请求,以及在您的应用程序开始处理之前收到的响应。

这是我浏览的一个例子, example.com 。 您可以在右上半部分看到我的浏览器发送的请求,以及右下半部分的响应,包括所有标题和所有内容……仅使用exception管理尝试调试HTTP流量会让您感到疯狂。

提琴手的形象 直接链接

除了使用Fiddler(我强烈建议使用它,因为它是一个很棒的工具),您还可以将捕获逻辑更改为以下内容以获取响应正文详细信息:

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

… 要么 …

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

此外,如果您使用的是PayPal .NET SDK的1.4.3版(或更高版本),则可以通过以下public static属性访问先前请求和响应的详细信息:

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

每当SDK对API进行新调用时,都会设置每个属性。

我很欣赏@JasonZ建议使用PayPalResource.LastResponseDetails.Value但发现响应体总是空的。 我发现没有fiddler得到错误解释的唯一方法是:

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

结果如下:

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

我经历过同样的问题。 就我而言,信用卡问题可能会被过度使用。 所以我从这个站点测试信用卡上取了新的信用卡号码,换成旧的。 这是我使用的信用卡信息

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

注意:PayPal网站中提到的所有信用卡都不起作用,给我同样的问题。 如果它适合你,那么否则使用新的测试信用卡号是好的。 希望这对某人有所帮助。

享受编码!