cancel
Showing results for 
Search instead for 
Did you mean: 

asp.net AIM Line item 1 is invalid.

I don't see what the problem is in creating the line_items. Line item 1 is invalid. Thanks in advance!

 

My code:

 

Dim stringList As New List(Of String)()

If Session("p1Name") <> "" And Session("p1Amt") <> "" Then
stringList.Add("item1<|>" & Session("p1Name") & "<|>Donation<|>1<|>" & Session("p1Amt") & "<|>")
End If
If Session("p2Name") <> "" And Session("p2Amt") <> "" Then
stringList.Add("item2<|>" & Session("p2Name") & "<|>Donation<|>1<|>" & Session("p2Amt") & "<|>")
End If
If Session("p3Name") <> "" And Session("p3Amt") <> "" Then
stringList.Add("item3<|>" & Session("p3Name") & "<|>Donation<|>1<|>" & Session("p3Amt") & "<|>")
End If
If Session("p4Name") <> "" And Session("p4Amt") <> "" Then
stringList.Add("item4<|>" & Session("p4Name") & "<|>Donation<|>1<|>" & Session("p4Amt") & "<|>")
End If
If Session("p5Name") <> "" And Session("p5Amt") <> "" Then
stringList.Add("item5<|>" & Session("p5Name") & "<|>Donation<|>1<|>" & Session("p5Amt") & "<|>")
End If
If Session("p6Name") <> "" And Session("p6Amt") <> "" Then
stringList.Add("item6<|>" & Session("p6Name") & "<|>Donation<|>1<|>" & Session("p6Amt") & "<|>")
End If
If Session("p7Name") <> "" And Session("p7Amt") <> "" Then
stringList.Add("item7<|>" & Session("p7Name") & "<|>Donation<|>1<|>" & Session("p7Amt") & "<|>")
End If
If Session("p8Name") <> "" And Session("p8Amt") <> "" Then
stringList.Add("item8<|>" & Session("p8Name") & "<|>Donation<|>1<|>" & Session("p8Amt") & "<|>")
End If

Dim line_items As String() = stringList.ToArray()

For Each value As String In line_items
post_string += "&x_line_item=" + HttpUtility.UrlEncode(value)
Next

bt99
Member
1 ACCEPTED SOLUTION

Accepted Solutions

Thanks very much for your help! You saved me a bunch of time.

 

I knew the $ could not be in the amt but it still got in. Here is my item one now, i hope this will help someone else.

 

x_line_item=item1%3c%7c%3eAll+Aboard+Westcliffe%3c%7c%3eDonation%3c%7c%3e1%3c%7c%3e10%3c%7c%3eN

View solution in original post

14 REPLIES 14

It would be easier if you post the post_string

anyway, it missing the taxable field at the end.

RaynorC1emen7
Expert

Thanks, In the post, my data is being repeated. i'll check into that.

 

post:

x_login=logincode&x_tran_key=transcode&x_delim_data=TRUE&x_delim_char=%7c&x_relay_response=FALSE&x_test_request=TRUE&x_type=AUTH_CAPTURE&x_method=CC&x_first_name=firstname&x_last_name=lastname&x_company=&x_email=address%40domain.com&x_phone=3036819012&x_address=POB+799&x_zip=81252&x_ship_to_address=POB+799&x_ship_to_city=Somecity&x_ship_to_state=CO&x_ship_to_zip=81252&x_description=Description%3a&x_amount=20.00&x_card_num=4007000000027&x_exp_date=1215&x_card_code=test&x_line_item=item1%3c%7c%3eCuster+County+Clinic%3c%7c%3eDonation%3c%7c%3e1%3c%7c%3e%2410.00%3c%7c%3eNx_login=logincode&x_tran_key=transcode&x_delim_data=TRUE&x_delim_char=%7c&x_relay_response=FALSE&x_test_request=TRUE&x_type=AUTH_CAPTURE&x_method=CC&x_first_name=firstname&x_last_name=lastname&x_company=&x_email=address%40domain.com&x_phone=3036819012&x_address=POB+799&x_zip=81252&x_ship_to_address=POB+799&x_ship_to_city=somecity&x_ship_to_state=CO&x_ship_to_zip=81252&x_description=Description%3a&x_amount=20.00&x_card_num=4007000000027&x_exp_date=1215&x_card_code=test&x_line_item=item1%3c%7c%3eCuster+County+Clinic%3c%7c%3eDonation%3c%7c%3e1%3c%7c%3e%2410.00%3c%7c%3eN&x_line_item=item2%3c%7c%3eAll+Aboard+Westcliffe%3c%7c%3eDonation%3c%7c%3e1%3c%7c%3e%2410.00%3c%7c%3eN

 

 

