我尝试将PayPal API集成到我的应用中。当我尝试在脚本中调用API时,出现错误:
传入的JSON请求未映射到API请求。这是错误的全部对象:
debug_id:“ 8280412cbada” information_link:“ https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST”
消息:“传入的JSON请求未映射到API请求” 名称:“ MALFORMED_REQUEST”
但是当我尝试通过EasyRest使用相同的参数进行呼叫时,一切正常。
这是我用来打电话的代码:
function payPalStep3(gAccessToken, gPrice, gCurrency, gOrderNumber){ return new Promise((resolve, reject) => {
let newPayment = {
intent: 'sale',
redirect_urls: {
return_url: 'http://localhost:3000/success.html',
cancel_url: 'http://localhost:3000/reject.html'
},
payer: {
payment_method: 'paypal'
},
transactions: [{
amount: {
total: parseFloat(gPrice),
currency: gCurrency
}
}]
}
let req = new XMLHttpRequest();
let UrlReq = 'https://api.sandbox.paypal.com/v1/payments/payment';
req.open('POST', UrlReq, true);
req.setRequestHeader('Content-Type', 'application/json');
req.setRequestHeader('Authorization', 'Bearer '+gAccessToken);
req.onreadystatechange = function(){
if(req.readyState == 4){
let shopUserResponse = req.response;
shopUserResponse = JSON.parse(shopUserResponse);
resolve(shopUserResponse);
}
req.onerror = () => err(false);
}
req.send(newPayment) })}
也许有人可以帮助我。