#!/usr/local/bin/perl##    tally.pl##    $Source: /usr/local/CVS/SETREF_1_0_Release/webdemo/merchant/cgi-bin/set-demo/tally.pl,v #    $Revision: 1.4 #    $Date: 1997/06/06 00:53:06 #    $Name: SETREF_1_0_Release #    $Disclaimer: #    ----------------------------------------------------------------------#    SET Draft Reference Implementation Disclaimer/License#    June 30, 1997#    #    This is a beta version of the SET Draft Reference Implementation#    ("DRI").  It is a work in progress and is being provided at this#    stage and in this form to help developers and other interested#    parties to understand the SET protocol.  This version of the DRI#    provides the core functionality required to process a simple#    transaction.  This release does not support certificate authority#    messages. Nor does it support the SET option to perform#    transactions without cardholder certificates.  For more details#    on the functionality in this beta version, please refer to the#    attached documentation.  #    #    Later versions of the DRI will include additional functionality#    and may include other changes.  DO NOT RELY UPON THIS CODE IN YOUR#    DEVELOPMENT.  If you discover a bug, please let us know by posting#    a message to the SET-DEV mailing list.  Our lawyers made us include#    the next four paragraphs, so PLEASE READ THE TEXT BELOW because it#    describes what you can do with the DRI.#     #    Copyright (C) 1996, 1997, Visa International Service Association and#    MasterCard International Incorporated.  All rights reserved.  #    Permission to copy and implement the material contained herein is#    granted subject to the conditions that (i) any copy or re-publication#    must bear this legend in full; (ii) any derivative work must bear#    a notice that it is not the Draft Reference Implementation ("DRI")#    for SET and (iii) that none of the copyright holders shall have any#    responsibility or liability whatsoever to any other party arising#    from the use or publication of the material contained herein.#    #    Visa and MasterCard ("Licensors") hereby grant you ("Licensee") a#    limited license to (i) make, use, copy and modify the DRI for the#    purpose of developing software that complies with the SET#    Specification ("SET Products") and for the purpose of achieving a#    better understanding of the SET Protocol; and (ii) distribute SET#    Products that incorporate all or a portion of the DRI and other#    software, which together are provided under a defined interface#    different from that provided by the DRI's API.  Licensee shall not#    redistribute or sell a license to the DRI nor shall Licensee#    incorporate any part of the DRI into a SET Toolkit.  A "Toolkit"#    means a product that provides comprehensive facilities to enable#    other parties to create software products for distribution. #    Bolt-on applications and payment modules shall not be considered#    Toolkits for the purpose of this license.  The DRI is not intended#    to be used as a Toolkit.#    #    Licensors make no representation or warranty of any kind, express#    or implied, relating to the DRI.  Licensors are making the DRI#    publicly available as an aid to understanding, creating, and#    testing SET Products.  Licensees are solely responsible for any#    use of the DRI and agree to hold Licensors harmless for any claim#    that may arise out of any product created with the DRI.  #    #    Licensee expressly acknowledges Terisa Systems, Inc., a Delaware#    Corporation with offices at 4984 El Camino Real, Los Altos,#    California, as a third party beneficiary of this license.#    #    This software is controlled material under U.S. law and the laws#    of other jurisdictions and you hereby acknowledge and agree that#    you must fully comply with all the current laws of the United States#    including, without limitation, rules and regulations of the United#    States Office of Export Administration and other applicable U.S.#    governmental agencies.  #    ----------------------------------------------------------------------#     $##    Copyright (C) 1996, 1997, Visa International Service Association and MasterCard International Incorporated#    All Rights Reserved.##    briank@terisa.com and ehl@terisa.com## Determine the directory where this script resides, so that we can# find the other SET demo Perl scripts and the cgiset application.# # Assume that we won't see backslashes under UNIX or slashes under Windows.$last_separator_index = rindex($0, "/");$last_separator_index = rindex($0, "\\") if ($last_separator_index < 0);$script_dir = substr($0, 0, $last_separator_index + 1);push(@INC, $script_dir);require 'postinfo.pl';require 'taxes.pl';%qstring = &process_qstring($ENV{'QUERY_STRING'});$MEDIA = "/set-demo/";$CGIBIN = "/cgi-bin/set-demo/";## Tally#$total = 0;$shipping = 39.99;$output = "";$count = 0;$od = "";for ($i = 1; $i < 10; ++$i) {    next if (!defined($qstring{'Item'.$i}) && !defined($qstring{'Qty'.$i}));    $Qty = $qstring{'Qty'.$i};    $Item = $qstring{'Item'.$i};    # check for illegal values in Qty (must be blank or a number)    if ($Qty !~ /^ *[0-9]* *$/) {        &error_Qty($Qty);        next;    }    # product specified if and only if quantity is spcified    $Item_empty = (($Item =~ /^ *-+ *$/) ? 1 : 0);    $Qty_empty = (($Qty =~ /^ *$/) ? 1 : 0);    $Qty_zero = (($Qty =~ /^ *0+ *$/) ? 1 : 0);    next if ($Qty_zero);    next if ($Item_empty && $Qty_empty);    if ($Item_empty && ! $Qty_empty) {           &error_Item;           next;    }    if (! $Item_empty && $Qty_empty ) {           &error_Qty($Qty);           next;    }    ($name, $size, $cost) =        $Item =~ /([^ ]+) *([^-]+)--\$([0-9\.]+)/;    $subtotal = $Qty * $cost;    $output .= &show_item($name, $size, $cost, $Qty, $subtotal);    $od.= $name." ".$size." ".$cost." ".$Qty." ".$subtotal.":";    $total += $subtotal;}##  Did they specify anything?#&display_error("Please purchase some drives.") if ($count < 1);##  Figure the tax#$tax = &state_tax($qstring{'State'})/100 * $total;##  Format everything#$subtotal = &dollars($total);$shipping = &dollars($shipping + (0.04 * $subtotal));$tax = &dollars($tax);$total += $shipping + $tax;$total = &dollars($total);## determine the name of cgiset (cgiset on UNIX, cgiset.exe on Windows)#if (-e "${script_dir}cgiset") {    $CGISET = "${CGIBIN}cgiset";}else {    $CGISET = "${CGIBIN}cgiset.exe";}##  Display#    print <<"PAGE" Content-Type: text/html<HTML><HEAD><TITLE>Drives R Us: Purchase Order</TITLE></HEAD><BODY BGCOLOR="FFFFFF"><!--HEADER GRAPHICS AND TEXT--><IMG SRC="${MEDIA}drives-r-us.gif"> <!--INPUT FORM--><FORM ACTION="${CGISET}" METHOD="POST"><TABLE><TR><TD></TD><TD></TD>  <TD><IMG SRC="${MEDIA}Fmodel.gif"></TD>  <TD><IMG SRC="${MEDIA}Fquantity.gif"></TD>  <TD><IMG SRC="${MEDIA}Fprice.gif"></TD>  <TD><IMG SRC="${MEDIA}Famount.gif"></TD>  </TR>$output<TR><TD></TD><TD></TD><TD></TD><TD></TD>    <TD></TD>    <TD><HR></TD>    </TR><TR><TD></TD><TD></TD><TD></TD><TD></TD>    <TD ALIGN="right"><IMG SRC="${MEDIA}Tsubtotal.gif"></TD>    <TD ALIGN="right">$subtotal</TD>    </TR><TR><TD></TD><TD></TD><TD></TD><TD></TD>    <TD ALIGN="right"><IMG SRC="${MEDIA}Tshipping.gif"></TD>    <TD ALIGN="right">$shipping</TD>    </TR><TR><TD></TD><TD></TD><TD></TD><TD></TD>    <TD ALIGN="right"><IMG SRC="${MEDIA}Ttax.gif"></TD>    <TD ALIGN="right">$tax</TD>    </TR><TR><TD></TD><TD></TD><TD></TD><TD></TD>    <TD></TD>    <TD><HR></TD>    </TR><TR><TD></TD><TD></TD><TD></TD><TD></TD>    <TD ALIGN="right"><IMG SRC="${MEDIA}Ttotal.gif"></TD>    <TD ALIGN="right">\$$total</TD>    </TR>    <TR><TD WIDTH=20></TD><TD WIDTH=30></TD>    <TD WIDTH=110></TD><TD WIDTH=75></TD><TD WIDTH=75></TD><TD WIDTH=50></TD>    </TR></TABLE><TABLE><TR><TD></TD><TD></TD>  <TD><IMG SRC="${MEDIA}state.gif"></TD>  <TD><IMG SRC="${MEDIA}shipping.gif"></TD></TR><TR><TD></TD><TD></TD>   <TD>$qstring{'State'}</TD>   <TD>$qstring{'Shipping'}</TD>   </TR><TR>  <TD WIDTH=20></TD><TD WIDTH=30></TD><TD WIDTH=110></TD><TD WIDTH=130></TD>  </TR></TABLE><INPUT TYPE="hidden" NAME="payment_amt" VALUE="$total"><INPUT TYPE="hidden" NAME="order_description" VALUE="$od"><P><TABLE><TR><TD></TD><TD></TD>   <TD><INPUT TYPE="image" NAME="Pay" SRC="${MEDIA}pay.gif" BORDER=0></TD>   </TR><TR>   <TD WIDTH=20></TD><TD WIDTH=30></TD><TD WIDTH=75></TD><TD WIDTH=130></TD>   </TR></TABLE></FORM></BODY></HTML>PAGE;##  Create a product tally#sub show_item {    local($name, $size, $cost, $qty, $subtotal) = @_;    local($str) = "";    ++$count;    local($i) = $count;    $subtotal = &dollars($subtotal);    $str .= "<TR><TD></TD><TD>$i.</TD>    <TD>$name $size</TD><TD>$qty</TD><TD>$cost</TD>    <TD ALIGN=\"right\">$subtotal</TD>    </TR>";    return $str;}##  Format a dollar amount#sub dollars {    local($number) = @_;    local($str) = "";    $str .= sprintf("%.2f", $number);    return $str;}##  Error subroutines#sub error_Item {    &display_error("You must specify a product with each quantity.");}sub error_Qty {  local($qty) = @_;  if ($qty =~ /^ *$/) {      &display_error("You must specify a quantity with each product.");  }  else {      &display_error("Bad quantity specified.");  }}sub display_error {    local($msg) = @_;    print <<"PAGE" Content-Type: text/html<HTML><HEAD><TITLE>Drives R Us: Error</TITLE></HEAD><BODY BGCOLOR="FFFFFF"><!--HEADER GRAPHICS AND TEXT--><IMG SRC="${MEDIA}drives-r-us.gif"> <TABLE><TR><TD></TD><TD></TD>  <TD><IMG SRC="${MEDIA}error.gif"></TD></TR>  <TR><TD></TD><TD></TD><TD>$msg</TD></TR><TR><TD WIDTH=20></TD><TD WIDTH=30></TD><TD WIDTH=265></TD></TR></TABLE><P><BR><TABLE><TR><TD></TD><TD></TD>   <TD><A HREF="${MEDIA}order.html">   <IMG SRC="${MEDIA}back.gif" BORDER=0></A></TD>   </TR><TR>   <TD WIDTH=20></TD><TD WIDTH=30></TD><TD WIDTH=75></TD><TD WIDTH=130></TD>   </TR></TABLE></BODY></HTML>PAGE;  exit(0);}