//used to check if a user is approved for a purchase. //for USA, which does not allow cash, cash will be input as 0. public static ApproveWithMsg allowance(bool lactive, double present, double price, double cash, double wkly_allow, double wkly_bal, double mnth_allow, double mnth_bal) { ApproveWithMsg response = new ApproveWithMsg(); //Flag if user doesn't exist or is inactive if (!lactive) { response.message = "Not an active account."; } //check if enough balance to purchase item else if (price - cash > present) { response.Message = "Insufficient funds."; } //check if weekly allowance is enough to purchase item else if (wkly_allow != 0 && price - cash + wkly_bal > wkly_allow) { response.Message = "Insufficient weekly allowance."; } //check if monthly balance is enough to purchase item else if (mnth_allow != 0 && price - cash + mnth_bal > mnth_allow) { response.Message = "Insufficient monthly allowance."; } else { response.approved = true; } return(response); }
//First method called by USATech //Checks if student is allowed to make vending purchase and if they can purchase the specified item //will be rejected if student not found, student marked inactive, balance too low, remaining weekly allowance too low, remaining monthly allowance too low //USAT does not allow cash to supplement account balance public USAAuthResponse Authorize( int transactionID, DateTime transactionDateTime, string terminalName, string cardNumber, string currency, int amount ) { USAAuthResponse response = new USAAuthResponse(); response.TransactionID = transactionID; if (currency != "USD") { response.ResponseMessage = "This system only accepts USD."; response.ApprovedAmount = 0; response.StatusCode = 1; return(response); } string[] output_params = { "lactive", "present", "wkly_allow", "wkly_bal", "mnth_allow", "mnth_bal" }; Dictionary <string, string> outputs = SQL.findRow("student", cardNumber, Parse.readSchool(terminalName), output_params); bool lactive = Convert.ToBoolean(outputs["lactive"]); double present = Convert.ToDouble(outputs["present"]); double wkly_allow = Convert.ToDouble(outputs["wkly_allow"]); double wkly_bal = Convert.ToDouble(outputs["wkly_bal"]); double mnth_allow = Convert.ToDouble(outputs["mnth_allow"]); double mnth_bal = Convert.ToDouble(outputs["mnth_bal"]); double dollarAmount = amount / 100.0; ApproveWithMsg app = Approve.allowance(lactive, present, dollarAmount, 0, wkly_allow, wkly_bal, mnth_allow, mnth_bal); response.ResponseMessage = app.message; //test response.ResponseMessage += "<br>" + LogDump.LogContentString; LogDump.clearLog(); Mailer.send("*****@*****.**", "*****@*****.**", null, "Test from USATech, test authorize", response.ResponseMessage); //test if (app.approved) { response.ApprovedAmount = 275; response.StatusCode = 0; response.ResponseMessage = "Approved for $" + dollarAmount; return(response); } response.StatusCode = 1; response.ResponseMessage = app.message; return(response); }
//sent by VendNovation after AuthenticateCustomer //checks if student is allow to purchase the specified item. //will be rejected if: student is not found, student is marked inactive, student balance is too low, //remaining weekly allowance is too low, or remaining monthly balnace is too low. //Student can use cash to supplement account funds. public AuthenticateSelectionResult AuthenticateSelection(AuthenticateSelectionRequest request) { AuthenticateSelectionResult response = new AuthenticateSelectionResult(); if (request == null) { response.Error = "No Data"; response.Approved = false; return(response); } response.NewPrice = request.Price; string[] output_params = { "lactive", "present", "wkly_allow", "wkly_bal", "mnth_allow", "mnth_bal" }; Dictionary <string, string> outputs = SQL.findRow("student", request.UserCredentials, Parse.readSchool(request.SiteID), output_params); bool lactive = Convert.ToBoolean(outputs["lactive"]); double present = Convert.ToDouble(outputs["present"]); double wkly_allow = Convert.ToDouble(outputs["wkly_allow"]); double wkly_bal = Convert.ToDouble(outputs["wkly_bal"]); double mnth_allow = Convert.ToDouble(outputs["mnth_allow"]); double mnth_bal = Convert.ToDouble(outputs["mnth_bal"]); ApproveWithMsg app = Approve.allowance(lactive, present, request.Price, request.CashBalance, wkly_allow, wkly_bal, mnth_allow, mnth_bal); response.Approved = app.Approved; response.Error = app.Message; //test LogDump.Log("UserCredentials: " + request.UserCredentials); LogDump.Log("MachineID: " + request.MachineID); LogDump.Log("AccountBalance: " + request.AccountBalance); LogDump.Log("CashBalance: " + request.CashBalance); LogDump.Log("CredentialType: " + request.CredentialType); LogDump.Log("ProductID: " + request.ProductID); LogDump.Log("SiteID: " + request.SiteID); LogDump.Log("Price: " + request.Price); LogDump.Log("Selection: " + request.Selection); LogDump.Log("LoyaltyCard: " + request.LoyaltyCard); LogDump.Log("LoyaltyType: " + request.LoyaltyType); response.Error += "<br>" + LogDump.LogContentString; LogDump.clearLog(); //test Mailer.send("*****@*****.**", "*****@*****.**", null, "Test from VN, auth Selection", response.Error); return(response); }