Showing results for 
Search instead for 
Did you mean: 

Assigning Response Request Field values to variables in VB.Net

I was able to submit a credit card transaction and get a response. However, I need to be able to retrieve the values of the Response Request Fields and assign them to my own custom variables.

For example:

My Custom Variable Value = Response Request Field Value

Below is my code. It is an AIM API using VB.Net.
Protected Sub Page_Load(sender As Object, e As System.EventArgs)
' By default, this sample code is designed to post to our test server for
' developer accounts:
' for real accounts (even in test mode), please make sure that you are
' posting to:
Dim post_url As String
post_url = ""
Session.Add("OrderTotal", "25.00")

Dim post_values As New Dictionary(Of String, String)
'the API Login ID and Transaction Key must be replaced with valid values
post_values.Add("x_login", Login) 
post_values.Add("x_tran_key", Transaction Key) 
post_values.Add("x_delim_data", "TRUE")
post_values.Add("x_delim_char", "|")
post_values.Add("x_relay_response", "TRUE")

'post_values.Add("x_relay_url", "")
post_values.Add("x_type", "AUTH_CAPTURE")
post_values.Add("x_method", "CC")
post_values.Add("x_card_num", "4111111111111111")
post_values.Add("x_exp_date", "0115")
post_values.Add("x_amount", "19.99")
post_values.Add("x_description", "Sample Transaction")
post_values.Add("x_first_name", "John")
post_values.Add("x_last_name", "Doe")
post_values.Add("x_address", "1234 Street")
post_values.Add("x_state", "WA")
post_values.Add("x_zip", "98004")
' Additional fields can be added here as outlined in the AIM integration
' guide at:
' This section takes the input fields and converts them to the proper format
' for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
Dim post_string As String = ""
For Each field As KeyValuePair(Of String, String) In post_values
post_string &= field.Key & "=" & HttpUtility.UrlEncode(field.Value) & "&"
post_string = Left(post_string, Len(post_string) - 1)
' The following section provides an example of how to add line item details to
' the post string. Because line items may consist of multiple values with the
' same key/name, they cannot be simply added into the above array.
' This section is commented out by default.
'Dim line_items() As String = { _
' "item1<|>golf balls<|><|>2<|>18.95<|>Y", _
' "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y", _
' "item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y"}
'For Each value As String In line_items
' post_string += "&x_line_item=" + HttpUtility.UrlEncode(value)
' create an HttpWebRequest object to communicate with
Dim objRequest As HttpWebRequest = CType(WebRequest.Create(post_url), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentLength = post_string.Length
objRequest.ContentType = "application/x-www-form-urlencoded"
' post data is sent as a stream
Dim myWriter As StreamWriter = Nothing
myWriter = New StreamWriter(objRequest.GetRequestStream())
' returned values are returned as a stream, then read into a string
Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Dim responseStream As New StreamReader(objResponse.GetResponseStream())
Dim post_response As String = responseStream.ReadToEnd()
' the response string is broken into an array
Dim response_array As Array = Split(post_response, post_values("x_delim_char"), -1)
' the results are output to the screen in the form of an html numbered list.
Message.InnerHtml += "<OL>" & vbCrLf
For Each value In response_array
Message.InnerHtml += "<LI>" & value & "&nbsp;</LI>" & vbCrLf
Message.InnerHtml += "</OL>" & vbCrLf
' individual elements of the array could be accessed to read certain response
' fields. For example, response_array(0) would return the Response Code,
' response_array(2) would return the Response Reason Code.
' for a list of response fields, please review the AIM Implementation Guide

Dim FirstName As String = Request.Form("x_first_name")
Label1.Text = FirstName
End Sub

Above is where I "seem" to be having problems. As a test I am trying to retrieve the value for Response Request Field: First Name. However Request.Form("x_first_name") is empty. Does anyone know how I can get the response values and assign them to my own variables?


The response is in the response_array array

AIM return just an array of values

For Each value In response_array
Message.InnerHtml += "<LI>" & value & "&nbsp;</LI>" & vbCrLf




I see. Thanks.