public async Task <System.Web.Http.IHttpActionResult> InsertPaymentProcessData(PaymentProcess paymentprocess) { bool inserted = false; if (ValidateCreditCard(paymentprocess.CreditCardNumber)) { if (IsCreditCardInfoValid(paymentprocess.ExpirationDate, paymentprocess.SecurityCode)) { if (paymentprocess.Amount > 0) { inserted = await paymentService.InsertPayment(paymentprocess); if (inserted) { if (paymentprocess.Amount <= 20) { if (await cheapPaymentGatewayService.AnalysisPaymentByThisGatewayProcessed(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } else if (await cheapPaymentGatewayService.AnalysisPaymentByThisGatewayPending(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } else if (await cheapPaymentGatewayService.AnalysisPaymentByThisGatewayFailed(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } } else if (paymentprocess.Amount >= 21 && paymentprocess.Amount <= 500) { if (await expensivePaymentGatewayService.AnalysisPaymentByThisGatewayProcessed(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } else if (await expensivePaymentGatewayService.AnalysisPaymentByThisGatewayPending(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } else if (await expensivePaymentGatewayService.AnalysisPaymentByThisGatewayFailed(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } } else if (paymentprocess.Amount > 500) { if (await premiumPaymentService.AnalysisPaymentByThisGatewayProcessed(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } else if (await premiumPaymentService.AnalysisPaymentByThisGatewayPending(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } else if (await premiumPaymentService.AnalysisPaymentByThisGatewayFailed(paymentprocess.Amount, paymentprocess.CreditCardNumber)) { return((System.Web.Http.IHttpActionResult)Ok()); } } return((System.Web.Http.IHttpActionResult)Ok()); } else if (!inserted) { return((System.Web.Http.IHttpActionResult)BadRequest()); } else { return((System.Web.Http.IHttpActionResult)StatusCode(500)); } } else { return((System.Web.Http.IHttpActionResult)BadRequest("Amount can never be negative or zero")); } } else { return((System.Web.Http.IHttpActionResult)BadRequest("Expiry Date or CVV no is invalid")); } } else { return((System.Web.Http.IHttpActionResult)BadRequest("Credit card is invalid")); } }