Guest User

Untitled

a guest
Apr 30th, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. ' ASP.NET VB
  2.  
  3. Imports System.Net
  4. Imports System.Net.Mail
  5. Imports System.IO
  6. Imports System.Data
  7. Imports System.Data.SqlClient
  8.  
  9. Public Class WebForm7
  10. Inherits System.Web.UI.Page
  11.  
  12. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  13. 'Post back to either sandbox or live
  14. Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
  15. Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
  16. Dim req As HttpWebRequest = CType(WebRequest.Create(strSandbox), HttpWebRequest)
  17.  
  18. 'Set values for the request back
  19. req.Method = "POST"
  20. req.ContentType = "application/x-www-form-urlencoded"
  21. Dim Param() As Byte = Request.BinaryRead(HttpContext.Current.Request.ContentLength)
  22. Dim strRequest As String = Encoding.ASCII.GetString(Param)
  23. strRequest = strRequest + "&cmd=_notify-validate"
  24. req.ContentLength = strRequest.Length
  25.  
  26. 'for proxy
  27. 'Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
  28. 'req.Proxy = proxy
  29.  
  30. 'Send the request to PayPal and get the response
  31. Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
  32. streamOut.Write(strRequest)
  33. streamOut.Close()
  34.  
  35. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
  36.  
  37. Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
  38. Dim strResponse As String = streamIn.ReadToEnd()
  39. streamIn.Close()
  40.  
  41. If strResponse = "VERIFIED" Then
  42. 'check the payment_status is Completed
  43. 'check that txn_id has not been previously processed
  44. 'check that receiver_email is your Primary PayPal email
  45. 'check that payment_amount/payment_currency are correct
  46. 'process payment
  47. Response.Write("<script language=javascript>alert('success!');</script>")
  48. ElseIf strResponse = "INVALID" Then
  49. 'log for manual investigation
  50. Response.Write("<script language=javascript>alert('error1!');</script>")
  51. Else
  52. 'Response wasn't VERIFIED or INVALID, log for manual investigation
  53. Response.Write("<script language=javascript>alert('error2!');</script>")
  54. End If
  55. End Sub
  56. End Class
Advertisement
Add Comment
Please, Sign In to add comment