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

标签 c# asp.net-mvc-4 paypal paypal-ipn

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/

相关文章:

c# - 如何识别基于单个左连接的 sql 命令的左连接过多

rest - 具有多个参数的 MVC4 Web API Rest 接口(interface)

c# - 如何使用 ASP.NET MVC 和 Knockout JS 将真/假值绑定(bind)到复选框

c# - 删除 PayPal 中的送货地址信息

php - Paypal - 返回 $_GET 的 URL 数组

Paypal IPN 处理程序 - 如何知道谁的交易发生

c# - 防止在单元测试中写入数据库 - .NET MVC/Entity Framework

c# - 图像编码为 ccitt 的 iOS pdf

c# - 是否有可能创建一个始终会自行清理的进程?

c# - ASP MVC中的文件上传和处理