Sam*_*ath 1 c# paypal paypal-ipn asp.net-mvc-4
HomeControler/Index.cshtml页面如下
<div id="paypalDiv">
<form id="paypalForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<fieldset>
<p class="inline-small-label" style="padding-top: 7px;">
<label for="device-id"><span>User ID</span></label></p>
<input id="custom" class="full-width" type="text" name="custom" value="">
<input class="full-width" type="hidden" name="business" value="sampath-facilitator@inexisconsulting.com">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="credits">
<input type="hidden" name="item_number" value="40">
<input type="hidden" name="amount" value="2.95">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://localhost:13769">
<input type="hidden" name="notify_url" value="https://localhost:13769/Home/Ipn">
<button class="btn btn-primary submit-button" type="submit">Pay with PayPal</button>
</fieldset>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
HomeControler/Ipn Action方法如下
public ActionResult Ipn()
{
// Receive IPN request from PayPal and parse all the variables returned
var formVals = new Dictionary<string, string>();
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();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是即使付款完成后,上面的Ipn动作方法也没有解雇.无法调试.我怎么能这样做?
如果我没记错的话,IPN是一个异步调用,可以在事务发生后的任何时间进行(通常是"即时",有时不是那么多).但这来自PayPal,他无法访问http://localhost.要测试IPN,您需要部署到任何人都可以访问的实际Internet站点.我与IPN合作已经有几年了 - 但这是我的一般经历.在应用程序中设置一些日志记录,发布,然后进行测试事务.
编辑:
另外 - 我认为你可以给它你的WAN IP地址(不是本地的),打开路由器中的端口,而是使用该IP地址(注意你可能需要启用与IIS Express的远程连接 - 请参阅IIS Express启用外部请求):
<input type="hidden" name="notify_url" value="https://97.25.43.21:13769/Home/Ipn">
Run Code Online (Sandbox Code Playgroud)