Partial Class attractions_duluth_maritime_festival
Inherits System.Web.UI.Page
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim errStr As String = ""
errStr = doAuthorize()
If errStr = "Accepted" Then
sendMail()
Else
pnlErr.Visible = True
pnlForm.Visible = False
lblErr.Text = errStr
End If
End Sub
Function doAuthorize() As String
Dim NVC As New NameValueCollection(Request.Form)
Dim objRequest As New Net.WebClient
Dim objInf As New System.Collections.Specialized.NameValueCollection(30)
Dim objRetInf As New System.Collections.Specialized.NameValueCollection(30)
Dim objRetBytes() As Byte
Dim objRetVals() As String
Dim strError As String
objInf.Add("x_version", "3.1")
objInf.Add("x_delim_data", "True")
objInf.Add("x_login", System.Configuration.ConfigurationManager.AppSettings("AuthorizeLoginID"))
objInf.Add("x_tran_key", System.Configuration.ConfigurationManager.AppSettings("AuthorizeTransactionKey"))
objInf.Add("x_relay_response", "False")
' Switch this to False once you go live
objInf.Add("x_test_request", "False")
objInf.Add("x_delim_char", ",")
objInf.Add("x_encap_char", "|")
' Billing Address
Dim splitStr() As String = NVC("CardHoldersName").Split(" ")
Dim firstStr As String = NVC("CardHoldersName")
Dim lastStr As String = NVC("CardHoldersName")
If splitStr.Length = 2 Then
firstStr = splitStr(0)
lastStr = splitStr(1)
ElseIf splitStr.Length = 3 Then
firstStr = splitStr(0)
lastStr = splitStr(2)
Else
End If
objInf.Add("x_first_name", firstStr)
objInf.Add("x_last_name", lastStr)
objInf.Add("x_address", NVC("Address"))
objInf.Add("x_city", NVC("City"))
objInf.Add("x_state", NVC("State"))
objInf.Add("x_zip", NVC("Zip"))
objInf.Add("x_country", "United States")
objInf.Add("x_phone", NVC("Phone"))
objInf.Add("x_email", NVC("Email"))
objInf.Add("x_email_customer", "TRUE")
' Shipping Address
objInf.Add("x_ship_to_first_name", firstStr)
objInf.Add("x_ship_to_last_name", lastStr)
objInf.Add("x_ship_to_address", NVC("Address"))
objInf.Add("x_ship_to_city", NVC("City"))
objInf.Add("x_ship_to_state", NVC("State"))
objInf.Add("x_ship_to_zip", NVC("Zip"))
objInf.Add("x_ship_to_country", "United States")
Dim orderDescription As String = ""
objInf.Add("x_description", orderDescription)
' Card Details
objInf.Add("x_card_num", NVC("CCN"))
objInf.Add("x_exp_date", NVC("CCExpMonth") + NVC("CCExpYear"))
' Authorization code of the card (CCV)
objInf.Add("x_card_code", NVC("CCV"))
objInf.Add("x_method", "CC")
objInf.Add("x_type", "AUTH_CAPTURE")
objInf.Add("x_amount", NVC("Total"))
' Currency setting. Check the guide for other supported currencies
objInf.Add("x_currency_code", "USD")
'Set the duplicate window to 30 seconds
objInf.Add("x_duplicate_window", "30")
Try
' Pure Test Server
'objRequest.BaseAddress = "https://certification.authorize.net/gateway/transact.dll"
' Requested testing server.
'objRequest.BaseAddress = "https://test.authorize.net/gateway/transact.dll"
' Actual Server
'(uncomment the following line and also set above Testmode=off to go live)
objRequest.BaseAddress = "https://secure.authorize.net/gateway/transact.dll"
objRetBytes = objRequest.UploadValues(objRequest.BaseAddress, "POST", objInf)
objRetVals = System.Text.Encoding.ASCII.GetString(objRetBytes).Split(",".ToCharArray())
''''''''''''''''''''''''''''''''''''''''''''
'Session.Add("ReturnString", objRetVals)
''''''''''''''''''''''''''''''''''''''''''''
If objRetVals(0).Trim(Char.Parse("|")) = "1" Then
' Returned Authorisation Code
Session("AuthorizationCode") = objRetVals(4).Trim(Char.Parse("|"))
' Returned Transaction ID
Session("TransactionID") = objRetVals(6).Trim(Char.Parse("|"))
' If selected in web.config then send seperate email to merchant.
'If Not (System.Configuration.ConfigurationManager.AppSettings("MerchantEmail") = Nothing) Then
'Call MerchantEmail(CartTable, System.Configuration.ConfigurationManager.AppSettings("MerchantEmail"))
'CustomerEmail(Session("BEmail"), System.Configuration.ConfigurationManager.AppSettings("MerchantEmail"))
'End If
Return "Accepted"
Else
strError = objRetVals(3).Trim(Char.Parse("|")) + " (" + objRetVals(2).Trim(Char.Parse("|")) + ")"
If objRetVals(2).Trim(Char.Parse("|")) = "44" Then
' CCV transaction decline
strError += "Our Card Code Verification (CCV) returned " + "the following error: "
Select Case objRetVals(38).Trim(Char.Parse("|"))
Case "N"
strError += "Card Code does not match."
Case "P"
strError += "Card Code was not processed."
Case "S"
strError += "Card Code should be on card but was not indicated."
Case "U"
strError += "Issuer was not certified for Card Code."
End Select
End If
If objRetVals(2).Trim(Char.Parse("|")) = "45" Then
If strError.Length > 1 Then
strError += "
n"
End If
' AVS transaction decline
strError += "Our Address Verification System (AVS) " + "returned the following error: "
Select Case objRetVals(5).Trim(Char.Parse("|"))
Case "A"
strError += " the zip code entered does not match " + "the billing address."
Case "B"
strError += " no information was provided for the AVS check."
Case "E"
strError += " a general error occurred in the AVS system."
Case "G"
strError += " the credit card was issued by a non-US bank."
Case "N"
strError += " neither the entered street address nor zip " + "code matches the billing address."
Case "P"
strError += " AVS is not applicable for this transaction."
Case "R"
strError += " please retry the transaction; the AVS system " + "was unavailable or timed out."
Case "S"
strError += " the AVS service is not supported by your " + "credit card issuer."
Case "U"
strError += " address information is unavailable for the " + "credit card."
Case "W"
strError += " the 9 digit zip code matches, but the " + "street address does not."
Case "Z"
strError += " the zip code matches, but the address does not."
End Select
End If
' Error!
Return strError
End If
Catch ex As Exception
' Error!
Return ex.Message + " ERROR"
Finally
End Try
End Function
Sub sendMail()
Dim PostedCollection As New NameValueCollection(Request.Form)
Dim errorFlag As Boolean
Dim errorString As String = ""
Dim i As Integer
Dim sentAt As Date = Date.Now
If (PostedCollection("submit") <> "") Then
PostedCollection.Remove("submit")
End If
If (PostedCollection("submit.x") <> "") Then
PostedCollection.Remove("submit.x")
End If
If (PostedCollection("submit.y") <> "") Then
PostedCollection.Remove("submit.y")
End If
If (PostedCollection("CCN") <> "") Then
PostedCollection.Remove("CCN")
End If
If (PostedCollection("CCExpMonth") <> "") Then
PostedCollection.Remove("CCExpMonth")
End If
If (PostedCollection("CCExpYear") <> "") Then
PostedCollection.Remove("CCExpYear")
End If
If (PostedCollection("CCV") <> "") Then
PostedCollection.Remove("CCV")
End If
Try
Dim email As New Net.Mail.MailMessage
email.To.Add(New Net.Mail.MailAddress("tickets@decc.org"))
email.To.Add(New Net.Mail.MailAddress("payment@decc.org"))
email.To.Add(New Net.Mail.MailAddress("msullivan@decc.org"))
email.To.Add(New Net.Mail.MailAddress("forms@fastersolutions.com"))
'email.To.Add(New Net.Mail.MailAddress("ross@fastersolutions.com"))
email.From = New Net.Mail.MailAddress("nobody@fastersolutions.com")
email.Subject = "Duluth Maritime Festival Form Submission"
email.IsBodyHtml = True
email.Body = ""
email.Body = "
| " + PostedCollection.GetKey(i) + ": | " + PostedCollection(i) + " |