Paypal Ipn与asp.net MVC集成

HomeControler / Index.cshtml页面如下

HomeControler / Ipn Action方法如下

 public ActionResult Ipn() { // Receive IPN request from PayPal and parse all the variables returned var formVals = new Dictionary(); formVals.Add("cmd", "_notify-validate"); // if you want to use the PayPal sandbox change this from false to true string response = GetPayPalResponse(formVals, false); if (response == "VERIFIED") { string transactionID = Request["txn_id"]; string sAmountPaid = Request["mc_gross"]; string deviceID = Request["custom"]; //validate the order Decimal amountPaid = 0; Decimal.TryParse(sAmountPaid, out amountPaid); if (sAmountPaid == "2.95") { // take the information returned and store this into a subscription table // this is where you would update your database with the details of the tran return View(); } else { // let fail - this is the IPN so there is no viewer // you may want to log something here } } return View(); } 

我的问题是,即使付款完成后,上面的Ipn动作方法也没有解雇。无法调试。我怎么能这样做?

如果我没记错的话,IPN是一个异步调用,可以在事务发生后的任何时间进行(通常是“即时”,有时不是那么多)。 但这来自PayPal,他无法访问http://localhost 。 要测试IPN,您需要部署到任何人都可以访问的实际Internet站点。 我与IPN合作已经有几年了 – 但那是我的一般经历。 在应用程序中设置一些日志记录,发布,然后进行测试事务。

编辑:

另外 – 我认为你可以给它你的WAN IP地址(不是本地的),打开路由器中的端口,而是使用该IP地址(注意你可能需要启用与IIS Express的远程连接 – 请参阅IIS Express启用外部请求 ):

  

您可以在localhost上查看ipn。 您需要将路由器设置为接受并将传入呼叫重定向到本地主机。 然后转到paypal.sandbox。 使用他们的工具,您可以模仿对本地主机的不同IPN响应(当然使用您的外部IP地址)。

通过这种方式,沙箱将tcp / ip消息发送到您的计算机,您的路由器将其重定向到托管测试网站的计算机。

最好不要尝试向沙箱发送消息,并期望接收和捕获响应。 沙盒不能正常工作。 它是。

问题是如果沙箱响应很快,那么您的测试机器(在调试模式下)可能不够快,无法捕获返回的tcp / ip数据包。 您可以使用另一台计算机在localhost网站上启动事务。 即解耦测试事务路径。

希望这可以帮助。