JS PayPal REST integration error: MALFORMED_REQUEST

andrOl
Contributor
Contributor

Hello, guys!

I try to integrate PayPal API to my app. When I try to make call to API in my script I got an error:
Incoming JSON request does not map to API request. This is the full object of error:

 

{
debug_id:"8280412cbada",
information_link:"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
message:"Incoming JSON request does not map to API request",
name:"MALFORMED_REQUEST"
}

 

But when I try to make call via EasyRest with the same parameters all is working OK.

This is the code which I used to make call:

 

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)


})
}


Maybe somebody can help me, please.

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.