-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPayment.aspx.vb
More file actions
71 lines (56 loc) · 2.99 KB
/
Payment.aspx.vb
File metadata and controls
71 lines (56 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Imports System.Net
Imports System.IO
Partial Class Payment
Inherits System.Web.UI.Page
Protected Sub submitButton_Click(sender As Object, e As EventArgs) Handles submitButton.Click
Dim post_values As New Dictionary(Of String, String)
post_values.Add("x_card_num", ccField.Text)
post_values.Add("x_amount", amountField.Text)
post_values.Add("x_login", "7YguC74tk") ' your login ID
post_values.Add("x_tran_key", "5vy8U598pQmz4vU7") ' your transaction key
post_values.Add("x_delim_data", "TRUE")
post_values.Add("x_delim_char", ",")
post_values.Add("x_relay_response", "FALSE")
post_values.Add("x_type", "AUTH_CAPTURE")
post_values.Add("x_method", "CC")
post_values.Add("x_exp_date", "0118")
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")
' test server
Dim post_url As String = "https://test.authorize.net/gateway/transact.dll"
' converts them to the proper format "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) & "&"
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"
' send the data in a stream
Dim myWriter As StreamWriter = Nothing
myWriter = New StreamWriter(objRequest.GetRequestStream())
myWriter.Write(post_string)
myWriter.Close()
' create an HttpWebRequest object to process the returned values in a stream and convert it 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()
' break the response string 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.
Response.Write("<OL>")
For Each value In response_array
Response.Write("<LI>" & value & " </LI>" & vbCrLf)
'resultSpan.InnerHtml += "<LI>" & value & " </LI>" & vbCrLf
Next
Response.Write("</OL>")
End Sub
End Class