Validating Payment During the Check Out Process
Introduction. Now
we need to develop an ASP that will be used for validating payments. The file will be called
ValidatePayment.asp.
This will be presented after discussing
stored procedures.
We will need three stored procedures to initialize the order, insert the order data and insert the payment data. These are called sp_InitializeOrderStatus, sp_InsertOrderData and sp_InsertPaymentData. We also need to update all of the information in the shopping basket using sp_UpdateBasket. The following table displays the name of each stored procedure and the ASP file in which it is called. |
Stored Procedure | ASP Container |
sp_InitializeOrderStatus sp_InsertOrderData sp_InsertPaymentData sp_UpdateBasket |
ValidatePayment.asp |
The Stored Procedure. Now I will list out each stored procedure that you should create using SQL and ASPs pretty much exactly like we have for the other stored procedures. This first file should be called sp_InitializeOrderStatus.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connfoxFire, strSQLCreate Set connfoxFire = Server.CreateObject("ADODB.Connection") connfoxFire.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_InitializeOrderStatus @idOrder int AS " & _ "insert into OrderStatus(idOrder) values(@idOrder)" connfoxFire.execute(strSQLCreate) |
This second file should be called sp_InsertOrderData.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connfoxFire, strSQLCreate Set connfoxFire = Server.CreateObject("ADODB.Connection") connfoxFire.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_InsertOrderData " & _ "@idShopper int, " & _ "@chrShipFirstName varchar(150), " & _ "@chrShipLastName varchar(150), " & _ "@chrShipAddress varchar(150), " & _ "@chrShipCity varchar(150), " & _ "@chrShipState varchar(25), " & _ "@chrShipProvince varchar(150), " & _ "@chrShipCountry varchar(150), " & _ "@chrShipZipCode varchar(150), " & _ "@chrShipPhone varchar(150), " & _ "@chrShipEmail varchar(150), " & _ "@chrBillFirstName varchar(150), " & _ "@chrBillLastName varchar(150), " & _ "@chrBillAddress varchar(150), " & _ "@chrBillCity varchar(150), " & _ "@chrBillState varchar(25), " & _ "@chrBillProvince varchar(150), " & _ "@chrBillCountry varchar(150), " & _ "@chrBillZipCode varchar(150), " & _ "@chrBillPhone varchar(150), " & _ "@chrBillEmail varchar(150), " & _ "@idBasket int AS " & _ "insert into orderdata(idShopper, chrShipFirstName, " & _ "chrShipLastName, chrShipAddress, " & _ "chrShipCity, chrShipState, " & _ "chrShipProvince, chrShipCountry, " & _ "chrShipZipCode, chrShipPhone, " & _ "chrShipEmail, chrBillFirstName, " & _ "chrBillLastName, chrBillAddress, " & _ "chrBillCity, chrBillState, " & _ "chrBillProvince, chrBillCountry, " & _ "chrBillZipCode, chrBillPhone, " & _ "chrBillEmail, idBasket) " & _ "values(@idShopper, @chrShipFirstName, " & _ "@chrShipLastName, @chrShipAddress, " & _ "@chrShipCity, @chrShipState, " & _ "@chrShipProvince, @chrShipCountry, " & _ "@chrShipZipCode, @chrShipPhone, " & _ "@chrShipEmail, @chrBillFirstName, " & _ "@chrBillLastName, @chrBillAddress, " & _ "@chrBillCity, @chrBillState, " & _ "@chrBillProvince, @chrBillCountry, " & _ "@chrBillZipCode, @chrBillPhone, " & _ "@chrBillEmail, @idBasket) " & _ "select idOrder = @@identity" connfoxFire.execute(strSQLCreate) |
This file is considerably longer because of all the order data you need. Each entry has been put on its own line in attempt to increase the clarity of what is contained in the procedure. |
This third file should be called sp_InsertPaymentData.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connfoxFire, strSQLCreate Set connfoxFire = Server.CreateObject("ADODB.Connection") connfoxFire.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_InsertPaymentData " & _ "@idOrder int, " & _ "@chrCardType varchar(100), " & _ "@chrCardNumber varchar(50), " & _ "@chrExpDate varchar(25), " & _ "@chrCardName varchar(150) " & _ "AS " & _ "insert into paymentdata(idOrder, chrCardType, " & _ "chrCardNumber, chrExpDate, chrCardName) " & _ "values(@idOrder, @chrCardType, " & _ "@chrCardNumber, @chrExpDate, @chrCardName)" connfoxFire.execute(strSQLCreate) |
This fourth file should be called sp_UpdateBasket.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connfoxFire, strSQLCreate Set connfoxFire = Server.CreateObject("ADODB.Connection") connfoxFire.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connfoxFire.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_UpdateBasket " & _ "@idBasket int, " & _ "@intQuantity int, " & _ "@intSubTotal int, " & _ "@intShipping int, " & _ "@intFreeShipping int, " & _ "@intTax int, " & _ "@intTotal int " & _ "AS " & _ "update basket set " & _ "intQuantity = @intQuantity, " & _ "intSubtotal = @intSubtotal, " & _ "intShipping = @intShipping, " & _ "intFreeShipping = @intFreeShipping, " & _ "intTax = @intTax, " & _ "intTotal = @intTotal " & _ "where idBasket = @idBasket" connfoxFire.execute(strSQLCreate) |
Like all of the other ASPs based on CREATE SQL commands, these files need to be uploaded to your web and then executed once. After they have been executed, you should get an error if you try to execute them again because the stored procedures should already be there. After these sp_name.asp files have been used they should be removed from your space on the server. |
The ValidatePayment.asp.
Since we have just created the stored procedures required for this ASP we can
now make use of them. The following ValidatePayment.asp
will
|
<%@ Language=VBScript %> <% ' Retrieve the credit card data chrCCName = request("chrCCName") chrCCNumber = request("chrCCNumber") chrCCType = request("chrCCType") chrCCExpMonth = request("chrCCExpMonth") chrCCExpYear = request("chrCCExpYear") ' Retrieve the billing data chrBillFirstName = request("chrBillFirstName") chrBillLastName = request("chrBillLastName") chrBillAddress = request("chrBillAddress") chrBillCity = request("chrBillCity") chrBillState = request("chrBillState") chrBillProvince = request("chrBillProvince") chrBillCountry = request("chrBillCountry") chrBillZipCode = request("chrBillZipCode") chrBillPhone = request("chrBillPhone") chrBillEmail = request("chrBillEmail") chrPassword = request("chrPassword") intCookie = request("intCookie") ' Check to see if a credit card name was entered if chrCCName = "" then
end if
end if
end if
end if
end if
end if
end if
end if
else
end if
end if
end if
end if
end if
end if
else
end if |
This ASP is almost entirely a processing script and relies on other ASPs, primarily Payment.asp, as the user interface. |