#!/usr/local/bin/perl # checkout.pl - web cgi routine to handle shopping cart checkout # # Dave Stoddard - 5/29/04 # dgs@accelix.com # # Copyright # --------- # Copyright(c) 2004, Accelix LLC. All Rights Reserved. # # Description # ----------- # This program begins the process of checkout for the shopping cart system. # The steps in the checkout process, and their associated modules, are as # follows: # # checkout.pl - collect shipping information for the customer's order # billing.pl - show total and collect billing information # confirm.pl - show total and confirm or cancel the order # payment.pl - process payment and provide an invoice # # This routine creates two types of records -- the orders record and the # shipto record. Updates to the orderd table (which mimicks the cart table) # are deferred until the order is complete, valid, and accepted. This allows # the user to make changes in their cart right up to the final moment. # # Note: The orders table is named "orders" instead of "order" because the # word order is a reserved word in the database manager. # # RCS Information # --------------- # $Id$ # $Log$ # # package main; use strict 'vars'; use strict 'subs'; # use warnings; # use diagnostics; # load application modules use cart; # shopping cart support routines # --------------------------- # DECLARATIONS AND PROTOTYPES # --------------------------- # local elements my %form = (); # data from form (name/value pairs) my %state = (); # state persistence data hash my %sess = (); # session id hash my %orders = (); # orders table record my %cart = (); # cart table record my %shipto = (); # shipto table record my %tax = (); # tax table hash my @recs = (); # contents of the current shopping cart my $itemtot = 0; # order total my $discount = 0; # order discount amount my $nettotal = 0; # net total (itemtot - discount) my $salestax = 0; # sales tax amount my $shipcost = 0; # shipping costs my $mintotal = 150.00; # minimum order amount my $i = ""; # current cart record in series my $curr = "/cgi-bin/checkout.pl"; # the name of this program my $next = "/cgi-bin/billing.pl"; # next in the series of CGI programs # only states in this table have sales tax applied $tax{PA} = .06; # function prototypes sub CheckForOrders ($); # check for an existing order record sub CheckForShipto ($); # check for an existing shipto record sub EditShiptoData (\%\%); # edit form data for shipto record sub CalcDiscount ($); # calculate discounts sub CalcSalesTax (\%$); # calculate sales tax sub CalcShipping (\%$); # calculate shipping costs sub DisplayShipToPage (\%); # display the shipping info form sub GetOrdersRecord ($); # retrieve an orders record sub InitOrdersRecord (); # initialize a blank orders record sub AddOrdersRecord (\%); # add an orders record to the table sub ChangeOrdersRecord (\%); # change an existing orders record sub GetShiptoRecord ($); # retrieve a shipto record sub InitShiptoRecord (); # initialize a blank shipto record sub AddShiptoRecord (\%); # add a shipto record to the table sub ChangeShiptoRecord (\%); # change an existing shipto record sub GetStates (); # load state code hash sub GenerateOptions (\%$$); # create