I am making a website that has a Buy Now button. Once the user confirms the payment to be made, PayPal uses a notification text stream that is sent to my site. If my notification page gets the stream and if hasn't been altered you can make it do things on the
db side or whatever. then that stream is sent back to Paypal where the user is then redirected to the completed page.
Here's my trouble; If the response from PayPal is verified, I want to run a little task against the DB to allow the information the user paid for to now be viewable to all visitors. In that, I use a session variable to store the record ID of the data the user
entered. But the notification page seems to be completely ignoring my session variables. Everything else works as it should
In the example below, the session variables are being used for testing. I was using them to see where the page was breaking. The values are to be displayed on another page. Also, this page will only send an email with the whole IPN text. I don't have my db
code setup on this example.
Why would the page not assign the text values to the session variables?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Session("test1") = "Page load is good"
'Read in IPN POST Dim strFormValues As String = Encoding.ASCII.GetString(Request.BinaryRead(Request.ContentLength)) Dim strNewValue
' Create the request back Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"), _ HttpWebRequest)
' 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 Dim stOut As StreamWriter = New StreamWriter(req.GetRequestStream(), _ Encoding.ASCII) stOut.Write(strNewValue) stOut.Close()
'send the request, read the response Dim strResponse As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse) Dim IPNResponseStream As Stream = strResponse.GetResponseStream Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8") Dim readStream As New StreamReader(IPNResponseStream, encode)
Dim read(256) As [Char] ' Reads 256 characters at a time.
Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0 ' Dumps the 256 characters to a string and displays the string to the console. Dim IPNResponse As New [String](read, 0, count) count = readStream.Read(read, 0, 256)
' if IPN response was VERIFIED..perform VERIFIED handling 'for this example - send email of raw IPN string
If IPNResponse = "VERIFIED" Then Session("test2") = "It hit the verified"
Dim myEmail As New MailMessage myEmail.To.Add("user@domainname.com") myEmail.From = New MailAddress(String.Format("{0} <{1}>", "domainname.com", "noreply@domainname.com")) myEmail.Body = strNewValue myEmail.Subject = "IPN VERIFIED test" Dim client As New System.Net.Mail.SmtpClient() client.Credentials = New System.Net.NetworkCredential("user@domainname.com", "password") client.Send(myEmail)
Else
' if IPN is INVALID 'log and manually investigate
Session("test3") = "It hit the invalid"
Dim myEmail As New MailMessage myEmail.To.Add("user@domainname.com") myEmail.From = New MailAddress(String.Format("{0} <{1}>", "domainname.com", "noreply@domainname.com")) myEmail.Body = strNewValue myEmail.Subject = "IPN INVALID test" Dim client As New System.Net.Mail.SmtpClient() client.Credentials = New System.Net.NetworkCredential("user@domainname.com", "password") client.Send(myEmail) End If End While
'tidy up, close streams readStream.Close() strResponse.Close()
flipknob
Member
22 Points
79 Posts
PayPal IPN and Session variables
Jan 22, 2009 03:56 PM|LINK
Hello,
I am making a website that has a Buy Now button. Once the user confirms the payment to be made, PayPal uses a notification text stream that is sent to my site. If my notification page gets the stream and if hasn't been altered you can make it do things on the db side or whatever. then that stream is sent back to Paypal where the user is then redirected to the completed page.
Here's my trouble; If the response from PayPal is verified, I want to run a little task against the DB to allow the information the user paid for to now be viewable to all visitors. In that, I use a session variable to store the record ID of the data the user entered. But the notification page seems to be completely ignoring my session variables. Everything else works as it should
In the example below, the session variables are being used for testing. I was using them to see where the page was breaking. The values are to be displayed on another page. Also, this page will only send an email with the whole IPN text. I don't have my db code setup on this example.
Why would the page not assign the text values to the session variables?
-----------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------
"Load Balaned" "Web Farm" "Fail-Over" "Session Variables" session problem session not set .Net 2.0 session loss session conflict session asp.net