gpt4 book ai didi

c# - Paypal Ipn 与 asp.net MVC 集成

转载 作者:太空宇宙 更新时间:2023-11-03 19:14:41 25 4
gpt4 key购买 nike

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>

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

我的问题是即使在付款完成后,上面的 Ipn 操作方法也没有触发。无法调试。我该怎么做?

最佳答案

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

编辑:

另外 - 我想你可以给它你的 WAN IP 地址(不是本地的),打开你路由器的端口,然后使用那个 IP 地址(注意你可能需要启用与 IIS Express 的远程连接 - 见 IIS Express enable external request ) :

<input type="hidden" name="notify_url" value="https://97.25.43.21:13769/Home/Ipn">

关于c# - Paypal Ipn 与 asp.net MVC 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17911050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com