Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using beautiful article "http://www.codeproject.com/Tips/84538/Setting-up-PayPal-Instant-Payment-Notification-IPN.aspx?fid=1573899&df=90&mpp=25&noise=3&sort=Position&view=Quick[^]"

I have created sandbox accounts, sandbox seller, ipn_pal.htm, set the ipn url to match, gone to the ipn test site, every time I get HTTP Error 405 Method Not Allowed.

I went back to the original paypal code and removed all the good stuff... same error.

Paypal says it's the host that has the problem. The host has never seen the problem before. I have tried it on another site (different host), same problem.

Please tell me what I've done wrong! Thanks!!!!

I have it stripped down to this:

XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#"    %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Text" %>
<%@ Import Namespace = "System.Net" %>
<%@ Import Namespace = "System.Web" %>

<script type="text/javascript" Language="JavaScript">
//Some JavaScript you may need goes here
</script>
<script Language="C#" Option="Explicit" type="text/C#"  runat="server">

protected void Page_Load(object sender, EventArgs e)
{
//Post back to either sandbox or live
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);
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
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
  // --- end of page load --
</script>

<html>
<head runat="server" >
<title>IPN PayPal</title>
</head>
<body runat="server">
<label id="debuggy" runat="server"/>
<h2> my test page</h2>
Load this first to check the syntax of your page
</body>
</html>
Posted
Comments
Nathan St 7-Oct-10 11:07am    
Is there a reason you're specifically using ASCII instead of Unicode? If the request to your page has any unicode characters, that might be messing things up :)
Metrakay 7-Oct-10 11:58am    
Not really, I just did a copy/paste. Both the link above and Paypal's sample code had it.

1 solution

This code works fine for me.

405 errors often arise with the POST method, however not all ISPs allow the POST method necessary to process the request.
All 405 errors can be traced to configuration of the Web server and security governing access to the content of the Web site, so should easily be explained by your ISP.

As the code you have posted is the same as outlined here[^] on the paypal site I would have a talk with the hosts and get them to investigate, other than that you may want to look into if you need to use a proxy and uncomment the proxy section of the code, replacing the "url:port#" part with the correct proxy information (if you need to use a proxy that is).
 
Share this answer
 
Comments
Metrakay 7-Oct-10 11:58am    
That's what I thought, I was just hoping I was wrong and that I had done something stupid...

I had tried both sets of code to try to eliminate any errors on my end.

Thank you for your help!

I have forwarded this information to the host.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900