Payment Gateway Integration using VB.NET with Authorized.NET

To understand how credit card processes have a look at following steps:

Step 1: The merchant submits a credit card transaction to the Authorize.Net Payment Gateway on behalf of a customer via secure connection from a Web site, at retail, from a MOTO center or a wireless device.

Step 2: Authorize.Net receives the secure transaction information and passes it via a secure connection to the Merchant Bank's Processor.

Step 3: The Merchant Bank's Processor submits the transaction to the Credit Card Interchange (a network of financial entities that communicate to manage the processing, clearing, and settlement of credit card transactions).

Step 4: The Credit Card Interchange routes the transaction to the customer's Credit Card Issuer.

Step 5: The Credit Card Issuer approves or declines the transaction based on the customer's available funds and passes the transaction results, and if approved, the appropriate funds, back through the Credit Card Interchange.

Step 6: The Credit Card Interchange relays the transaction results to the Merchant Bank's Processor.

Step 7: The Merchant Bank's Processor relays the transaction results to Authorize.Net.

For more details please visit to http://www.authorize.net/resources/howitworksdiagram/

Following code can be integrated at the final step, when you are done with the shopping and submitting your order, in the zip file you will find some of the default values are assigned to the form fields, you can assign your own values as per the requirement, and go through the documentation as mentioned in the above url.

Make sure that you have added reference of MsXML to the project and you or your client have merchant ID with authorized.net. You can change code as per the login info of merchant ID.

While submitting a form you submit values for the following fields

1. x_Description
2. x_Amount
3. x_Card_Num
4. x_Exp_Date
5. x_First_Name
6. x_Last_Name
7. x_Address
8. x_City
9. x_State
10. x_ZIP
11. x_Phone
12. x_Fax
13. x_Email

Using XMLHttpRequest object post the data to the respective URL as below:

XMLReq.open("POST", "
https://secure.authorize.net/gateway/transact.dll?" & PostData & "", False)
XMLReq.send()

I have also trapped the response code to know the status of transaction.

Response Code:

1 = This transaction has been approved.
2 = This transaction has been declined.
3 = There has been an error processing this transaction.

The entire code snippet as below which is called on submit of button from the form.

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

'First enter our loginID'

Dim PostData As String

'test account for Authorize.Net

PostData = "x_Login=test"

PostData = PostData & "&x_Version=3.1"

'since we are testing

PostData = PostData & "&x_Test_Request=TRUE"

'we want comma delimited

PostData = PostData & "&x_ADC_Delim_Data=TRUE"

'do not want to redirect

PostData = PostData & "&x_ADC_URL=FALSE"

'Now add the form fields

PostData = PostData & "&x_Card_Num=" & Request.Form("x_Card_Num") & ""

PostData = PostData & "&x_Exp_Date=" & Request.Form("x_Exp_Date") & ""

PostData = PostData & "&x_Description=" & Request.Form("x_Description") & ""

PostData = PostData & "&x_Amount=" & Request.Form("x_Amount") & ""

PostData = PostData & "&x_First_Name=" & Request.Form("x_First_Name") & ""

PostData = PostData & "&x_Last_Name=" & Request.Form("x_Last_Name") & ""

PostData = PostData & "&x_company=" & Request.Form("x_company") & ""

PostData = PostData & "&x_Address=" & Request.Form("x_Address") & ""

PostData = PostData & "&x_City=" & Request.Form("x_City") & ""

PostData = PostData & "&x_State=" & Request.Form("x_State") & ""

PostData = PostData & "&x_ZIP=" & Request.Form("x_ZIP") & ""

PostData = PostData & "&x_Phone=" & Request.Form("x_Phone") & ""

PostData = PostData & "&x_Fax=" & Request.Form("x_Fax") & ""

PostData = PostData & "&x_Email=" & Request.Form("x_Email") & ""

 

Dim XMLReq As New MSXML.XMLHTTPRequest

Dim strURL As String

Dim tempstr As String

Dim strStatus As Integer

Dim strRetval As String

Dim strArrayVal As Array

Dim x_response_code As String

Dim x_Description As String

Dim x_Amount As String

 

XMLReq = New MSXML.XMLHTTPRequest

PostData = PostData & "&x_Password=jvette1"

XMLReq.open("POST", "https://secure.authorize.net/gateway/transact.dll?" & PostData & "", False)

XMLReq.send()

strStatus = XMLReq.status

strRetval = XMLReq.responseText

strArrayVal = Split(strRetval, ",", -1)

'Response Code:

'1 = This transaction has been approved.

'2 = This transaction has been declined.

'3 = There has been an error processing this transaction.

Dim x_response_subcode As String

Dim x_response_reason_code As String

Dim x_response_reason_text As String

Dim x_auth_code As String

Dim x_avs_code As String

Dim x_trans_id As String

Dim x_invoice_num As String

Dim x_country As String

Dim x_method As String

Dim x_type As String

Dim x_cust_id As String

Dim x_company As String

Dim x_First_Name As String

Dim x_Last_Name As String

Dim x_Address As String

Dim x_City As String

Dim x_State As String

Dim x_ZIP As String

Dim x_Phone As String

Dim x_Fax As String

Dim x_Email As String

 

x_response_code = strArrayVal(0)

x_response_subcode = strArrayVal(1)

x_response_reason_code = strArrayVal(2)

x_response_reason_text = strArrayVal(3)

'6 digit approval code

x_auth_code = strArrayVal(4)

x_avs_code = strArrayVal(5)

'transaction id

x_trans_id = strArrayVal(6)

x_invoice_num = strArrayVal(7)

x_Description = strArrayVal(8)

x_Amount = strArrayVal(9)

x_method = strArrayVal(10)

x_type = strArrayVal(11)

x_cust_id = strArrayVal(12)

x_First_Name = strArrayVal(13)

x_Last_Name = strArrayVal(14)

x_company = strArrayVal(15)

x_Address = strArrayVal(16)

x_City = strArrayVal(17)

x_State = strArrayVal(18)

x_ZIP = strArrayVal(19)

x_country = strArrayVal(20)

x_Phone = strArrayVal(21)

x_Fax = strArrayVal(22)

x_Email = strArrayVal(23)

'Check the ErrorCode to make sure that the component was able to talk

'to the authorization network

If (strStatus <> 200) Then

Response.Write("An error has occured during processing your request. " & "Please try again later." &
strStatus)

Else

If x_response_code.Equals("1") Then

Response.Write("Thank you for your purchase.(Transaction has been approved)")

ElseIf x_response_code.Equals("2") Then

Response.Write("Transaction has been declined")

Else

Response.Write("There has been error while processing this transaction." & "Please try again later."
& x_response_code)

End If

End If

End Sub