The

For Each value As String In line_items
post_string += "&x_line_item=" + HttpUtility.UrlEncode(value)
Next

 is wrong. that why is repeating.

 

create a new string var before the loop to add the x_line_item text

then add it to the post_string after the loop.

 

Sorry for the trouble, now I'm not getting the postback string on the page, so I can't tell if it is still doubled, but line 1 is still invalid. Maybe the best thing is to post a larger snipit of code. If you can tell me where I'm going wrong it would be most appreciated. Thanks!

 

post_values.Add("x_first_name", first_name.Text)
post_values.Add("x_last_name", last_name.Text)
post_values.Add("x_company", Company.Text)
post_values.Add("x_email", email.Text)
post_values.Add("x_phone", phone.Text)
post_values.Add("x_address", address.Text)
post_values.Add("x_zip", zip.Text)
post_values.Add("x_ship_to_address", shipAddress.Text)
post_values.Add("x_ship_to_city", shipCity.Text)
post_values.Add("x_ship_to_state", shipState.Text)
post_values.Add("x_ship_to_zip", shipZip.Text)
post_values.Add("x_description", Description.Text)
post_values.Add("x_amount", amount.Text)
post_values.Add("x_card_num", card_num.Text)
post_values.Add("x_exp_date", exp_date.Text)
post_values.Add("x_card_code", card_code.Text)

 

Dim post_string As String = ""
For Each field As KeyValuePair(Of String, String) In post_values
post_string &= field.Key & "=" & HttpUtility.UrlEncode(field.Value) & "&"
Next


Dim stringList As New List(Of String)()

If Session("p1Name") <> "" And Session("p1Amt") <> "" Then
stringList.Add("item1<|>" & Session("p1Name") & "<|>Donation<|>1<|>" & Session("p1Amt") & "<|>N")
End If
If Session("p2Name") <> "" And Session("p2Amt") <> "" Then
stringList.Add("item2<|>" & Session("p2Name") & "<|>Donation<|>1<|>" & Session("p2Amt") & "<|>N")
End If
If Session("p3Name") <> "" And Session("p3Amt") <> "" Then
stringList.Add("item3<|>" & Session("p3Name") & "<|>Donation<|>1<|>" & Session("p3Amt") & "<|>N")
End If
If Session("p4Name") <> "" And Session("p4Amt") <> "" Then
stringList.Add("item4<|>" & Session("p4Name") & "<|>Donation<|>1<|>" & Session("p4Amt") & "<|>N")
End If
If Session("p5Name") <> "" And Session("p5Amt") <> "" Then
stringList.Add("item5<|>" & Session("p5Name") & "<|>Donation<|>1<|>" & Session("p5Amt") & "<|>N")
End If
If Session("p6Name") <> "" And Session("p6Amt") <> "" Then
stringList.Add("item6<|>" & Session("p6Name") & "<|>Donation<|>1<|>" & Session("p6Amt") & "<|>N")
End If
If Session("p7Name") <> "" And Session("p7Amt") <> "" Then
stringList.Add("item7<|>" & Session("p7Name") & "<|>Donation<|>1<|>" & Session("p7Amt") & "<|>N")
End If
If Session("p8Name") <> "" And Session("p8Amt") <> "" Then
stringList.Add("item8<|>" & Session("p8Name") & "<|>Donation<|>1<|>" & Session("p8Amt") & "<|>N")
End If

 

Dim line_items As String() = stringList.ToArray()

