All pastes #332270 Raw Edit

Miscellany

public text v1 · immutable
#332270 ·published 2007-01-29 21:30 UTC
rendered paste body
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
{

    /// <summary>
    /// Verifies the IPN message from PayPal
    /// </summary>
    /// <remarks>
    /// Add code under Create the IpnTransaction to process your IPN
    /// </remarks>
    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

            }
        }
    }


}