2012-11-29 37 views
3

我想在我的node.js應用中實現PayPal IPN驗證。我使用快速框架。PayPal與node.js的IPN驗證 - 快速應用

這是我的代碼:

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 

     } 
     } 
    }); 
}); 

我使用paypal-ipn這一點。

當我試圖從貝寶沙箱發送IPN消息我得到這個消息

IPN傳遞失敗。無法連接到指定的網址。請驗證網址並重試。

但是當我嘗試採樣消息從終端的捲曲我在我的服務器應用程序獲取請求的幫助下,它會顯示日誌

貝寶! req.body:[對象的對象] req.body.payment_status:待定MSG:VERIFIED POST /貝寶200 572ms

+0

從PayPal沙盒我使用的URL爲http:// myserverurl:PORTNO /貝寶 – Damodaran

回答

1

我知道了。我沒有在我的服務器上偵聽端口443(https)。

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); 
}); 

貝寶將IPN消息發送到https端口443(我認爲)。無論如何,我明白了...