我正在尝试使用Ajax发起PayPal付款,我已设法获取我的OAuth Bearer Access Token并使用它来创建一个AJAX查询来请求付款,但是当我提交时我收到以下错误
<ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.lang.NullPointerException</ns1:faultstring></ns1:XMLFault>
我正在运行的代码是:
dataObject = {
"transactions": [{
"amount": {
"currency":"USD",
"total":"12"
},
"description":"creating a payment"
}],
"payer": {
"payment_method":"paypal"
},
"intent":"sale",
"redirect_urls": {
"cancel_url":"https://devtools-paypal.com/guide/pay_paypal/curl?cancel=true",
"return_url":"https://devtools-paypal.com/guide/pay_paypal/curl?success=true"
}
};
$.ajax({
headers: {
"Accept": "application/json",
"Accept-Language": "en_US",
"Authorization": "Bearer " + accessCode,
},
url: "https://api.sandbox.paypal.com/v1/payments/payment",
method: "POST",
data: dataObject,
complete: function(result) {
if (console) { console.log('response: ' + JSON.stringify(result)); };
},
error: function(err) {
alert(err);
}
});
答案 0 :(得分:1)
找到解决方案,从PayPal Curl文档转换的标头中出现错误,需要明确说明内容类型的Ajax
"Content-Type": "application/json"