Hey Guys,
not sure if this is the correct place to post this, so if not let me
know, also apologies if it turns out to be something very obvious.
I am trying to call the paypal adaptive payments api via node.js and
am getting a 580001 invalid request error. I can make a successfull
call via curl with the below message and headers, but not through
node.
any help would be much appreciated.
var API_endpoint = "
svcs.sandbox.paypal.com";
var API_user = '';
var API_pass = '';
var API_sig = '';
message='requestEnvelope.errorLanguage=en_US&actionType=PAY&senderEmail=
test_1320...@gmail.com&receiverList.receiver(0).email=
test2_1320...@gmail.com&
receiverList.receiver(0).amount=100.00¤cyCode=USD&cancelUrl=http://
your_cancel_url& returnUrl=
http://your_return_url'
//var params = qs.parse(message);
//params = qs.stringify(params);
var req_options = {
host: API_endpoint,
method: 'POST',
path: '/AdaptivePayments/Pay',
headers: {
'Host': API_endpoint,
'Content-Type': 'application/x-www-form-urlencoded',
//'Content-Type': 'text/namevalue',
'Content-Length': message.length,
'X-PAYPAL-REQUEST-DATA-FORMAT:':'NV',
'X-PAYPAL-RESPONSE-DATA-FORMAT':'NV',
'X-PAYPAL-SECURITY-USERID':API_user,
'X-PAYPAL-SECURITY-PASSWORD':API_pass,
'X-PAYPAL-SECURITY-SIGNATURE':API_sig,
'X-PAYPAL-APPLICATION-ID':'APP-80W284485P519543T'
}
}
fs.readFile('/home/dev/.ssh/sandbox-paypal-private.pem', 'ascii',
function(err, key){
fs.readFile('/home/dev/.ssh/sandbox-paypal-public.pem',
'ascii', function(err, cert){
req_options.key=key
req_options.cert=cert
var req = https.request(req_options, function(res){
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' +
JSON.stringify(res.headers));
res.on('data', function(d){
var response = d.toString();
console.log(response)
});
});
req.write(message);
req.end();
req.on('error', function request_error(e) {
console.log(e);
});
});
});