public async Task <IActionResult> ProcessPayment([FromBody] PaymentCardDetails ClientCardDetails) { StatusMessages statusMessages = new StatusMessages(); try { PaymentCardDetails _PaymentCardDetails = new PaymentCardDetails(); var ValidateCard = ValidateCreditCard(ClientCardDetails.CreditCardNumber); if (ValidateCard == false) { statusMessages.Status = "failed"; statusMessages.Message = "Invalid credit card Details"; return(BadRequest(statusMessages)); } else if (ValidateCardDetails(ClientCardDetails) == false) { statusMessages.Status = "failed"; statusMessages.Message = "The request is invalid:"; return(BadRequest(statusMessages)); } else { if (ClientCardDetails.Amount < 20) { var MakePayment = await _ICheapPaymentGateway.CheapPaymentGateway(ClientCardDetails); if (MakePayment.Status == "Success") { ClientCardDetails.PaymentState = "processed"; await _IPaymentGateway.SavePaymentStatus(ClientCardDetails); statusMessages.Status = "Success"; statusMessages.Message = MakePayment.Message; } else { ClientCardDetails.PaymentState = "failed"; await _IPaymentGateway.SavePaymentStatus(ClientCardDetails); statusMessages.Status = "failed"; statusMessages.Message = MakePayment.Message; return(BadRequest(statusMessages)); } } else if (ClientCardDetails.Amount > 20 && ClientCardDetails.Amount < 500) { var MakePayment = await _IExpensivePaymentGateway.ExpensivePaymentGateway(ClientCardDetails); if (MakePayment.Status == "Success") { ClientCardDetails.PaymentState = "processed"; await _IPaymentGateway.SavePaymentStatus(ClientCardDetails); statusMessages.Status = "Success"; statusMessages.Message = MakePayment.Message; } else { ClientCardDetails.PaymentState = "failed"; await _IPaymentGateway.SavePaymentStatus(ClientCardDetails); statusMessages.Status = "failed"; statusMessages.Message = MakePayment.Message; return(BadRequest(statusMessages)); } } else if (ClientCardDetails.Amount > 500) { var MakePayment = await _IPremiumPaymentService.PremiumPaymentService(ClientCardDetails); if (MakePayment.Status == "Success") { ClientCardDetails.PaymentState = "processed"; await _IPaymentGateway.SavePaymentStatus(ClientCardDetails); statusMessages.Status = "Success"; statusMessages.Message = MakePayment.Message; } else { statusMessages.Status = "failed"; statusMessages.Message = MakePayment.Message; ClientCardDetails.PaymentState = "pending"; await _IPaymentGateway.SavePaymentStatus(ClientCardDetails); return(BadRequest(statusMessages)); } } } return(Ok(statusMessages)); } catch (Exception ex) { var result = StatusCode(StatusCodes.Status500InternalServerError, ex); return(result); } }