/// <summary> /// The Function that actually processes an order, Validates Order with the BankService and returns a confirmation. /// </summary> /// <param name="encoded_order_object">The encoded OrderObject string to process as an OrderObject, once it is decoded of course.</param> public static void orderProcessor(string encoded_order_object) { //Decode string into an object: OrderObject new_order_object = EnDecoder.Decode(encoded_order_object); //Update total amount to account for Sales tax: decimal total = BankService.formatCurrency((new_order_object.getAmount() + (new_order_object.getAmount() * SALES_TAX))); new_order_object.setAmount(total); //Create an encryption service via ASU's Repo: Service encryption = new Service(); //Encrypt the credit card number: string encrypted_cc_number = encryption.Encrypt(Convert.ToString(new_order_object.getCardNo())); //encrypt the total amount to charge the account: string encrypted_amount = encryption.Encrypt(Convert.ToString(new_order_object.getAmount())); //Have Bank validate the Account charge given the encrypted credit card number and amount to charge: new_order_object.setIsValid(BankService.confirmCreditCard(encrypted_cc_number, encrypted_amount)); //Get the Travel_agencies ID: string travel_agency_id = new_order_object.getSenderID(); //Encode the Processed Order Object: string encoded_processed_order = EnDecoder.Encode(new_order_object); //Create a new thread to handle the processed order: OrderProcessing.submitProcessedOrderObject(encoded_processed_order, travel_agency_id); Thread processed_order_thread = new Thread(() => OrderProcessing.submitProcessedOrderObject(encoded_processed_order, travel_agency_id)); //Start the thread: processed_order_thread.Start(); }
/// <summary> /// This function takes in a string which has an OrderOjbect "encoded" into it, and decodes it back into an OrderObject. /// </summary> /// <param name="orderStr">The "encoded" OrderObject string to decode into an OrderObject.</param> /// <returns>The OderObject that was "decoded" from the "encoded" data passed in.</returns> public static OrderObject Decode(string orderStr) { //"decode" the "encoded" data: string[] orderData = orderStr.Split(' '); //Create a new orderObject to set up with the "decoded" data: OrderObject orderObj = new OrderObject(); //Set up orderObject based on data in the encoded string: orderObj.setSenderID(orderData[0]); //Set the Sender ID orderObj.setReceiverID(orderData[1]); //Set the receiver ID orderObj.setCardNo(Convert.ToInt32(orderData[2])); //Set the Card Number orderObj.setAmount(Convert.ToDecimal(orderData[3])); //Set the Amount orderObj.setUnitPrice(Convert.ToDecimal(orderData[4])); //Set the Unit Price orderObj.setIsValid(Convert.ToBoolean(orderData[5])); //Set the Order Validator orderObj.setRoomsOrdered(Convert.ToInt32(orderData[6])); //Return the newly orderObject that has been created from the "decoded" data: return(orderObj); }