locked
Really Simple way to charge peoples credit cards via Authorize.net! RRS feed

  • Question

  • User635479908 posted

    Hey all, with some help of authorize.net's sample code, i figured i'd share what i write with the class :)

     

     

    Imports System.IO
    Imports System.Net

    Private Function readHtmlPage(ByVal url As String) As [String]
    Dim result As [String] = ""
    Dim strPost As [String] = "x_login=Login_Goes_Here&x_tran_key=TransKey_Goes_Here&x_method=CC&x_type=AUTH_CAPTURE&x_amount=" & txtAmount.Text & "&x_delim_data=TRUE&x_delim_char=,&x_relay_response=FALSE&x_card_num=" & txtCCno.Text & "&x_exp_date=" & txtCCexp.Text & "&x_test_request=TRUE&x_version=3.1"
    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())
    lblResponse.Text = ""
    lblResponse.Text = sr.ReadLine
    lblResponse.Text = Left(lblResponse.Text, 5)

    If lblResponse.Text = "1,1,1" Then

    'Do whatever i gotta do, cause i got my cash!!


    End If
    If lblResponse.Text = "2,2,2" Then
    errLabel.Text = "The Transaction has been Declined"
    End If
    If lblResponse.Text = "2,2,3" Then
    errLabel.Text = "The Transaction has been Declined"
    End If
    If lblResponse.Text = "2,2,4" Then
    errLabel.Text = "The Transaction has been Declined"
    End If
    If lblResponse.Text = "3,1,5" Then
    errLabel.Text = "You must enter a valid amount."
    End If
    If lblResponse.Text = "3,1,6" Then
    errLabel.Text = "The Credit Card Number is Invald. Plase make sure the number is correct."
    End If
    If lblResponse.Text = "3,2,3" Then
    errLabel.Text = "The Expiration date is invalid. Please check the numbers and try again."
    End If
    If lblResponse.Text = "3,1,1" Then
    errLabel.Text = "This is a Duplicate Transaction"
    End If
    If lblResponse.Text = "3,1,7" Then
    errLabel.Text = "Expiration date is not valid."
    End If
    If lblResponse.Text = "3,2,1" Then
    errLabel.Text = "An error occurred during processing. Please try again in 5 minutes."
    End If
    If lblResponse.Text = "3,2,2" Then
    errLabel.Text = "An error occurred during processing. Please try again in 5 minutes."
    End If
    If lblResponse.Text = "3,2,3" Then
    errLabel.Text = "An error occurred during processing. Please try again in 5 minutes."
    End If
    If lblResponse.Text = "3,2,5" Then
    errLabel.Text = "An error occurred during processing. Please try again in 5 minutes."
    End If
    If lblResponse.Text = "3,2,6" Then
    errLabel.Text = "An error occurred during processing. Please try again in 5 minutes."
    End If
    If lblResponse.Text = "2,2,7" Then
    errLabel.Text = "The address entered doe

    ' Close and clean up the StreamReader
    sr.Close()
    Return result
    End Function 'readHtmlPage

      

     

       Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    readHtmlPage("https://secure.authorize.net/gateway/transact.dll")
    End Sub
      
    Wednesday, September 12, 2007 7:05 PM

All replies

  • User-1367805312 posted

    Thanks for sharing that... I might use it on a project, saves me having to figure it all out [:D]  ..

    Friday, October 5, 2007 2:52 PM
  • User635479908 posted

    No prob!!

    Monday, October 8, 2007 2:20 PM