本文介绍了与asp.net MVC好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="[email protected]">
                <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中操作方法如下

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中的操作方法是不是firing.Cannot debug.How我能做到这一点?

My question is even after payment has been done, above Ipn action method is not firing.Cannot debug.How could I do that ?

推荐答案

如果我没有记错,该IPN是一个异步调用,可以来在交易后的任何时间(通常它的即时,有时没有那么多)。但是,这来自贝宝,谁也无法访问的http://本地主机。为了测试IPN需要部署到实际的互联网网站,任何人都可以访问。这是一个几年,因为我有工作IPN - 但是这是我的基本经验。安装在应用程序中的一些日志,发布,然后做你的测试数据。

If I remember correctly, the IPN is an asynchronous call that can come at anytime after the transaction (its generally "instant", sometimes not so much). But this comes from PayPal, who cannot access http://localhost. To test IPN you need to deploy to an actual internet site that anyone can access. It's been a few years since I worked with IPN - but that was my general experience. Setup some logging in your application, publish, then do your test transactions.

编辑:

此外 - 我想你可以给它你的广域网IP地址(非本地),在你的路由器打开端口,并改用IP地址(注意,您可能需要启用IIS防爆preSS远程连接 - 请参见):

Also - I think you can give it your WAN IP address (not local), open up the ports in your router, and instead use that IP address (note you may need to enable remote connections with IIS Express - see IIS Express enable external request):

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

这篇关于与asp.net MVC好PayPal IPN一体化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 11:47