【问题标题】:Internal Server Error(500) paypal create payment Rest API with Java json payload in SandboxInternal Server Error(500) paypal create payment Rest API with Java json payload in Sandbox
【发布时间】:2017-03-06 19:08:40
【问题描述】:

我在使用 Sandbox 中的 json 有效负载使用 Java 代码创建贝宝付款时收到 Internal Server Error(500)

我是用 json 做的:

{
"intent": "sale",
"redirect_urls":
{
"return_url": "somelink",
"cancel_url": "somelink"
},
"payer":
{
"payment_method": "paypal"
},
"transactions": [
{
"amount":
{
"total": "17",
"currency": "EUR"
},
"description": "This is payment tran."
}]
}

我尝试使用邮递员完成相同的工作,我可以做到。事实上,我使用邮递员完成了整个付款交易(批准和执行)

我正在使用 Bearer 传递正确的访问令牌。

HttpPost paymentPost = new HttpPost("api.sandbox.paypal.com/v1/payments/payment"); 
paymentPost.setHeader(HttpHeaders.AUTHORIZATION, pt.getTokenType() + " " + pt.getAccessToken()); 
List<NameValuePair> nvPairs = new ArrayList<NameValuePair>(4); 
nvPairs.add(new BasicNameValuePair("content-type", "application/json")); nvPairs.add(new BasicNameValuePair("Accept", "application/json"));
paymentPost.setEntity(new UrlEncodedFormEntity(nvPairs));

【问题讨论】:

  • 您是否设置了正确的内容类型标头。 Content-Type:application/json?
  • 嗨 Nitish 我正在使用以下代码 HttpPost paymentPost = new HttpPost("api.sandbox.paypal.com/v1/payments/payment"); paymentPost.setHeader(HttpHeaders.AUTHORIZATION, pt.getTokenType() + " " + pt.getAccessToken()) ; List nvPairs = new ArrayList(4); nvPairs.add(new BasicNameValuePair("content-type", "application/json")); nvPairs.add(new BasicNameValuePair("Accept", "application /json")); paymentPost.setEntity(new UrlEncodedFormEntity(nvPairs));

标签: java json paypal paypal-sandbox


【解决方案1】:

您正在将内容类型和接受设置为请求的正文而不是标头。而且在您的代码中,我看不到您将 json 添加到请求的位置。也许您正在这样做并且没有在您发布的代码中显示它。 .您需要使用 addHeader 添加两个标题。也许你可以试试下面的代码,看看它是否能解决问题。

HttpPost paymentPost = new HttpPost("api.sandbox.paypal.com/v1/payments/payment");
paymentPost.setHeader(HttpHeaders.AUTHORIZATION, pt.getTokenType() + " " + pt.getAccessToken());  
paymentPost.addHeader("content-type", "application/json"); 
paymentPost.addHeader("Accept", "application/json"); 
paymentPost.setEntity(new StringEntity(/**"YOUR JSON STRING"**/));

【讨论】:

  • 谢谢 Nithish。我错过了。我正在字符串实体中构造和传递我的 json。
  • 是的。抱歉这么晚才回复。
猜你喜欢
  • 2015-03-05
  • 1970-01-01
  • 2013-09-20
  • 2023-04-06
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
相关资源
最近更新 更多