dhiraj79
asked on
Pay pal IPN(instant payment notification) Implementation
Hi ALL
I am Implementing Paypal IPN IN ASP.NET and C# website.
If any one has done this plese give me the code to check the validity of order once the Paypal IPN sends the response as VERIFIED.
After that How to validate various order fields .
Like order cost, Oder no , Transaction nop etc....
I am using the follwing code but it is giving response to "INVALID"
ALSO hOW TO CHECK
//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_cur rency are correct
//process payment
etc.
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
public partial class csIPNexample : System.Web.UI.Page
{
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(st rSandbox);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-ur lencoded";
byte[] param = Request.BinaryRead(HttpCon text.Curre nt.Request .ContentLe ngth);
string strRequest = Encoding.ASCII.GetString(p aram);
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.GetReques tStream(), System.Text.Encoding.ASCII );
streamOut.Write(strRequest );
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetRespon se().GetRe sponseStre am());
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_cur rency are correct
//process payment
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}
I am Implementing Paypal IPN IN ASP.NET and C# website.
If any one has done this plese give me the code to check the validity of order once the Paypal IPN sends the response as VERIFIED.
After that How to validate various order fields .
Like order cost, Oder no , Transaction nop etc....
I am using the follwing code but it is giving response to "INVALID"
ALSO hOW TO CHECK
//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_cur
//process payment
etc.
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
public partial class csIPNexample : System.Web.UI.Page
{
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
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-ur
byte[] param = Request.BinaryRead(HttpCon
string strRequest = Encoding.ASCII.GetString(p
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.GetReques
streamOut.Write(strRequest
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetRespon
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_cur
//process payment
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.