Implementing Authorize.Net

Mar 28 2006 2:08 PM

Im having trouble with my script to link my form to authorize.net, I would greatly appreicat any input or help.


<script language="VB" runat="server">
  Sub Page_Load(Src As [Object], E As EventArgs)
   'myPage.Text = readHtmlPage("https://test.authorize.net/gateway/transact.dll")
   'Uncomment the line ABOVE for shopping cart testing OR uncomment the line BELOW for live accounts
   myPage.Text = readHtmlPage("https://secure.authorize.net/gateway/transact.dll")
End Sub 'Page_Load


Private Function readHtmlPage(url As String) As [String]
   Dim result As [String] = ""
   Dim strPost As [String] =
    "x_login=MID686003012485954" & _
    "&x_tran_key=zixtZu2AVDLzGnZv" & _
    "&x_method=CC&x_type=AUTH_CAPTURE&x_delim_data=TRUE" & _
    "&x_delim_char=|&x_relay_response=FALSE&x_test_request=FASLE&x_version=3.1" & _
    "&x_amount=" & System.Web.HttpUtility.UrlEncode(x_amount)  & _
    "&x_card_num=" & System.Web.HttpUtility.UrlEncode(x_card_num.Text.Trim) & _
    "&x_exp_date=" & System.Web.HttpUtility.UrlEncode(x_exp_date.Text.Trim) & _
    "&x_card_code=" & System.Web.HttpUtility.UrlEncode(x_card_code.Text.Trim) & _
    "&x_first_name=" & System.Web.HttpUtility.UrlEncode(x_first_name.Text.Trim) & _
    "&x_last_name=" & System.Web.HttpUtility.UrlEncode(x_last_name.Text.Trim) & _
    "&x_address=" & System.Web.HttpUtility.UrlEncode(x_address.Text.Trim) & _
    "&x_city=" & System.Web.HttpUtility.UrlEncode(x_city.Text.Trim) & _
    "&x_state=" & System.Web.HttpUtility.UrlEncode(x_state.Text.Trim) & _
    "&x_zip=" & System.Web.HttpUtility.UrlEncode(x_zip.Text.Trim)"


   Dim myWriter As StreamWriter = Nothing
  
   Dim objRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
   objRequest.Method = "POST"
   objRequest.ContentLength = strPost.Length
   objRequest.ContentType = "application/x-www-form-urlencoded"
  
   Try
      myWriter = New StreamWriter(objRequest.GetRequestStream())
      myWriter.Write(strPost)
   Catch e As Exception
      Return e.Message
   Finally
      myWriter.Close()
   End Try
  
   Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
   Dim sr As New StreamReader(objResponse.GetResponseStream())
      result = sr.ReadToEnd()
     
      ' Close and clean up the StreamReader
      sr.Close()
   Return result
End Function 'readHtmlPage
</script>