paypal https request

1,086 views
Skip to first unread message

garry slacker

unread,
Nov 11, 2011, 3:23:21 AM11/11/11
to nodejs
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&currencyCode=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);
});
});
});

Koichi Kobayashi

unread,
Nov 11, 2011, 10:01:56 PM11/11/11
to nod...@googlegroups.com
Hi,

Because default Agent ignores key and cert,
you should use a custom Agent.

var req_options = {
...
};
req_options.agent = new https.Agent(req_options);

http://nodejs.org/docs/latest/api/https.html#https.request

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

garry slacker

unread,
Nov 11, 2011, 11:20:14 PM11/11/11
to nod...@googlegroups.com
thanks for the reply!

i have made the changes but still getting the same error, I've been looking at the returned res from the https.request for a clue as to why it's not connecting, but not sure what to look for. The response from paypal is

responseEnvelope.timestamp=2011-11-11T20%3A12%3A51.332-08%3A00&responseEnvelope.ack=Failure&responseEnvelope.correlationId=a895d3bb9728a&responseEnvelope.build=2228340&error(0).errorId=580001&error(0).domain=PLATFORM&error(0).subdomain=Application&error(0).severity=Error&error(0).category=Application&error(0).message=Invalid+request%3A+%7B0%7D

im guesing the this means paypal is not receiving any values at all, as the converted hex in error(0).message reads : {0}
Reply all
Reply to author
Forward
0 new messages