Link to home
Start Free TrialLog in
Avatar of dhiraj79
dhiraj79

asked on

Pay pal IPN Integration

Hi all,

I read on pay pal site that IPN CAN BE USED FOR

 

1.notify your server every time a new transaction occurs

2. if the status of a prior transaction changes, use IPN

 

I want to know that suppose someone paid on my website and due to any reason the payment statuse is pending at the moment(Say if verification is enabled).

Now on my return page Page_ load I will get pending and update my database accordingly.

The user will not be able to use the paid service till the payment status is "completed " in my database.

 

Now suppose the payment status is completed after one hour.

How the pay pal will notify me so that I can give the user paid services.

 

Thanks
Avatar of oleggold
oleggold
Flag of United States of America image

in vb.net,good for asp.net 2
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://urlort#");
 
//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
 
}
 
}
 
 

Open in new window

Avatar of dhiraj79
dhiraj79

ASKER

Thanks for the reply
Can I use .ashx (httpHandler) page as IPNLISTENER?
ASKER CERTIFIED SOLUTION
Avatar of wcfguru
wcfguru

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial