Example #1
0
        public string transfer(TransferRequest request)
        {
            string cardNumberPreFix = request.cardNumber.Substring(0, 3);

            if (!OnmemoryDataBase.validateCardBins(cardNumberPreFix))
            {
                throw new Exception("Tarjeta invalida");
            }

            string cardCompany = OnmemoryDataBase.getCardCompany(cardNumberPreFix);

            if ("AMEX".Equals(cardCompany) && request.cardNumber.Length != 15)
            {
                throw new Exception("El numero de tarjeta es invalido");
            }
            else if (("VISA".Equals(cardCompany) || "MASTERCARD".Equals(cardCompany)) && request.cardNumber.Length != 16)
            {
                throw new Exception("El numero de la tarjeta es invalido");
            }
            string number           = request.cardNumber;
            string cardNumberSubfix = number.Substring(number.Length - 4, 4);

            Console.WriteLine($"Se ha realizado un cargo al cliente {request.cardName} {Environment.NewLine}" +
                              $"\t por el monto de {request.amount}  a la tarjeta con terminacion {cardNumberSubfix}");

            return(System.Guid.NewGuid().ToString());
        }
Example #2
0
        public double pay(BillingPayRequest billingPay)
        {
            Customer customer = OnmemoryDataBase.findCustomerById(billingPay.customerId);

            customer.balance = customer.balance - billingPay.amount;
            Console.WriteLine($"Pago aplicado al cliente: {customer.name} ," +
                              $"El nuevo saldo es {customer.balance}");
            return(customer.balance);//new Balance
        }
Example #3
0
        public PaymentResponse pay(PaymentRequest request)
        {
            Customer customer = crmSystem.findCustomer(request.CustomerId);

            if (customer == null)
            {
                throw new Exception("Cliente no existe");
            }
            else if (customer.status.Equals("Baja"))
            {
                throw new Exception("Cliente dado de baja");
            }

            //realizar el cobro a la tarjeta de credito
            TransferRequest transfer = new TransferRequest(request.Amount, request.CardNumber, request.CardNAme,
                                                           request.CardExpdate, request.CardSecureNumber);
            string reference = bankSystem.transfer(transfer);

            //llamado al sistema de fatuiracion
            BillingPayRequest billingRequest = new BillingPayRequest(request.CustomerId, request.Amount);
            double            newBalance     = billingSystem.pay(billingRequest);

            //determinar nuevo status
            string newStatus = customer.status;

            if (newBalance <= 50)
            {
                OnmemoryDataBase.changeCustomerStatus(request.CustomerId, newStatus);
                newStatus = "Activo";
            }

            //mandamos el email
            Dictionary <string, string> parans = new Dictionary <string, string>();

            parans.Add("$name", customer.name);
            parans.Add("$ammount", customer.ammount.ToString());
            parans.Add("$newBalance", request.Amount.ToString());
            string number = request.CardNumber;
            string subfix = number.Substring(number.Length - 4, 4);

            parans.Add("$cardNumber", subfix);
            parans.Add("$reference", reference);
            parans.Add("$newStatus", newStatus);

            emailSystem.sendEmail(parans);

            PaymentResponse response = new PaymentResponse(reference, newBalance, newStatus);

            return(response);
        }
Example #4
0
 public Customer findCustomer(long customerId)
 {
     return(OnmemoryDataBase.findCustomerById(customerId));
 }
Example #5
0
        public double queryCustomerBalance(long customerId)
        {
            Customer customer = OnmemoryDataBase.findCustomerById(customerId);

            return(customer.balance);
        }