Imports LawSubLibrary
Imports System.Net
Imports System.Data.SqlClient
Imports System.Data
Imports System.Collections.Generic
Imports System.IO
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Partial Class checkout
Inherits System.Web.UI.Page
Dim oAppearances As New Appearances
Dim oAppearancesDAO As New AppearancesDAO
Dim oUser As New User
Dim oUserDAO As New UserDAO
Dim ButtonClicked As Boolean = False
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("User") Is Nothing Then
Response.Redirect("Home.aspx")
End If
breadcrumbs.Text = " > My Cart > Check Out"
If Not Page.IsPostBack Then
BindCart()
With ddSameAddress
.DataSource = oUserDAO.PopulateAddress(Session("User"))
.DataValueField = "Address1"
.DataTextField = "Address1"
.DataBind()
.Items.Insert(0, "-- [ Select Address ] --")
End With
End If
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
' By default, this sample code is designed to post to our test server for
' developer accounts: https://test.authorize.net/gateway/transact.dll
' for real accounts (even in test mode), please make sure that you are
' posting to: https://secure.authorize.net/gateway/transact.dll
Dim post_url As String
post_url = "https://test.authorize.net/gateway/transact.dll"
Dim post_values As New Dictionary(Of String, String)
'the API Login ID and Transaction Key must be replaced with valid values
'
'MERCHANT INFO
' NOTE: I know I promised to keep this sample as simple as possible.
' However, storing the Authorize.net login and transaction keys in the .vb code-behind makes me nervous.
' That's why they're stored in the web.config instead as AppSettings.
' IIS/ASP.NET goes to greater lengths to protect the web.config file.
post_values.Add("x_login", ConfigurationManager.GetSection("DSAppSettings")("AuthorizeNetLogin"))
post_values.Add("x_tran_key", ConfigurationManager.GetSection("DSAppSettings")("AuthorizeNetTransactionKey"))
If rdoCC.Checked Then
If txtCardno.Text = String.Empty Then
ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('Credit card is missing.');", True)
Else
If txtcvv.Text = String.Empty Then
ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('CVV is missing.');", True)
Else
'TRANSACTION INFO
' Toggling between "TRUE" and "FALSE" for the "x_test_request" values is the equivalent to logging into "Mechant Login" and switching between "TEST" and "LIVE" modes.
' Changing the "x_test_request" value is much quicker than logging into the account, however.
' Note that submissions performed while in Test mode will not show up as a transaction in Authorize.net.
' After changing to LIVE mode, your transactions will show up. You'll have to use a real credit card though, not the 4111111111111111 test number.
' To find the transactions in LIVE mode, go to "Unsettled Transactions". Be sure to void your test transactions too (before that day's "settlement" time).
post_values.Add("x_invoice_num", Session("AppearanceID"))
post_values.Add("x_version", "3.0") 'The AIM Developer guide says it's best to explicitly set this instead of relying on the default value
post_values.Add("x_type", "AUTH_CAPTURE")
post_values.Add("x_delim_data", "TRUE")
post_values.Add("x_delim_char", "|")
post_values.Add("x_relay_response", "FALSE")
post_values.Add("x_method", "CC")
'CUSTOMER INFO
post_values.Add("x_card_num", txtCardno.Text) 'This is the "special" test number for VISA
post_values.Add("x_card_code", txtcvv.Text)
post_values.Add("x_exp_date", ddlMonth.SelectedItem.Value & ddlYear.SelectedItem.Value)
post_values.Add("x_amount", lbTotal.Text)
post_values.Add("x_description", "Law Sub Appearance")
post_values.Add("x_cust_id", Session("User"))
post_values.Add("x_first_name", txtFirst.Text)
post_values.Add("x_last_name", txtLast.Text)
post_values.Add("x_address", txtAddress.Text & " " & txtAddressContinued.Text)
post_values.Add("x_country", txtCountry.Text)
post_values.Add("x_state", txtStates.Text)
post_values.Add("x_zip", txtZip.Text)
' Additional fields can be added here as outlined in the AIM integration
' guide at: http://developer.authorize.net
' 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) & "&"
Next
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)
'Next
' 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)
If response_array(0) = 1 Then
divCheckout.Style.Add("display", "none")
divCheckOutpage.Style.Add("display", "block")
'check out results
Dim oUser As New User
oUser = oUserDAO.RetrieveUserFromUserID(Session("User"))
lbFirstName.Text = oUser.sFirstName
lbEmail.Text = oUser.sEmail
lbBillAddress.Text = oUser.sAddress1 & " " & oUser.sAddress2 & "
" & oUser.sCity & ", " & oUser.sState & " " & oUser.sZip
lbBillPhone.Text = oUser.sCellPhone
lbGranTotal.Text = lbTotal.Text
lbPayment.Text = response_array(10)
lbOrderNumber.Text = Session("AppearanceID")
lbOrderDate.Text = Now()
If Session("Discount") = True Then
lbCoupon.Text = "-$20.00"
lbSubtotal.Text = "$" & lbTotal.Text + 20
Else
lbCoupon.Text = "-$0.00"
lbSubtotal.Text = lbTotal.Text
End If
If Session("SpecialDiscount") = True Then
lbCoupon.Text = "Speacial Discount"
lbSubtotal.Text = lbTotal.Text
End If
lbOrderTotal.Text = lbTotal.Text
BindCartCheckOut()
' 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
For Each gv As GridViewRow In gwCart.Rows
Dim exAppearances = New Appearances
exAppearances = oAppearancesDAO.RetrieveAppearancesFromAppearanceID(gv.Cells(1).Text)
Dim iReturnedID As Integer
oAppearances = New Appearances
oAppearances.iAppearnceID = exAppearances.iAppearnceID
oAppearances.iUserID = exAppearances.iUserID
oAppearances.sCaseName = exAppearances.sCaseName
oAppearances.sPartyRep = exAppearances.sPartyRep
oAppearances.sCourtHouse = exAppearances.sCourtHouse
oAppearances.sCounty = exAppearances.sCounty
oAppearances.sAddress = exAppearances.sAddress
oAppearances.sRoom = exAppearances.sRoom
oAppearances.sAppearanceType = exAppearances.sAppearanceType
oAppearances.sCaseType = exAppearances.sCaseType
oAppearances.sIndexNumber = exAppearances.sIndexNumber
oAppearances.sJudgePart = exAppearances.sJudgePart
oAppearances.sInstructions = exAppearances.sInstructions
oAppearances.sNotification = exAppearances.sNotification
oAppearances.sAppearance = exAppearances.sAppearance
oAppearances.sAppearanceTime = exAppearances.sAppearanceTime
oAppearances.blnPostedAppearance = True
oAppearances.blnAcceptedAppearance = exAppearances.blnAcceptedAppearance
oAppearances.blnPendingAppearance = exAppearances.blnPendingAppearance
oAppearances.dtDatedAdded = exAppearances.dtDatedAdded
iReturnedID = oAppearancesDAO.InsertUpdateAppearances(oAppearances, iAddUpdateIn:=1)
oUser = New User
oUser.blnIsUsed = True
oUserDAO.UpdateCouponCode(Session("User"), True)
Session("Discount") = False
Session("SpecialDiscount") = False
Next
ElseIf response_array(0) = 2 Or response_array(0) = 3 Then
ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('Your transactions has been declined. Please make sure your card number and expiration date are correct.');", True)
End If
If response_array(0) = 4 Then
ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('Your transactions has been held for review.');", True)
End If
'now the appearance has been posted
ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('" & response_array(3) & "');", True)
End If
End If
ElseIf rdoPP.Checked Then
Dim oUser As New User
oUser = oUserDAO.RetrieveUserFromUserID(Session("User"))
post_values.Add("x_method", "ECHECK")
Session("totalShoppingAmt") = lbTotal.Text
Session("regemail") = oUser.sEmail
Session("orderID") = Session("AppearanceID")
Response.Redirect("sendpayment.aspx")
End If
End Sub
Public Sub BindCart()
Dim aCartList As New List(Of Appearances)
Dim dtCart As New DataTable
Dim CartRow As DataRow
aCartList = New List(Of Appearances)
aCartList = oAppearancesDAO.PopulateAppreanceGrid(Session("User"))
dtCart = New DataTable
dtCart.Columns.Add("CaseName", GetType(String))
dtCart.Columns.Add("AppearanceID", GetType(Integer))
dtCart.Columns.Add("Total", GetType(String))
For Each oAppearances As Appearances In aCartList
CartRow = dtCart.NewRow
CartRow("CaseName") = oAppearances.sCaseName
CartRow("AppearanceID") = oAppearances.iAppearnceID
CartRow("Total") = "$55.00"
dtCart.Rows.Add(CartRow)
Next
With gwCart
.DataSource = dtCart
.DataBind()
End With
For Each gv As GridViewRow In gwCart.Rows
oUser = New User
oUser = oUserDAO.RetrieveCouponCode(Session("User"))
Dim subtotal As Integer
Dim index As Integer = gwCart.SelectedIndex
If oUser.blnIsUsed = False And Session("Discount") = True Then
If gv.RowIndex = 0 Then
gwCart.Rows(0).Cells(2).Text = "$35.00"
subtotal = Utilities.ReplaceSpecialChars(gv.Cells(2).Text)
lbTotal.Text = "$" & subtotal & ".00"
Else
gwCart.Rows(0).Cells(2).Text = "$35.00"
subtotal = (Utilities.ReplaceSpecialChars(gv.Cells(2).Text) * (gv.DataItemIndex + 1)) - 20
lbTotal.Text = "$" & subtotal & ".00"
End If
Else
subtotal = Utilities.ReplaceSpecialChars(gv.Cells(2).Text) * (gv.DataItemIndex + 1)
lbTotal.Text = "$" & subtotal & ".00"
End If
If Session("SpecialDiscount") = True Then
subtotal = Utilities.ReplaceSpecialChars(gv.Cells(2).Text) * (gv.DataItemIndex + 1)
lbTotal.Text = "$0.01"
End If
Session("AppearanceID") = gv.Cells(1).Text
Next
End Sub
Public Sub BindCartCheckOut()
Dim aCartList As New List(Of Appearances)
Dim dtCart As New DataTable
Dim CartRow As DataRow
aCartList = New List(Of Appearances)
aCartList = oAppearancesDAO.PopulateAppreanceGrid(Session("User"))
dtCart = New DataTable
dtCart.Columns.Add("CaseName", GetType(String))
dtCart.Columns.Add("AppearanceID", GetType(Integer))
dtCart.Columns.Add("Total", GetType(String))
For Each oAppearances As Appearances In aCartList
CartRow = dtCart.NewRow
CartRow("CaseName") = oAppearances.sCaseName
CartRow("AppearanceID") = oAppearances.iAppearnceID
CartRow("Total") = "$55.00"
dtCart.Rows.Add(CartRow)
Next
With gwCheckOut
.DataSource = dtCart
.DataBind()
End With
For Each gv As GridViewRow In gwCheckOut.Rows
oUser = New User
oUser = oUserDAO.RetrieveCouponCode(Session("User"))
Dim subtotal As Integer
Dim index As Integer = gwCheckOut.SelectedIndex
If Session("Discount") = True Then
If gv.RowIndex = 0 Then
gwCheckOut.Rows(0).Cells(2).Text = "$35.00"
subtotal = Utilities.ReplaceSpecialChars(gv.Cells(2).Text)
lbTotal.Text = "$" & subtotal & ".00"
Else
gwCheckOut.Rows(0).Cells(2).Text = "$35.00"
subtotal = (Utilities.ReplaceSpecialChars(gv.Cells(2).Text) * (gv.DataItemIndex + 1)) - 20
lbTotal.Text = "$" & subtotal & ".00"
End If
Else
subtotal = Utilities.ReplaceSpecialChars(gv.Cells(2).Text) * (gv.DataItemIndex + 1)
lbTotal.Text = "$" & subtotal & ".00"
End If
If Session("SpecialDiscount") = True Then
subtotal = Utilities.ReplaceSpecialChars(gv.Cells(2).Text) * (gv.DataItemIndex + 1)
lbTotal.Text = "$0.01"
End If
Session("AppearanceID") = gv.Cells(1).Text
Next
End Sub
Protected Sub GetUser()
Dim exUser = New User
exUser = oUserDAO.RetrieveUserFromUserID(Session("User"))
If ddSameAddress.SelectedItem.Value = exUser.sAddress1 Then
txtFirst.Text = exUser.sFirstName
txtLast.Text = exUser.sLastName
txtAddress.Text = exUser.sAddress1
txtAddressContinued.Text = exUser.sAddress2
txtCity.Text = exUser.sCity
txtStates.Text = exUser.sState
txtZip.Text = exUser.sZip
txtCountry.Text = "US"
txtPhone.Text = exUser.sCellPhone
ElseIf ddSameAddress.SelectedIndex = 0 Then
txtFirst.Text = String.Empty
txtLast.Text = String.Empty
txtAddress.Text = String.Empty
txtAddressContinued.Text = String.Empty
txtCity.Text = String.Empty
txtStates.Text = String.Empty
txtZip.Text = String.Empty
txtPhone.Text = String.Empty
txtCountry.Text = String.Empty
End If
End Sub
Protected Sub btnApply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApply.Click
oUser = New User
oUser = oUserDAO.RetrieveCouponCode(Session("User"))
If txtCoupon.Text.ToUpper = "QQWWEE" Then
lbTotal.Text = ".01"
Session("SpecialDiscount") = True
BindCart()
Else
If txtCoupon.Text.ToUpper = oUser.sCouponCode And oUser.blnIsUsed = False Then
lbTotal.Text = lbTotal.Text - 20 & ".00"
Session("Discount") = True
BindCart()
Else
ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('Code is incorrect!');", True)
End If
End If
End Sub
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Response.Redirect("cart.aspx")
End Sub
Sub ddSameAddress_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddSameAddress.SelectedIndexChanged
GetUser()
End Sub
Protected Sub btnHelp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHelp.Click
popup.Style.Add("display", "block")
body.Style.Add("opacity", "0.2")
body.Style.Add("filter", "alpha(opacity=40)")
End Sub
Protected Sub btnCloseCVV_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCloseCVV.Click
popup.Style.Add("display", "none")
body.Style.Add("opacity", "1.0")
body.Style.Add("filter", "alpha(opacity=100)")
End Sub
Public Function Truncate(ByVal input As String, ByVal characterLimit As Integer) As String
Dim output As String = input
' Check if the string is longer than the allowed amount
' otherwise do nothing
If output.Length > characterLimit AndAlso characterLimit > 0 Then
' cut the string down to the maximum number of characters
output = output.Substring(0, characterLimit)
' Check if the character right after the truncate point was a space
' if not, we are in the middle of a word and need to remove the rest of it
If input.Substring(output.Length, 1) <> " " Then
Dim LastSpace As Integer = output.LastIndexOf(" ")
' if we found a space then, cut back to that space
If LastSpace <> -1 Then
output = output.Substring(0, LastSpace)
End If
End If
' Finally, add the "..."
output += "..."
End If
Return output
End Function
End Class