public void ValidatePaymentDetail() { //change creditcard to a valid one and set expected to true var testclass = new PaymentDetail(); testclass.CreditCardNumber = "5199110721565746"; testclass.SecurityCode = "234"; testclass.ExpirationDate = new DateTime(2021, 4, 24); testclass.Amount = 50; var actual = testclass.ValidatePaymentDetail(); var expected = false; Assert.Equal(expected, actual); }
public Response <PaymentResponseDto> ProcessPayment(PaymentDetail paymentDetail, int transactionType = 0) { try { if (!paymentDetail.ValidatePaymentDetail()) { return new Response <PaymentResponseDto> { Code = ResponseCodes.INVALID_REQUEST, Description = "Invalid Request", Payload = new PaymentResponseDto { Message = "Invalid Request", Amount = paymentDetail.Amount } } } ; bool paymentStatus; switch (paymentDetail.Amount) { //later move range to appsettings to make it dynamic case var n when n > 0 && n < 21: paymentStatus = ProcessPaymentLessThan21(paymentDetail, transactionType); break; case var n when n > 20 && n < 501: paymentStatus = ProcessPaymentGreaterThan21LessThan501(paymentDetail, transactionType); break; case var n when n > 500: paymentStatus = ProcessPaymentGreaterThan500(paymentDetail, transactionType); break; default: paymentStatus = false; break; } if (paymentStatus == true) { return(new Response <PaymentResponseDto> { Code = ResponseCodes.OK, Description = "Successful", Payload = new PaymentResponseDto { Message = "Invalid Request", Amount = paymentDetail.Amount } }); } else { return(new Response <PaymentResponseDto> { Code = ResponseCodes.ERROR, Description = "Server Error", Payload = new PaymentResponseDto { Message = "Invalid Request", Amount = paymentDetail.Amount } }); } } catch (Exception) { return(new Response <PaymentResponseDto> { Code = ResponseCodes.ERROR, Description = "Server Error", Payload = new PaymentResponseDto { Message = "Invalid Request", Amount = paymentDetail.Amount } }); } }