public string Transfer(TransferRequest request) { string cardNumerPrefix = request.CardNumber.Substring(0, 3); if (!OnMemoryDataBase.validateCardBins(cardNumerPrefix)) { throw new GeneralPaymentError("Invalid card."); } string cardCompany = OnMemoryDataBase.getCardCompany(cardNumerPrefix); if ("AMEX".Equals(cardCompany) && request.CardNumber.Length != 15) { throw new GeneralPaymentError("Invalid card number"); } else if (("VISA".Equals(cardCompany) || "MASTERCARD".Equals(cardCompany)) && request.CardNumber.Length != 16) { throw new GeneralPaymentError("Invalid card number"); } string number = request.CardNumber; Console.WriteLine("number.Length => " + number.Length); string cardNumerSubfix = number.Substring(number.Length - 4, 4); Console.WriteLine("A charge has been made to the client '" + request.CardName + "' \n" + "\tFor the amount of '" + request.Ammount + "' to the card " + "termination '" + cardNumerSubfix + "'.\n"); return(System.Guid.NewGuid().ToString()); }
protected override void ProcessFile() { try { StreamReader stream = new StreamReader(File.OpenRead()); string line; while ((line = stream.ReadLine()) != null) { string[] fields = line.Split(","); string id = fields[0]; string customer = fields[1]; double amount = double.Parse(fields[2]); string date = fields[3]; bool exist = OnMemoryDataBase.CustomerExist(int.Parse(customer)); if (!exist) { Log += id + " E" + customer + "\t\t" + date + " Customer not exist\n"; } else if (amount > 200) { Log += id + " E" + customer + "\t\t" + date + " The amount exceeds the maximum\n"; } else { Log += id + " E" + customer + "\t\t" + date + " Successfully applied\n"; } } stream.Close(); }catch (Exception e) { throw new SystemException(e.ToString()); } }
protected override void ProcessFile() { try { StreamReader stream = new StreamReader(File.OpenRead()); string line; while ((line = stream.ReadLine()) != null) { string id = line.Substring(0, 3); string customer = line.Substring(3, 2); double amount = double.Parse(line.Substring(5, 3)); string date = line.Substring(8, 8); bool exist = OnMemoryDataBase.CustomerExist(int.Parse(customer)); if (!exist) { Log += id + " E" + customer + "\t\t" + date + " Customer not exist\n"; } else if (amount > 200) { Log += id + " E" + customer + "\t\t" + date + " The amount exceeds the maximum\n"; } else { //TODO Aplicar el pago en algún lugar. Log += id + " E" + customer + "\t\t" + date + " Successfully applied\n"; } } stream.Close(); }catch (Exception e) { throw new SystemException(e.ToString()); } }
public double Pay(BillingPayRequest billingPay) { Customer customer = OnMemoryDataBase.findCustomerById(billingPay.CustomerId); customer.Balance = customer.Balance - billingPay.Amount; Console.WriteLine("Payment applied to the client '" + customer.Name + "', " + "the new balance is '" + customer.Balance + "'"); return(customer.Balance);//new Balance. }
protected void ValidateProcess() { string fileStatus = OnMemoryDataBase.GetFileStatus(File.Name); if (fileStatus != null && fileStatus.Equals("Processed")) { throw new Exception("The file '" + File.Name + "' has already been processed"); } }
public PaymentResponse Pay(PaymentRequest request) { Customer customer = CrmSystem.FindCustomer(request.CustomerId); //Validate Set if (customer == null) { throw new GeneralPaymentError("Customer ID does not exist '" + request.CustomerId + "' not exist."); } else if ("Inactive".Equals(customer.Status)) { throw new GeneralPaymentError("Customer ID does not exist '" + request.CustomerId + "' is inactive."); } else if (request.Ammount > BillingSyste.QueryCustomerBalance(customer.Id)) { throw new GeneralPaymentError("You are trying to make a payment " + "\n\tgreater than the customer's balance"); } //charge to the card TransferRequest transfer = new TransferRequest( request.Ammount, request.CardNumber, request.CardName, request.CardExpDate, request.CardNumber); string payReference = BankSyste.Transfer(transfer); //Impact of the balance in the billing system BillingPayRequest billingRequest = new BillingPayRequest( request.CustomerId, request.Ammount); double newBalance = BillingSyste.Pay(billingRequest); //The client is reactivated if the new balance is less than $ 51 string newStatus = customer.Status; if (newBalance <= 50) { OnMemoryDataBase.changeCustomerStatus(request.CustomerId, "Active"); newStatus = "Active"; } //Envio de la confirmación de pago por Email. Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("$name", customer.Name); parameters.Add("$ammount", request.Ammount + ""); parameters.Add("$newBalance", newBalance + ""); string number = request.CardNumber; string subfix = number.Substring(number.Length - 4, 4); parameters.Add("$cardNumber", subfix); parameters.Add("$reference", payReference); parameters.Add("$newStatus", newStatus); EmailSenderSystem.SendEmail(parameters); return(new PaymentResponse(payReference, newBalance, newStatus)); }
public Principal Authenticate(string userName, string passwrd) { User user = OnMemoryDataBase.FindUserByName(userName); if (user != null && user.Password.Equals(passwrd)) { return(new Principal(user.UserName, user.Rol)); } return(null); }
public Principal authenticate(string user, string pwd) { var userDB = OnMemoryDataBase.findUserById(user); if (userDB == null) { return(null); } else if (!userDB.pwd.Equals(pwd)) { return(null); } else { return new Principal() { user = user, rol = userDB.rol } }; } }
public double QueryCustomerBalance(Int64 customerId) { Customer customer = OnMemoryDataBase.findCustomerById(customerId); return(customer.Balance); }
public Customer FindCustomer(Int64 customerId) { return(OnMemoryDataBase.findCustomerById(customerId)); }
protected void MarkAsProcessFile() { OnMemoryDataBase.SetProcessFile(File.Name); }