Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.

Posted on 2011-10-07
9
Medium Priority
?
1,638 Views
Last Modified: 2012-08-14
hi experts,

I have written my IPN LIstene in c# as attached in the code and trying to test it via paypal
Instant Payment Notification (IPN) simulator but getting the following error

IPN delivery failed. Unable to connect to the specified URL. Please verify the URL and try again.

Any ideas what i m doing wrong
thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.IO;
using System.Collections.Specialized;

public partial class IPNListener : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


        string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        string strLive = "https://www.paypal.com/cgi-bin/webscr";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
        //Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);
        string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
        strRequest += "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
        //req.Proxy = proxy;
        //Send the request to PayPal and get the response
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();

        if (strResponse == "VERIFIED")
        {
            //check the payment_status is Completed
            //check that txn_id has not been previously processed
            //check that receiver_email is your Primary PayPal email
            //check that payment_amount/payment_currency are correct
            //process payment

            // pull the values passed on the initial message from PayPal

            NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
            string user_email = these_argies["payer_email"];
            string pay_stat = these_argies["payment_status"];
            //.
            //.  more args as needed look at the list from paypal IPN doc
            //.


            if (pay_stat.Equals("Completed"))
            {
                SendEmail(user_email);
            }


            // more checks needed here specially your account number and related stuff
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
        }
        else
        {
            //log response/ipn data for manual investigation
        }
    }

    protected void SendEmail(string userEmail)
    {

        string MailFrom, MailTo, MailSub, MailMsg;


        MailFrom = "support@practicelifeintheuktest.co.uk";
        MailTo = "mmalik15@gmail.com";
        MailSub = "A user has made a payment";
        MailMsg = "Dear Support,<Br /><Br />" + userEmail.ToString() + " has made us a payment at " + DateTime.Now.ToShortDateString() + ". <br /> Thankyou.";

        DT_SendEmail obj = new DT_SendEmail(MailTo, MailFrom, MailSub, MailMsg);
        obj.SendEmailWithOutCC();

    }
}

Open in new window

0
Comment
Question by:mmalik15
  • 4
  • 4
9 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 36934532
What have you specified as your IPN URL?

(When you enable IPN, PayPal sends messages to the IPN listener at the URL you specify in your account’s profile. You can override the URL to associate other IPN listeners with specific transactions. In this case, you specify the listener’s URL when you set up a Website Payment Standard button or a PayPal API operation.)

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36934535
That sounds like a connection error, not a code error.  I believe that means that the URL you gave to Paypal for your IPN page is wrong or is not accessible.
0
 

Author Comment

by:mmalik15
ID: 36935449
this is the IPNListerner URL on my website

http://www.practicelifeintheuktest.co.uk/IPNListener.aspx

and the paypal IPN simulator i m using is present on https://developer.paypal.com/us/cgi-bin/devscr

I have specified this test url in IPN simular on the paypal website
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Expert Comment

by:sjklein42
ID: 36935710
Your IPN URL appears to be doing a 302 redirect:.  Here are the headers you're returning from http://www.practicelifeintheuktest.co.uk/IPNListener.aspx

It appears to be redirecting to itself (infinite redirect loop?):

HTTP/1.1 302 Found
Connection: close
Pragma: no-cache
cache-control: no-cache
Location: /IPNListener.aspx

Open in new window

0
 

Author Comment

by:mmalik15
ID: 36936154
thanks for the comments. Any ideas why it could be doing a 302 redirect or goes in infinite redirect loop?
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 36937211
I am not an ASP expert, so I have idea why you are getting a 302 redirect.  Even your home page URL www.practicelifeintheuktest.co.uk/  returns 302 redirect.

It is even stranger than that.  I tried it several times, and about half the time it redirects to a random folder, see below.  The random string "YhaWT" is different each time.

HTTP/1.1 302 Found
Connection: close
Pragma: no-cache
cache-control: no-cache
Location: /YhaWT/IPNListener.aspx

Open in new window


Something is wrong with the way that the domain www.practicelifeintheuktest.co.uk is set up.  Try to get it fixed so you can return a simple HTML page from that domain before trying to get your IPN URL working.
0
 

Author Comment

by:mmalik15
ID: 36937223
Try www.practicelifeintheuktest.co.uk/home.aspx to access the website. I manage to find the prob. The prb is on this line of code

if (pay_stat.Equals("Completed"))
            {
                SendEmail(user_email);
            }
 if i remove that IPN simulator returns success.

Any ideas where shall i write code to store the info in the databas coming from IPN. In the above case I tried to call a method inside

 if (strResponse == "VERIFIED")
        {
            //check the payment_status is Completed
            //check that txn_id has not been previously processed
            //check that receiver_email is your Primary PayPal email
            //check that payment_amount/payment_currency are correct
            //process payment

            // pull the values passed on the initial message from PayPal

            NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
            string user_email = these_argies["payer_email"];
            string pay_stat = these_argies["payment_status"];
            //.
            //.  more args as needed look at the list from paypal IPN doc
            //.


            if (pay_stat.Equals("Completed"))
            {
                SendEmail(user_email);
            }


            // more checks needed here specially your account number and related stuff
        }

which does not seem to work
0
 

Author Comment

by:mmalik15
ID: 36937226
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 2000 total points
ID: 36937269
Your IPN program does not appear to generate any output text.  I think it is not acceptable for a CGI script to be "silent".

Try making your IPN program always print some output text.  For example, mine prints either "VERIFIED" or "INVALID" depending on which branch it goes down.

By the way, this is the right place to update the database and/or send email, so you are on the right track.


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question