1

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 操作方法也没有触发。无法调试。我该怎么做?

4

2 回答 2

6

如果我没记错的话,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">
于 2013-07-28T23:39:29.680 回答
0

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

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

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

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

希望这可以帮助。

于 2013-09-23T11:15:07.343 回答