For Each value As String In line_items
post_string += "&x_line_item=" + HttpUtility.UrlEncode(value)
Next

post_string = Left(post_string, Len(post_string) - 1)

 

' create an HttpWebRequest object to communicate with Authorize.net
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())
myWriter.Write(post_string)
myWriter.Close()

' 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()
responseStream.Close()

' 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.
resultSpan.InnerHtml += "<OL>" & vbCrLf
For Each value In response_array
resultSpan.InnerHtml += "<LI>" & value & "&nbsp;</LI>" & vbCrLf
Next
resultSpan.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

post_values.Add("x_first_name", first_name.Text)
post_values.Add("x_last_name", last_name.Text)
post_values.Add("x_company", Company.Text)
post_values.Add("x_email", email.Text)
post_values.Add("x_phone", phone.Text)
post_values.Add("x_address", address.Text)
post_values.Add("x_zip", zip.Text)
post_values.Add("x_ship_to_address", shipAddress.Text)
post_values.Add("x_ship_to_city", shipCity.Text)
post_values.Add("x_ship_to_state", shipState.Text)
post_values.Add("x_ship_to_zip", shipZip.Text)
post_values.Add("x_description", Description.Text)
post_values.Add("x_amount", amount.Text)
post_values.Add("x_card_num", card_num.Text)
post_values.Add("x_exp_date", exp_date.Text)
post_values.Add("x_card_code", card_code.Text)

Dim post_string As String = ""
For Each field As KeyValuePair(Of String, String) In post_values
post_string &= field.Key & "=" & HttpUtility.UrlEncode(field.Value) & "&"
Next
post_string = Left(post_string, Len(post_string) - 1)

Dim stringList As New List(Of String)()
If Session("p1Name") <> "" And Session("p1Amt") <> "" Then
stringList.Add("item1<|>" & Session("p1Name") & "<|>Donation<|>1<|>" & Session("p1Amt") & "<|>N")
End If
If Session("p2Name") <> "" And Session("p2Amt") <> "" Then
stringList.Add("item2<|>" & Session("p2Name") & "<|>Donation<|>1<|>" & Session("p2Amt") & "<|>N")
End If
If Session("p3Name") <> "" And Session("p3Amt") <> "" Then
stringList.Add("item3<|>" & Session("p3Name") & "<|>Donation<|>1<|>" & Session("p3Amt") & "<|>N")
End If
If Session("p4Name") <> "" And Session("p4Amt") <> "" Then
stringList.Add("item4<|>" & Session("p4Name") & "<|>Donation<|>1<|>" & Session("p4Amt") & "<|>N")
End If
If Session("p5Name") <> "" And Session("p5Amt") <> "" Then
stringList.Add("item5<|>" & Session("p5Name") & "<|>Donation<|>1<|>" & Session("p5Amt") & "<|>N")
End If
If Session("p6Name") <> "" And Session("p6Amt") <> "" Then
stringList.Add("item6<|>" & Session("p6Name") & "<|>Donation<|>1<|>" & Session("p6Amt") & "<|>N")
End If
If Session("p7Name") <> "" And Session("p7Amt") <> "" Then
stringList.Add("item7<|>" & Session("p7Name") & "<|>Donation<|>1<|>" & Session("p7Amt") & "<|>N")
End If
If Session("p8Name") <> "" And Session("p8Amt") <> "" Then
stringList.Add("item8<|>" & Session("p8Name") & "<|>Donation<|>1<|>" & Session("p8Amt") & "<|>N")
End If

Dim line_items As String() = stringList.ToArray()
For Each value As String In line_items
post_string += "&x_line_item=" + HttpUtility.UrlEncode(value)
Next

Did see why it woun't have any postback data, can't you debug it and see what in post_string before you send it?

 

 

 

Sorry, I still can't see a post string to debug.

it crash? not maybe you need to step thru it line by line.

No error other than 

  1. 270 
  2. (TESTMODE) Line item 1 is invalid. 

Still working on it...

Reverting back to the authorize.net demo code, default.aspx, and adding an email address, I get the line items in an email but no post string.