<% '************************************************************************* ' ASP Scripting: ' Filename: handler_checkout.asp ' Written by: Wilbert Madarang ' Date: May 10, 2003 '************************************************************************* ' Description: This is the main Checkout Handler '************************************************************************* ' Revision History: ' September 28, 2003 ' 1.0 Added by WM. Added getOrderNumber Function ' 2.0 Modified logic to State "confirm_order". ' October 19, 2003 ' 3.0 Added Extra validation for checking valid session '************************************************************************* CC_NUMBER_OF_DIGITS = 12 LENGTH_ZIPCODE = 5 LENGTH_POSTAL_CODE = 6 %> <% '************************************************** ' Global Variables '************************************************** Dim strAction 'Checks if buyer has been authenticated Dim bAuthenticated, bSuccessful, strSuccessUrl, strFailUrl 'During Shipping Info Collection Dim strAddress, strCity, strProvince, strPostalCode, strCountry Dim strCreditCardType, strCreditCardNumber, strExpiryDateMonth, strExpiryDateYear '************************************************** ' Check if Valid Session '************************************************** strAction = Request( "action" ) If ( InStr("uthenticate",strAction)=0 ) Then 'If the action is to authenticate, then the email field may not be available... Else If ( Session("MyEmail") = "" ) Then Response.Redirect "error_page.asp?error_code=session_expiry" End If End If '************************************************** ' Main Logic Controller '************************************************** SELECT CASE strAction Case "authenticate" 'Check If User Already Authenticated bAuthenticated = Session( "Authenticated" ) If bAuthenticated = False Then Response.Redirect "checkout_login_page.asp" Else Response.Redirect "checkout_get_shipping_info.asp" End If Case "validate_shipping_info" 'TBD: 'Validate Shipping Info ... 'bSuccessful = ValidateShippingInfo() Call parseShippingInfo Response.Redirect "checkout_review_order.asp" Case "confirm_order" Session( "MyOrderNumber" ) = getOrderNumber( DEFAULT_ORDER_NUMBER_SIZE ) Call SendOrderEmail Response.Redirect "checkout_confirm_order.asp" End Select '************************************************************** ' FUNCTION: ValidateShippingInfo ' DESCRIPTION: Checks if All Required Shipping Info is Available ' PARAMETERS: none ' RETURNS: returns Fail '************************************************************** Function ValidateShippingInfo Dim bValidateSuccessful bValidateSuccessful = True 'Parse The Information Call parseShippingInfo 'Validation Rules bConfirmedRequiredData = isAllShippingInfoAvailable() bIsNumericCC = isNumericCreditCardNumber( strCreditCardNumber ) bCreditCardDigits = CheckCreditCardDigits( strCreditCardNumber ) If ( strCountry = "us" ) Then bPostalCode = CheckZipCodeFormat( strPostalCode ) Else ' bPostalCode = CheckPostalCodeFormat( strPostalCode ) End If 'Debug Call printShippingInfo Response.Write "bConfirmedRequiredData is " & bConfirmedRequiredData & "
" & vbCrLf Response.Write "bIsNumericCC is " & bIsNumericCC & "
" & vbCrLf ValidateShippingInfo = bValidateSuccessful End Function '************************************************************** ' FUNCTION: parseShippingInfo ' DESCRIPTION: parses all the Shipping Info ' PARAMETERS: none ' RETURNS: none '************************************************************** Function parseShippingInfo 'Address strAddress = Request("address") strCity = Request( "city" ) strProvince = Request( "province" ) strPostalCode = Request( "postal_code" ) strCountry = Request( "country" ) 'Credit Card strCreditCardType = Request("credit_card_type") strCreditCardNumber = Request("credit_card_number") strExpiryDateMonth = Request("expiry_date_month") strExpiryDateYear = Request("expiry_date_year") 'Store Session Information Session("MyShippingAddress") = strAddress Session("MyShippingCity") = strCity Session("MyShippingProvince") = strProvince Session("MyShippingPostalCode") = strPostalCode Session("MyShippingCountry") = strCountry Session("MyCreditCardType") = strCreditCardType Session("MyCreditCardNumber") = strCreditCardNumber Session("MyCreditCardExpiryDateMonth") = strExpiryDateMonth Session("MyCreditCardExpiryDateyear") = strExpiryDateYear End Function '************************************************************** ' FUNCTION: isAllShippingInfoAvailable ' DESCRIPTION: Checks if All Required Shipping Info is Available ' PARAMETERS: none ' RETURNS: returns Fail '************************************************************** Function isAllShippingInfoAvailable() bReturn = true If IsNull( LEN(strAddress) ) OR LEN(strAddress) = 0 Then bReturn = false Elseif IsNull( LEN(strCity) ) OR LEN(strCity) = 0 Then bReturn = false Elseif IsNull( LEN(strProvince) ) OR LEN(strProvince) = 0 Then bReturn = false Elseif IsNull( LEN(strPostalCode) ) OR LEN(strPostalCode) = 0 Then bReturn = false Elseif IsNull( LEN(strCountry) ) OR LEN(strCountry) = 0 Then bReturn = false Elseif IsNull( LEN(strCreditCardType) ) OR LEN(strCreditCardType) = 0 Then bReturn = false Elseif IsNull( LEN(strCreditCardNumber) ) OR LEN(strCreditCardNumber) = 0 Then bReturn = false Elseif IsNull( LEN(strExpiryDateMonth) ) OR LEN(strExpiryDateMonth) = 0 Then bReturn = false Elseif IsNull( LEN(strExpiryDateYear) ) OR LEN(strExpiryDateYear) = 0 Then bReturn = false End If isAllShippingInfoAvailable = bReturn End Function '************************************************************** ' FUNCTION: IsNumbericCreditCardNumber ' DESCRIPTION: Checks if all the Numbers of the Credit Card are Numeric ' PARAMETERS: the CreditCard Number ' RETURNS: returns True/Fail '************************************************************** Function isNumericCreditCardNumber( strCreditCardNumber ) isNumericCreditCardNumber = IsNumeric( strCreditCardNumber ) End Function '************************************************************** ' FUNCTION: CheckZipCodeFormat ' DESCRIPTION: Checks the Zip Code Format ' PARAMETERS: Zip Code ' RETURNS: True / False '************************************************************** Function CheckZipCodeFormat( strZipCode ) Dim bSuccessful bSuccessful = True 'Check Length If LEN( strZipCode ) = LENGTH_ZIPCODE Then Else bSuccessful = False End If 'Check Format If IsNumeric( strZipCode ) Then Else bSuccessful = False End If CheckZipCodeFormat = bSuccessful End Function '************************************************************** ' FUNCTION: CheckPostalCodeFormat ' DESCRIPTION: Checks the Postal Code Format ' PARAMETERS: PostalCode ' RETURNS: True / False '************************************************************** Function CheckPostalCodeFormat( strPostalCode ) Dim bSuccessful bSuccessful = True 'Check Length If LEN(strPostalCode) = LENGTH_POSTAL_CODE Then Else bSuccessful = False End If CheckPostalCodeFormat = bSuccessful End Function '************************************************************** ' FUNCTION: CheckCreditCardDigits ' DESCRIPTION: Checks the number of Credit Card Digits ' PARAMETERS: credit card ' RETURNS: True / False '************************************************************** Function CheckCreditCardDigits( strCreditCardNumber ) Dim bCCDigits If LEN(strCreditCardNumber) = CC_NUMBER_OF_DIGITS Then bCCDigits = True Else bCCDigits = False End If CheckCreditCardDigits = bCCDigits End Function '************************************************************** ' FUNCTION: printShippingInfo ' DESCRIPTION: prints all the Shipping Info ' PARAMETERS: none ' RETURNS: none '************************************************************** Function printShippingInfo Response.Write "strAddress is " & strAddress & "
" & vbCrLf Response.Write "strCity is " & strCity & "
" & vbCrLf Response.Write "strProvince is " & strProvince & "
" & vbCrLf Response.Write "strPostalCode is " & strPostalCode & "
" & vbCrLf Response.Write "strCountry is " & strCountry & "
" & vbCrLf Response.Write "strCreditCardType is " & strCreditCardType & "
" & vbCrLf Response.Write "strCreditCardNumber is " & strCreditCardNumber & "
" & vbCrLf Response.Write "strExpiryDateMonth is " & strExpiryDateMonth & "
" & vbCrLf Response.Write "strExpiryDateYear is " & strExpiryDateYear & "
" & vbCrLf End Function '************************************************************** ' FUNCTION: getOrderNumber ' DESCRIPTION: Generate Order Number for Transaction ' PARAMETERS: none ' RETURNS: none '************************************************************** Function getOrderNumber( nNumberOfDigits ) Dim floatRandomNumber, nRandomNumber Dim nMaxNumber Dim strOrderNumber 'Make sure Number of Digits is Valid If ( nNumberOfDigits <= 0 ) Then nNumberOfDigits = DEFAULT_ORDER_NUMBER_SIZE End If 'Maximum Number of Digits Randomize() nMaxNumber = 10^nNumberOfDigits floatRandomNumber = nMaxNumber * Rnd() nRandomNumber = Int( floatRandomNumber ) strOrderNumber = CStr( nRandomNumber ) & "-" & _ Month(Date) & _ Day(Date) & _ Year(Date) getOrderNumber = strOrderNumber End Function '************************************************************** ' FUNCTION: SendOrderEmail ' DESCRIPTION: Sends the Order Email ' PARAMETERS: none ' RETURNS: none '************************************************************** ' Modified: September 28, 2003 ' 1.0 Changed Dear Sir/Madam to Dear ' 2.0 "please reply to this email" versus "please email us with" ' 3.0 Added Order Number '************************************************************** ' Modified: October 19, 2003 ' 1.0 Added Firstname, Lastname in function SendOrderEmail ' 2.0 Added ShippingAddress, BillingAddress to function ' SendOrderEmail '************************************************************** ' Modified: November 1, 2003 ' 1.0 Modified to Accept Shopping Cart Color ' from: strColor = aryShoppingCart(i, SCART_COLOR ) ' to: strColor = aryShoppingCart(i, SCART_PRODUCT_COLOR ) '************************************************************** Function SendOrderEmail Dim strTo, strFrom, strSubject, strBody Dim strBodyHead, strBodyItems, strBodyTotal Dim nShoppingCartItems, aryShoppingCart Dim strProductName, strProductCode, strColor Dim nProductRegularPrice, nProductSalePrice, nProductPrice, nQuantity Dim strCurrencyLabel Dim strFirstname Dim strLastname Dim strShippingAddress, strBillingAddress Dim strOrderNumber, strPaymentType 'Body aryShoppingCart = Session("MyShoppingCart") strOrderNumber = Session( "MyOrderNumber" ) strFirstname = Session("MyFirstname") 'Check if this is valid for authenticated users, versus new users. strLastname = Session("MyLastname") 'strBodyHead = "Dear Sir/Madam," & vbCrLf & vbCrLf & _ strBodyHead = "Dear " & strFirstname & " " & strLastname & "," & vbCrLf & vbCrLf & _ "Thank you for your order at www.charister.com. Please review the order below. To " & _ "confirm your order, please reply to this email with the last four digits of the credit card number " & _ "and the name of the bank issuing the credit card that " & _ "you had provided for the order. Your order will be processed once we receive your confirmation." & _ " An email will be sent to you with an approximate shipping date of the items." & vbCrLf & vbCrLf & _ "Order Number: " & strOrderNumber & vbCrLf & vbCrLf strBodyItems = "" 'Add Shopping Cart Items nShoppingCartItems = Session("NumShopItems") If nShoppingCartItems > 0 Then 'Format Column Size strBodyItems = "Items" & SPACE( EMAIL_ITEM_COLUMN_SIZE-5 ) & "Quantity" & SPACE( EMAIL_QUANTITY_COLUMN_SIZE-8 ) & "Total" & vbCrLf For i = 1 to nShoppingCartItems 'Obtain Shopping Cart Parameters 'TBD: Rehash this Code strProductName = aryShoppingCart(i, SCART_PRODUCT_NAME ) strColor = aryShoppingCart(i, SCART_PRODUCT_COLOR ) strProductCode = aryShoppingCart(i, SCART_PRODUCT_CODE ) nQuantity = aryShoppingCart(i, SCART_QUANTITY ) nProductRegularPrice = aryShoppingCart(i, SCART_REGULAR_PRICE) nProductSalePrice = aryShoppingCart(i, SCART_SALE_PRICE ) 'Determine Regular or Sale Price If nProductSalePrice > 0 Then nProductPrice = nProductSalePrice Else nProductPrice = nProductRegularPrice End If '************************************************************** 'Modifed November 8, 2003 ' Modified to call existing function. '************************************************************** 'Determine Currency Label 'If Session("MyCountry")="canada" Then ' strCurrencyLabel = "CDN " 'Else ' strCurrencyLabel = "USD " 'End If strCurrencyLabel = GetCurrencyLabel() '************************************************************** 'End of Modification Nov 8, 2003 '************************************************************** 'Assemble String 'TBD: Rehash this code strBodyItems = strBodyItems & _ strProductName & SPACE( EMAIL_ITEM_COLUMN_SIZE-LEN(strProductName) ) & _ nQuantity & SPACE( EMAIL_QUANTITY_COLUMN_SIZE-LEN(CSTR(nQuantity)) ) & _ FormatCurrency( nQuantity*nProductPrice, 2 ) & vbCrLf 'Print Price If nProductSalePrice > 0 Then strBodyItems = strBodyItems & _ "Price: " & strCurrencyLabel & FormatCurrency(nProductRegularPrice, 2) & vbCrLf & _ "Sale Price: " & strCurrencyLabel & FormatCurrency(nProductSalePrice, 2) & vbCrLf Else strBodyItems = strBodyItems & _ "Price: " & strCurrencyLabel & FormatCurrency(nProductRegularPrice, 2) & vbCrLf End If 'Print Color If strColor = "" OR IsNull(strColor) Then Else strBodyItems = strBodyItems & "Color: " & strColor & vbCrLf End If 'Print ProductCode strBodyItems = strBodyItems & "Product Code: " & strProductCode & vbCrLf & vbCrLf & vbCrLf Next 'strBodyTotal = "Subtotal: " & FormatCurrency(Session("MySubTotal"),2) & vbCrLf & _ strBodyTotal = "Subtotal: " & FormatCurrency(Session("MySubTotalBeforeDiscounts"),2) & vbCrLf & _ "Promotional Discount: (" & FormatCurrency( Session("MyPromoDiscount"),2) & ")" & vbCrLf & _ "Shipping and Handling Fee: " & FormatCurrency(Session("MyShippingCost"),2) & vbCrLf & vbCrLf & _ "Subtotal (after discount and shipping): " & FormatCurrency( Session("MySubTotalAfterDiscounts"), 2) & vbCrLf & _ "PST: " & FormatCurrency( Session("MyPST"), 2) & vbCrLf & _ "GST: " & FormatCurrency( Session("MyGST"), 2) & vbCrLf & _ "Total : " & strCurrencyLabel & FormatCurrency(Session("MyTotal"),2) & vbCrLf & vbCrLf '************************** ' Billing Address '************************** strBillingAddress = "Billing Address:" & vbCrLf & _ Session("MyAddress") & vbCrLf & _ Session("MyCity") & vbCrLf & _ Session("MyProvince") & vbCrLf & _ Session("MyPostalCode") & vbCrLf & _ Session("MyCountry") & vbCrLf & vbCrLf '************************** ' Shipping Address '************************** strShippingAddress = "Shipping Address:" & vbCrLf & _ Session("MyShippingAddress") & vbCrLf & _ Session("MyShippingCity") & vbCrLf & _ Session("MyShippingProvince") & vbCrLf & _ Session("MyShippingPostalCode") & vbCrLf & _ Session("MyShippingCountry") & vbCrLf & vbCrLf '************************** ' Credit Card Number '************************** strPaymentType = "Payment Type: " & vbCrLf & _ "Credit Card: " & Session("MyCreditCardType") & vbCrLf & _ "Credit Card Number: " & Session("MyCreditCardNumber") & vbCrLf & _ "Expiry Date (Month/Year): " & _ Session("MyCreditCardExpiryDateMonth") & "/" & _ Session("MyCreditCardExpiryDateYear") & vbCrLf & vbCrLf 'Construct the Email String strBody = strBodyHead & strPaymentType & strBillingAddress & strShippingAddress & strBodyItems & strBodyTotal End If 'Send Email to Client strTo = Session("MyEmail") strFrom = CHARISTER_EMAIL strSubject = "Purchase Confirmation for Order Number: " & strOrderNumber Call SendEmail(strTo, strFrom, strSubject, strBody) 'Send Email to Charister strTo = CHARISTER_EMAIL strFrom = Session("MyEmail") strSubject = "Purchase Confirmation for Order Number: " & strOrderNumber Call SendEmail(strTo, strFrom, strSubject, strBody) 'Send Email for testing ' strTo = "" ' strFrom = Session("MyEmail") ' strSubject = "Purchase Confirmation for Order Number: " & strOrderNumber ' Call SendEmail(strTo, strFrom, strSubject, strBody) End Function '************************************************************** ' FUNCTION: SendEmail ' DESCRIPTION: Sends the Order Email ' PARAMETERS: none ' RETURNS: none '************************************************************** Function SendEmail(strTo, strFrom, strSubject, strBody) Dim objSendMail 'Send the email to inform Canalite Set objSendMail = CreateObject("CDONTS.NewMail") objSendMail.To = strTo objSendMail.From = strFrom objSendMail.Subject = strSubject objSendMail.Body = strBody objSendMail.Send Set objSendMail = Nothing End Function %>