/* ***** Functions for performing a credit transaction. ***** */ // //////////////////// BEGIN MAIN ///////////////////////// var success = false; var merchantReference = null; /* 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. Please see "MakeValidMerchantReference()" for length restrictions on the "merchantReference" variable. */ registerLivePayment(); merchant = new Merchant(); terminal = new Terminal(); processor = new Processor(project.acquirer); if (processor.bad()) { PrintFmtError("Failed to construct processor object.", processor.getStatusMessage()); } /* 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"); batch = GetCurrentBatch(merchant, terminal, processor); if (request.creditType == "manual") //Manual credit transaction. { var today = new Date(); var thisMonth = today.getMonth() + 1; var thisYear = today.getYear() + 1900; var expMonth = request.cardExpMonth; if (expMonth.charAt(0) == "0") expMonth = expMonth.charAt(1); /* 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. Please see "MakeValidMerchantReference()" for length restrictions on the "merchantReference" variable. For example, FDC restricts the merchantReference value to 10 numeric characters. */ // Format some of the input received from the form. // Put cardExpDate in proper YYYYMM format request.cardExpDate = request.cardExpYear + request.cardExpMonth; // Remove dashes or spaces from cardNumber request.cardNumber = RemoveAlpha(request.cardNumber); // If no cents are entered, set centsAmount to "00". if ((request.centsAmount == "") || (request.centsAmount == "0")) request.centsAmount = "00"; // If cents length is less than 2, convert it to 2. if (request.centsAmount.length == 1) request.centsAmount = "0" + request.centsAmount; // Add dollars & cents to arrive at the credit amount in cents. var creditAmount = "" + request.dollarAmount + request.centsAmount; // Initialize unused values to null. request.billAddress = "null"; request.zip = "null" // Validate the data that was entered. var errMsg = ""; if (IsBlank(request.billName)) errMsg = "Please enter a name for the Card Holder."; else if (IsBlank(request.cardType)) errMsg = "Please enter a Credit Card Type."; else if (!IsNum(request.cardNumber) || !IsCardMatch(request.cardType, request.cardNumber)) errMsg = "Invalid Credit Card Number entered for card type " + request.cardType; else if (IsBlank(request.dollarAmount) || !IsNum(request.dollarAmount) || (parseInt(request.dollarAmount) < 1)) errMsg = "Please enter a valid credit amount for at least 1 dollar."; else if (IsBlank(creditAmount) || !IsNum(creditAmount)) errMsg = "Please enter a valid credit amount in cents."; else if ( (parseInt(expMonth) < thisMonth) && (parseInt(request.cardExpYear) == thisYear) ) errMsg = "This card has expired or you have entered an incorrect expiration month." else if ( parseInt(request.cardExpYear) < thisYear ) errMsg = "This card has expired or you have entered an incorrect expiration year." if (errMsg != "") PrintError("some purchase form data is invalid.", errMsg); // Create an instance of a SaleObject to hold data required for a manual credit creditData = new SaleObject(creditAmount, project.currency, request.orderDesc, request.billName, request.cardType, request.cardNumber, request.cardExpDate, request.billAddress, request.zip, request.merchantReference); // Generate the slip GenerateSlip(creditData, processor); // Create a new credit event and get the purchase ID request.id = CreateManualCreditEvent(batch, request.merchantReference, slipID, creditData.cardHolderName, creditData.amount); } // End if (Manual credit transaction) success = Credit(request.id, batch, merchant, terminal, processor, request.merchantReference); // Confirm() produces a HTML page which tells the user // if the operation succeeded or failed. Confirm(success, 'credit');