node.js - nodejs paypal pdt return 302 -


i'm using nodejs , express. code run on return paypal. 302 errors in response paypal. saw couple examples use ssl:// instead of https:// nodejs yells saying not valid protocol https module. have working nodejs script pdt , ipn?

var purchaseid = req.query.tx; var atoken = myauthtoken; var postdataarray = {'cmd':'_notify-synch','tx': purchaseid, 'at': atoken} var postdata = json.stringify(postdataarray); console.log(postdata); var options = {     hostname: 'www.sandbox.paypal.com',     port: 443,     path: '/cgi-bin/webscr', method: 'post',         headers: {             'content-type': 'application/x-www-form-urlencoded',             'content-length': postdata.length         }     };      var req = https.request(options, function(res) {         console.log('status: '+ res.statuscode);         console.log('headers: '+ json.stringify(res.headers));         res.setencoding('utf8');         res.on('data', function(chunk) {             console.log('body: '+chunk);         });         res.on('end', function() {             console.log('no more data in response.')         });     });     req.on('error', function(e) {         console.log('problem request: '+e.message);     });     req.write(postdata);     req.end(); }); 

this

you're missing accept: */* header. also, json.stringify not application/x-www-form-urlencoded. here working code build based on:

var request = require('request'); var endpoint = 'www.sandbox.paypal.com'; var options = {   form: {     cmd: '_notify-synch',     tx: tx,     at: auth   },   headers: {     accept: '*/*'   } }; request.post('https://' + endpoint + '/cgi-bin/webscr', options, function(e, r, body) {   return console.log(body); }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -