using System; using System.Data; using System.Configuration; using System.Web; using System.Net; using System.IO; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; namespace SNGlobal { /// /// Verifies the IPN message from PayPal /// /// /// Add code under Create the IpnTransaction to process your IPN /// public class IpnHandler : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { string strFormValues = Request.Form.ToString(); string strNewValue; string strResponse; // Create the request back HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.paypal.com/cgi-bin/webscr"); // Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; strNewValue = strFormValues + "&cmd=_notify-validate"; req.ContentLength = strNewValue.Length; // Write the request back IPN strings StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(strNewValue); stOut.Close(); // Do the request to PayPal and get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); // Confirm whether the IPN was VERIFIED or INVALID. If INVALID, just ignore the IPN if (strResponse == "VERIFIED") { // Create the IpnTransaction } } } }