1

HomeControler/Index.cshtml page is as below

<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 method is as below

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

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

Sampath
  • 63,341
  • 64
  • 307
  • 441
  • Hii, I'm facing same problem. How to test it on local server. and could you please show your GetPayPalResponse method code? – Amit Kumar Aug 17 '15 at 07:41

2 Answers2

6

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.

EDIT:

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">
Community
  • 1
  • 1
Jack
  • 9,156
  • 4
  • 50
  • 75
  • Excellent suggestions.I will try this solution tonight and will give you a feedback.Thanks a lot. – Sampath Jul 29 '13 at 07:00
  • I have sorted out my issue by hosting my app on public access IIS with trusted certification (https).Thanks for your idea. – Sampath Aug 14 '13 at 10:11
  • @Ostati Yes,I have successfully completed IPN integration. If you need any help plz let me know.And also when you put comments for me use "@sampath" otherwise SOF won't notify me or else put directly on my question area,Then no need to use "@" mark. – Sampath Aug 14 '13 at 10:16
  • @Sampath , Hi sampath this is Kishore.Am facing same problem with ipn.Am not getting any response back, so am not able to find the solution.Here is my code snippet. http://stackoverflow.com/questions/20607219/paypal-ipn-status-is-always-invalid – KiShOrE Dec 17 '13 at 05:04
  • @Kishore I would like to share my working code with you.So If you still have the same problem please let me know. – Sampath Dec 21 '13 at 07:25
  • hi sampath can you share your code to me i'm trying to integrate this too, please help – Nevi Oct 28 '15 at 02:08
  • @Sampath Any tips on how you managed to test this out? And did the basis of the code included in the question eventually change, or did the logic hold? – Jurgen Cuschieri Nov 08 '17 at 01:15
  • Oh... More than 4 years old question and now I'm not working with C# too.Sorry about that. Hope you can raise new question about your issue @JurgenCuschieri – Sampath Nov 08 '17 at 01:19
  • it's rather I have a solution and need to test it out. dont know sh*t about port forwarding and that kinda stuff, and you said "hosting my app on public access IIS", thought it might not have required any complicated stuff haha! I'll do some more research and raise a question if I do not get anywhere :) thanks for the question still though ! – Jurgen Cuschieri Nov 08 '17 at 01:26
  • Essentially, your local development box that you are programming on, is not a "real" webserver. People can't access it, and thus PayPal can't access it - no one can access it, except you, for development. If you want to "open it up" for access (to test IPN), you need to configure your router to allow traffic from anywhere to your local PC, which has risks. But you can disable it after testing. If you don't know anything about port forwarding, figure out your router type, then Google "port forwarding for router x". – Jack Nov 08 '17 at 05:01
0

You can check ipn on your localhost. You need to set up your router to accept and redirect incoming calls to your localhost. Then go to paypal.sandbox. Using their tools you can mimic different IPN responses to your localhost(of course using your outside Ip address).

In this way, sandbox sends tcp/Ip messages to your machine, your router redirects it to your machine which is hosting the test website.

It is best not to try to send a message to sandbox and expect to receive and capture the response back. It is not that sandbox is not working correctly. It is.

The problem is if sandbox responds quickly then your test machine(whilst in debug mode) may not be fast enough to capture the return tcp/ip packet. You could use another machine to start a transaction on your localhost website. i.e. decoupling test transaction path.

Hope this helps.

Farjad
  • 257
  • 4
  • 9
  • Get ngrok to bridge a channel between internet and your localhost, it is great tool that can run on all platform, include Windows. – Adamy Feb 27 '16 at 11:40