/* **************************************************************** PAGE DESCRIPTION: This page is the form handler for the Customer Information form. After setting some additional properties of the REQUEST object, it performs a credit card authorization. An error message is printed out if the Authorization fails, or a receipt is printed to the screen if the Authorization succeeds. ASSUMPTIONS FOR STARTER APP SAMPLE: Note that these assumptions will change once you integrate your inventory database and your own product/service line into the LivePayment sample application. The sample applications do NOT limit you to the number, price or type of items you sell. These assumptions about a few simple products were made only to show how the application and functions work, not to lock developers into a particular way of integrating their inventory system. Acquirer: "FDC" (see start.html and "project.acquirer" property) Slip: 1 per purchase Terminal number: as specified in configuration file Merchant name, number: as specified in configuration file Password file: as specified in configuration file **************************************************************** */ // Register LivePayment functions with LiveWire registerLivePayment(); // Set the client object (especially important for CLIENT-URL object maintenance!!) client.productID = request.productID; /* Format some of the input received from the form. This section may need to be changed if you alter the form elements in "purchase.html." */ // Concatenate addresses into 1 address request.billAddress = request.billAddr1 + " " + request.billAddr2; request.shipAddress = request.shipAddr1 + " " + request.shipAddr2; // Put cardExpDate in proper YYYYMM format request.cardExpDate = request.cardExpYear + request.cardExpMonth; // Remove dashes or spaces from cardNumber request.cardNumber = RemoveAlpha(request.cardNumber); /* IF SHIPPING INFORMATION IS SAME AS BILLING INFORMATION: If the "Check if Same as Above" checkbox is checked, then the billing information is mapped to the corresponding shipping fields in the REQUEST object. Changes to the REQUEST object occur in the function MatchShipToBill(), so upon return of the function, the shipping values contain the corresponding billing values. */ if (request.shipSame == "on") MatchShipToBill(request); // Validate user input from the customer information form VerifyPurchaseData(request); /* Merchants may want to assign their own meaningful values to the merchantReference variable here. It is used in the transaction processing and is stored in the database. If left as null, the program will generate a value for it at the time of the transaction process. However, some merchants may want to insert some more meaningful data into this field, usually a unique order number. Please see "MakeValidMerchantReference()" for length restrictions on the "merchantReference" variable. For example, FDC restricts the merchantReference value to 10 numeric characters. */ // request.merchantReference = "12345"; /* If database type is INFORMIX, Set database server to wait 20 seconds if table/row is locked. *** THIS COMMAND IS SPECIFIC TO INFORMIX *** */ if (project.dbType.toUpperCase() == "INFORMIX") database.execute("SET LOCK MODE TO WAIT 20"); /* FIND ORDER TOTAL AMOUNT (in cents) AND ORDER DESCRIPTION: Find the order total, in cents. This function may be re-written or replaced by your own function if you are using a shopping cart. or other mechanism for purchasing. By default, "CalcOrderTotal" interprets product ID's produced by "products.html" which is for sample purposes only, so it will need to be replaced by your own code for looking up product amounts. */ if (request.productID != null) item = GetItemProperties( request.productID ); else PrintError("Product not specified", "You did not specify a product before purchase."); // Check to see if we found a valid item if (item.desc == "Invalid Item") PrintError("Product not specified.", "An invalid product was specified before purchase. " + "No credit card authorization occured."); request.orderDesc = item.desc; // Pass the subtotal (in cents) to CalcOrderTotal to get the final // total. var purchaseAmount = CalcOrderTotal( item.amount ); // Create an instance of a SaleObject to hold data required for an Authorization authData = new SaleObject(purchaseAmount, project.currency, request.orderDesc, request.billName, request.cardType, request.cardNumber, request.cardExpDate, request.billAddress, request.billZip, request.merchantReference); // Perform the actual authorization with the "authData" object created above. // Output an HTML receipt of purchase if the Authorization was successful. if ( Authorize(authData) ) { EmitHeader("Purchase Successful"); // Standard HTML Header write("\n"); PrintReceipt(payevent, request.orderDesc); write("

Return to products form.

"); EmitFooter(); // Standard HTML Footer } // end IF statement // If the authorization failed, the Authorize() function will have called PrintError and an // error page will have been presented to the user before ever reaching this point.