public void InputDates(PayDetails payDetails) { System.Console.WriteLine("Please enter your payment start date:"); payDetails.PayStartDate = System.Console.ReadLine(); System.Console.WriteLine("Please enter your payment end date:"); payDetails.PayEndDate = System.Console.ReadLine(); }
public PayDetails GetPayDetailById(string Id) { SqlParameter[] param = { new SqlParameter("@flag", SqlDbType.VarChar, 50) { Value = "getPayById" } , new SqlParameter("@EmployeeId", SqlDbType.Int) { Value = Id } }; DataRow result = SqlHelper.ExecuteDataRow("spEmployee", param); PayDetails obj = new PayDetails(); obj.Id = Convert.ToInt32(result["Id"]); obj.EmployeeId = Convert.ToInt32(result["EmpId"]); obj.BankName = Convert.ToString(result["BankName"]); obj.BankBranch = Convert.ToString(result["BankBranch"]); obj.AccountNo = Convert.ToString(result["AccountNo"]); obj.AccountName = Convert.ToString(result["AccountName"]); //obj.BasicSalary = Convert.ToInt32(result["BasicSalary"]); obj.PaySchedule = Convert.ToString(result["PaySchedule"]); obj.BasicSalary = Convert.ToString(result["Salary"]); obj.OTRate = Convert.ToString(result["OTRate"]); obj.WorkingHR = Convert.ToDecimal(result["WorkingHR"]); return(obj); }
public PayDetailsRequest.PayDetailsResponse CalculateTax(PayDetailsRequest request) { PayDetails payDetails = new PayDetails() { FirstName = request.FirstName, SurName = request.SurName, PayStartDate = request.PayStartDate, PayEndDate = request.PayEndDate }; bool isValueValid = payDetails.TrySetSuperRate(request.SuperRate) && payDetails.TrySetAnnualSalary(request.AnnualSalary); if (isValueValid) { return(new PayDetailsRequest.PayDetailsResponse( payDetails.PayPeriod, payDetails.FullName, payDetails.GrossIncome, payDetails.IncomeTax, payDetails.NetIncome, payDetails.Super, 200)); } // do we reject ? throw exception ? throw new exception /*TODO: map the methods in the payDetail object*/ // fill out response object from paydetails return(new PayDetailsRequest.PayDetailsResponse(422, "Invalid input values")); }
public async Task <string> DoPayment(PayDetails payDetails) { var payStatus = PaymentStatusType.Pending; if (payDetails.Amount <= 20) { payStatus = await CheapPayment(payDetails); } else if (payDetails.Amount > 20 && payDetails.Amount <= 500) { payStatus = await ExpensivePayment(payDetails); } else { payStatus = await PremiumPayment(payDetails); } var payment = await _payRepository.Add(payDetails); var paymentStatus = new PaymentStatus { PayDetailId = payment.Id, Status = payStatus.ToString() }; var status = await _payStatusRepository.Add(paymentStatus); return(status.Status); }
public void PayResponse(object parameters) { try { ResponseParameters responseParameters = JsonConvert.DeserializeObject <ResponseParameters>(parameters.ToString()); //Update the payment details with the ones received from the payment terminal payDetails = responseParameters.PayDetails; //Check the status property of the parameters object to see if the Pay was successful if (responseParameters.Status == 0) { WasPaySuccessful = true; } else { WasPaySuccessful = false; } //Update the error code and error description specificStatusDetails.StatusCode = responseParameters.Status; specificStatusDetails.Description = responseParameters.Description; //Notify the Pay method that the message has stopped IsPayFinished = true; } catch (Exception ex) { logger.Error(PAYMENT_LOG, string.Format("Failed to validate the PayResponse. \r\n{0}", ex.ToString())); } }
public ActionResult PayDetailsEdit(PayDetails obj) { if (ModelState.IsValid) { try { var result = iEmployee.UpdatePayDetails(obj, "u-pay"); return(Json(new { ErrorCode = result.ErrorCode, Message = result.Msg, Id = result.Id, JsonRequestBehavior.AllowGet })); } catch (Exception ex) { return(Json(new { ErrorCode = 1, Message = ex.Message }, JsonRequestBehavior.AllowGet)); } } Response.TrySkipIisCustomErrors = true; string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); return(Json(new { ErrorCode = 1, Message = messages }, JsonRequestBehavior.AllowGet)); }
public void InputSuperRate(PayDetails payDetails) { try { System.Console.WriteLine("Please enter your super rate:"); string inputSuperRate; var promptUserFormat = false; do { inputSuperRate = System.Console.ReadLine(); promptUserFormat = !payDetails.TrySetSuperRate(inputSuperRate); if (promptUserFormat) { System.Console.WriteLine("Wrong format, the super rate should be numbers only, please re-enter your super rate:"); } else { System.Console.WriteLine("You entered super rate: " + payDetails.SuperRate); } } while (promptUserFormat); // while (regexSalary.IsMatch(inputRate) == false){ // Console.WriteLine("Wrong format, the super rate should be numbers only, please re-enter your super rate:"); // inputRate = Console.ReadLine(); // } // payDetails.Super = payDetails.CalcSuper(inputValue); } catch (Exception e) { throw e; } }
public void InputAnnualSalary(PayDetails payDetails) { try { System.Console.WriteLine("Please enter your annual salary:"); string inputSalary; var promptUserFormat = false; do { inputSalary = System.Console.ReadLine(); promptUserFormat = !payDetails.TrySetAnnualSalary(inputSalary); if (promptUserFormat) { System.Console.WriteLine("Wrong format, the annual salary should be numbers only, please re-enter your annual salary:"); } else { System.Console.WriteLine("You entered annual salary: " + payDetails.AnnualSalary); } } while (promptUserFormat); /* while (regexSalary.IsMatch(inputSalary) == false){ * Console.WriteLine("Wrong format, the annual salary should be numbers only, please re-enter your annual salary:"); * inputSalary = Console.ReadLine(); * }*/ payDetails.calcIncomeTax(); } catch (Exception e) { throw e; } }
private async Task <PaymentStatusType> ExpensivePayment(PayDetails payDetails) { var payStatus = await _expensivePaymentGateway.MakePayment(payDetails); if (payStatus == PaymentStatusType.Failed) { payStatus = await _cheapPaymentGateway.MakePayment(payDetails); } return(payStatus); }
public DbResult UpdatePayDetails(PayDetails obj, string flag) { SqlParameter[] param = { new SqlParameter("@flag", SqlDbType.VarChar, 50) { Value = flag } , new SqlParameter("@Id", SqlDbType.Int) { Value = obj.Id } , new SqlParameter("@EmployeeId", SqlDbType.Int) { Value = obj.EmployeeId } , new SqlParameter("@BankName", SqlDbType.VarChar, 50) { Value = obj.BankName } , new SqlParameter("@BankBranch", SqlDbType.VarChar, 50) { Value = obj.BankBranch } , new SqlParameter("@AccountNo", SqlDbType.VarChar, 50) { Value = obj.AccountNo } , new SqlParameter("@AccountName", SqlDbType.VarChar, 50) { Value = obj.AccountName } , new SqlParameter("@BasicSalary", SqlDbType.VarChar, 20) { Value = obj.BasicSalary } , new SqlParameter("@PaySchedule", SqlDbType.VarChar, 20) { Value = obj.PaySchedule } , new SqlParameter("@OTRate", SqlDbType.VarChar, 20) { Value = obj.OTRate } , new SqlParameter("@WorkingHR", SqlDbType.Decimal) { Value = obj.WorkingHR } , new SqlParameter("@userId", SqlDbType.NVarChar, 128) { Value = SessionHelper.GetUserID() } }; return(SqlHelper.ParseDbResult("spEmployee", param)); }
// Regex regexSalary = new Regex(@"^-?[0-9][0-9\.]+$"); //Regex to tolerate decimal point public void InputName(PayDetails payDetails) { try { System.Console.WriteLine("Please input your name:"); payDetails.FirstName = System.Console.ReadLine(); System.Console.WriteLine("Please input your surname:"); payDetails.SurName = System.Console.ReadLine(); } catch (Exception e) { System.Console.WriteLine("The name input is invalid" + "\n" + e.Message); } }
public List <string> payDetailsToArray(PayDetails payDetails) { List <string> result = new List <string> { payDetails.FullName, payDetails.PayPeriod, payDetails.GrossIncome.ToString(), payDetails.IncomeTax.ToString(), payDetails.NetIncome.ToString(), payDetails.Super.ToString() }; return(result); }
public async Task ExceptionHandledWhilePamentProcess() { var request = new PayDetails { CreditCardNumber = "1234567891234567", CardHolder = "Test", ExpirationDate = DateTime.Now.AddMonths(1), SecurityCode = 100, Amount = -100 }; _paymentHandler.Setup(a => a.DoPayment(request)).Throws(new Exception("Internal Server Error")); var response = await _controller.ProcessPayment(request); var errorResult = response as StatusCodeResult; Assert.AreEqual(500, errorResult.StatusCode); }
/// <summary> /// /// </summary> /// <param name="payRequest"></param> /// <param name="payDetails"></param> /// <param name="specificStatusDetails"></param> /// <param name="wasUncertainPaymentDetected"></param> /// <returns></returns> public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { _logger.Info(Constants.LOG_FILE, "Pay method started..."); _logger.Debug(Constants.LOG_FILE, $"PayRequest: {JsonConvert.SerializeObject(payRequest)}"); Result <PaymentData> result; var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { result = proxy.Pay(payRequest.Amount, payRequest.TransactionReference); } payDetails = new PayDetails { PaidAmount = result.Data?.PaidAmount ?? 0, HasClientReceipt = result.Data?.HasClientReceipt ?? false, HasMerchantReceipt = result.Data?.HasMerchantReceipt ?? false }; specificStatusDetails = new SpecificStatusDetails() { StatusCode = (int)result.ResultCode, Description = result.Message }; //Check the status property of the parameters object to see if the Pay was successful if ((result.ResultCode == ResultCode.Success && result.Data?.Result == PaymentResult.Successful)) { _logger.Info(Constants.LOG_FILE, "Payment has succeeded."); LastStatus = PeripheralStatus.PeripheralOK(); return(true); } else { _logger.Info(Constants.LOG_FILE, "Payment has failed."); return(false); } } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Payment exception thrown."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } }
/// <summary> /// /// </summary> /// <param name="payRequest"></param> /// <param name="payDetails"></param> /// <param name="specificStatusDetails"></param> /// <param name="wasUncertainPaymentDetected"></param> /// <returns></returns> public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { _logger.Info(Constants.LOG_FILE, "Pay method started..."); _logger.Debug(Constants.LOG_FILE, $"PayRequest: {JsonConvert.SerializeObject(payRequest)}"); //Init the paid amount and Tender Media payDetails = new PayDetails(); Result <PaymentData> result; var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { result = proxy.Pay(payRequest.Amount); } //Check the status property of the parameters object to see if the Pay was successful if (result.ResultCode == ResultCode.Success && result.Data.Result == PaymentResult.Successful) { _logger.Info(Constants.LOG_FILE, "Payment has been succeeded."); LastStatus = PeripheralStatus.PeripheralOK(); //Update the payment details with the ones received from the payment terminal //payDetails.TenderMediaId = result.Data.TenderMediaId; payDetails.PaidAmount = result.Data.PaidAmount; payDetails.HasClientReceipt = result.Data.HasClientReceipt; } else { _logger.Info(Constants.LOG_FILE, "Payment has been failed."); } specificStatusDetails = new SpecificStatusDetails() { StatusCode = (int)result.ResultCode, Description = result.Message }; return(result.ResultCode == ResultCode.Success && result.Data.Result == PaymentResult.Successful); } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Payment exception has been thrown."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } }
public void IncomeTax_SuperRateShouldBePositiveIfNegative() { var salary = 50000; var super = -9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(4166, payDetails.GrossIncome); Assert.AreEqual(650, payDetails.IncomeTax); Assert.AreEqual(3516, payDetails.NetIncome); Assert.AreEqual(395, payDetails.Super); }
public void IncomeTax_ShouldPositiveIfNegative() { var salary = -40000; var super = 9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(3333, payDetails.GrossIncome); Assert.AreEqual(379, payDetails.IncomeTax); Assert.AreEqual(2954, payDetails.NetIncome); Assert.AreEqual(316, payDetails.Super); }
public void IncomeTax_ShouldFallIntoSecondBracket() { var salary = 23000; var super = 9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(1916, payDetails.GrossIncome); Assert.AreEqual(76, payDetails.IncomeTax); Assert.AreEqual(1840, payDetails.NetIncome); Assert.AreEqual(182, payDetails.Super); }
public void IncomeTax_ShouldFallInTheMiddleBracket_IfSalaryExactlyEqualsBracketMinimum() { var salary = 87000.5; var super = 9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(7250, payDetails.GrossIncome); Assert.AreEqual(1652, payDetails.IncomeTax); Assert.AreEqual(5598, payDetails.NetIncome); Assert.AreEqual(688, payDetails.Super); }
[Test] public void IncomeTax_ShouldFallInTheLastBracket_IfSalaryExactlyEqualsBracketMinimum() { var salary = 180000.5; var super = 9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(15000, payDetails.GrossIncome); Assert.AreEqual(4520, payDetails.IncomeTax); Assert.AreEqual(10480, payDetails.NetIncome); Assert.AreEqual(1425, payDetails.Super); }
public void IncomeTax_ShouldBeZeroIfZero() { var salary = 0; var super = 9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(0, payDetails.GrossIncome); Assert.AreEqual(0, payDetails.IncomeTax); Assert.AreEqual(0, payDetails.NetIncome); Assert.AreEqual(0, payDetails.Super); }
public void IncomeTax_ShouldFallIntoFirstBracket() { var salary = 17000; var super = 9; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(1416, payDetails.GrossIncome); Assert.AreEqual(0, payDetails.IncomeTax); Assert.AreEqual(1416, payDetails.NetIncome); Assert.AreEqual(127, payDetails.Super); }
public void IncomeTax_ShouldFallIntoFifthBracket() { var salary = 200000; var super = 9.5; var payDetails = new PayDetails(); payDetails.TrySetAnnualSalary(salary.ToString()); payDetails.calcIncomeTax(); payDetails.TrySetSuperRate(super.ToString()); Assert.AreEqual(16666, payDetails.GrossIncome); Assert.AreEqual(5270, payDetails.IncomeTax); Assert.AreEqual(11396, payDetails.NetIncome); Assert.AreEqual(1583, payDetails.Super); }
public async Task <IActionResult> ProcessPayment([FromBody] PayDetails payDetails) { try { var paymentStatus = await _handler.DoPayment(payDetails); var response = new APIResponse { IsSuccess = true, Message = $"Payment Status: {paymentStatus}" }; return(new OkObjectResult(response)); } catch { return(new StatusCodeResult(500)); } }
public async Task PaymentProcessedSuccessfully(decimal amount, string status) { var request = new PayDetails { CreditCardNumber = "1234567891234567", CardHolder = "Test", ExpirationDate = DateTime.Now.AddMonths(1), SecurityCode = 100, Amount = amount }; _paymentHandler.Setup(a => a.DoPayment(request)).ReturnsAsync(status); var response = await _controller.ProcessPayment(request); var okResult = response as OkObjectResult; var apiResponse = okResult.Value as APIResponse; Assert.AreEqual(200, okResult.StatusCode); Assert.AreEqual(true, apiResponse.IsSuccess); Assert.AreEqual($"Payment Status: {status}", apiResponse.Message); }
private async Task <PaymentStatusType> PremiumPayment(PayDetails payDetails) { int retry = 0; var payStatus = PaymentStatusType.Pending; while (retry < 3) { payStatus = await _premiumPaymentGateway.MakePayment(payDetails); if (payStatus == PaymentStatusType.Processed) { break; } retry++; } return(payStatus); }
// string inputType; // string inputValue; static void Main(string[] args) { System.Console.WriteLine("This program calculate the income tax, gross income, net income and super based on positive values"); System.Console.WriteLine ( "Please select how do you want to enter data by press number:\n" + "[1] I want to enter the data manually via the console.\n" + "[2] I want to import the file.\n" + "NOTE: If you select [2], you need to enter the absolute path of your file, only .csv file will be accepted\n" ); string userInputKey = System.Console.ReadLine(); if (userInputKey == "1") { PayDetails payDetails = new PayDetails(); UserInput userInput = new UserInput(); userInput.InputName(payDetails); userInput.InputAnnualSalary(payDetails); userInput.InputSuperRate(payDetails); userInput.InputDates(payDetails); payDetails.PrintPayDetails(); } else if (userInputKey == "2") { System.Console.WriteLine("Please paste your path here:"); UserImport userImport = new UserImport(); string importPath = System.Console.ReadLine(); userImport.readImportPath(importPath); /*System.Console.WriteLine("\nSorry, you've just selected a feature that is still in development, you are recommended to terminate the program."); * Environment.Exit(0);*/ userImport.exportPayDetails(); } else { System.Console.WriteLine("\nYour selection is invalid"); Environment.Exit(0); } //TODO: set print as UserInput() }
public async Task PaymentDoneByPremiumPaymentGateway() { var premiumPayDetails = new PayDetails { CreditCardNumber = "1234567891234567", CardHolder = "Test", ExpirationDate = DateTime.Now.AddMonths(1), SecurityCode = 100, Amount = 550 }; _premiumPaymentGateway.Setup(s => s.MakePayment(premiumPayDetails)).ReturnsAsync(PaymentStatusType.Processed); _payRepository.Setup(p => p.Add(premiumPayDetails)).ReturnsAsync(new PayDetails { Id = 1 }); _payStatusRepository.Setup(p => p.Add(It.IsAny <PaymentStatus>())).ReturnsAsync(new PaymentStatus { Id = 1, Status = PaymentStatusType.Processed.ToString(), PayDetailId = 1 }); var result = await _handler.DoPayment(premiumPayDetails); Assert.AreEqual(PaymentStatusType.Processed.ToString(), result); _cheapPaymentGateway.Verify(s => s.MakePayment(premiumPayDetails), Times.Never); _expensivePaymentGateway.Verify(s => s.MakePayment(premiumPayDetails), Times.Never); }
public void readImportPath(string path) { using (TextFieldParser parser = new TextFieldParser(path)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { string[] fields = parser.ReadFields(); var payDetails = new PayDetails(); payDetails.FirstName = fields[0]; payDetails.SurName = fields[1]; payDetails.AnnualSalary = Convert.ToDouble(fields[2]); payDetails.SuperRate = Convert.ToDouble(fields[3]); payDetails.PayStartDate = fields[4]; payDetails.PayEndDate = fields[5]; payDetails.calcIncomeTax(); payDetailsList.Add(payDetails); } } }
public bool ElectronicPay(PayRequest payRequest, ref PayDetails payDetails) { return(true); }