我正在尝试POST
请求:
https://svcs.sandbox.paypal.com/AdaptivePayments/Pay
使用JQuery mobile。 我已经尝试在Postman中做到这一切,一切正常,收到钥匙和我需要的一切。但是使用Ajax,它会返回一个错误:
Authentication failed. API credentials are incorrect.
我正在使用相同的标题(appid,用户ID,密码,签名和数据格式) 这是发布请求的方法:
function sendPayment(amount){
$.ajax({
method:'POST',
dataType: "jsonp",
url:"https://svcs.sandbox.paypal.com/AdaptivePayments/Pay",
headers:{
"X-PAYPAL-APPLICATION-ID" : "APP-80W284485P519543T",
"X-PAYPAL-SECURITY-USERID" : "mysandboxemail.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" : "mysandboxpass",
"X-PAYPAL-SECURITY-SIGNATURE" : "mysandboxsignature",
"X-PAYPAL-REQUEST-DATA-FORMAT" : "JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT" : "JSON"
},
data:JSON.stringify({
"actionType":"PAY",
"currencyCode":"USD",
"receiverList":{"receiver":[{
"amount":"1.0",
"email":"myreceiveremail@gmail.com"}]
},
"returnUrl":"http://Payment-Success-URL",
"cancelUrl":"http://Payment-Cancel-URL",
"requestEnvelope":{
"errorLanguage":"en_US",
"detailLevel":"ReturnAll"
}
}),
success:function(data, status, xhr){
console.log(data);
},
error:function(data){
console.log(data);
},
timeout: 3000
});
}
关于我做错了什么的任何想法? (我当然使用的是沙盒)
答案 0 :(得分:0)
所以我们发现JQuery在标题或其他东西上添加了其他东西,因此它搞砸了请求。 因此,不要使用Jquery的$ .ajax方法,而是使用旧式的方法:
var toSend={
"actionType": "PAY",
"currencyCode": "USD",
"receiverList": {
"receiver": [{
"amount": 1.2,
"email": "killer123@gmail.com"
}]
},
"returnUrl": "http://google.com",
"cancelUrl": "http://yahoo.com",
"requestEnvelope": {
"errorLanguage": "en_US",
"detailLevel":'ReturnAll'
}
};
var xhr = new XMLHttpRequest();
xhr.open('POST', "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay", true); // plug-in desired URL
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
alert('Success: ' + xhr.responseText); // the response json here
alert(JSON.stringify(xhr)); //for debugging
} else {
alert('Error submitting image: ' + xhr.status);
alert(JSON.stringify(xhr));
}
}
};
//form.append('file', dataUrl);
xhr.setRequestHeader( "X-PAYPAL-APPLICATION-ID", "APP-coolioApp");
xhr.setRequestHeader( "X-PAYPAL-SECURITY-USERID", "senderman.gmail.com");
xhr.setRequestHeader( "X-PAYPAL-SECURITY-PASSWORD", "supersecretpass");
xhr.setRequestHeader( "X-PAYPAL-SECURITY-SIGNATURE", "supersecrensignature-asdasd");
xhr.setRequestHeader( "X-PAYPAL-REQUEST-DATA-FORMAT", "JSON");
xhr.setRequestHeader( "X-PAYPAL-RESPONSE-DATA-FORMAT", "JSON");
xhr.send(JSON.stringify(toSend));