I followed the Paypal documentation on how to make an order, this is the object:
var payReq= JSON.stringify({
"0intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:3000/process",
"cancel_url": "http://localhost:3000/cancel",
},
"transactions": [{
"item_list": {
"items": [{
"name": "tacos",
"sku": "001",
"price": "1.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": "1.00"
},
"description": "This is the payment description."
}]
});
And this is the function to make the order:
paypal.payment.create(payReq, function(error, payment){
var links = {};
if(error){
console.error(JSON.stringify(error));
} else {
// Capture HATEOAS links
payment.links.forEach(function(linkObj){
links[linkObj.rel] = {
href: linkObj.href,
method: linkObj.method
};
})
// If the redirect URL is present, redirect the customer to that URL
if (links.hasOwnProperty('approval_url')){
// Redirect the customer to links['approval_url'].href
} else {
console.error('no redirect URI present');
}
}
});
And this is what I get when executing the function:
{"response":{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"ee13a7fe92652","httpStatusCode":400},"httpStatusCode":400}
According to the Paypal documentation the error 400 means: Bad Request: The server could not understand the request, probably due to syntax error.