我得到一个内部服务器错误(500)当创建一个paypal支付与Java代码使用json有效载荷在沙盒。
我用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."
}]
}
我试着用邮差完成同样的事情,我可以做到。事实上,我使用邮差
完成了整个支付交易(审批和执行)。我正在传递正确的访问令牌。
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));
您正在将内容类型和Accept设置为请求的正文而不是标头。而且在你的代码中,我不知道你在哪里添加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"**/));