3
votes

I am trying to implement Paypal IPN verification in my node.js app.I am using express framework.

This is my code :

app.post('/paypal', function(req,res){
console.log("IN PAYPAL !! req.body : "+req.body);
var ipn = require('paypal-ipn');
ipn.verify(req.body, function callback(err, msg) {
      if (err) {
        console.log("Error:"+err);
      } else {
        //Do stuff with original params here
          console.log("req.body.payment_status :"+req.body.payment_status+" msg: "+msg);
          res.end();
        if (req.body.payment_status == 'Completed') {
          //Payment has been confirmed as completed

        }
      }
    });
});

I am using paypal-ipn for this.

When I try to send the IPN message from Paypal Sandbox I am getting this message

IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.

But when I try a sample message from terminal with the help of curl i am getting the request at my server app and it is displaying the log

IN PAYPAL !! req.body : [object Object] req.body.payment_status :Pending msg: VERIFIED POST /paypal 200 572ms

1
From Paypal Sandbox I use the url as myserverurl:PORTNO/paypalDamodaran

1 Answers

1
votes

I got it. I am not listening to port 443 (https) in my server.

var https = require('https'),
    fs = require('fs');

var httpsOptions = {
    key: fs.readFileSync('path/to/private/key'),
    cert: fs.readFileSync('path/to/certs')
}

http.createServer(app).listen(app.get('port'), function() {
    console.log("server listening on port " + app.get('port'));
});

https.createServer(httpsOptions, app).listen(443,function () {
    console.log("server listening on port " + 443);
});

Paypal sending the IPN message to the https port 443 (I think). Anyway I got it...