public ResponseModel ProcessPayment(PaymentModel request)
        {
            try
            {
                request.CreditCardNumber = request.CreditCardNumber.Replace(" ", "").Trim();
                if (request.Amount < appSettings.Value.CheapAmount)
                {
                    //call cheap service
                    return(_cheapPaymentGateway.ProcessPayment(request));
                }
                if (request.Amount >= appSettings.Value.ExpensiveAmountMin && request.Amount <= appSettings.Value.ExpensiveAmountMax)
                {
                    //call expensive service
                    return(_expensivePaymentGateway.ProcessExpensivePayment(request));
                }

                if (request.Amount > appSettings.Value.PremiumAmount)
                {
                    //premium service.
                    return(_premiumPaymentService.ProcessPremiumPayment(request));
                }

                return(ResponseDictionary.ProvideResponse("04"));
            }
            catch (Exception ex)
            {
                Trace.TraceInformation($"An error occurred, {ex.Message}");
                return(ResponseDictionary.ProvideResponse("06"));
            }
        }
        public async Task <APIResponse> ProcessPayment(CardInfoDTO request)
        {
            var response = new APIResponse();

            try
            {
                var amount = request.Amount;
                if (amount < 20)
                {
                    response = await _cheapPaymentGateway.ProcessCheapPayment(request);
                }
                else if (amount >= 21 && amount <= 500)
                {
                    if (_expensivePaymentGateway != null)
                    {
                        response = await _expensivePaymentGateway.ProcessExpensivePayment(request);
                    }
                    else
                    {
                        response = await _cheapPaymentGateway.ProcessCheapPayment(request);
                    }
                }
                else if (amount > 500)
                {
                    int count = 0;
                    response = await _premiumPayment.ProcessPremiumPayment(request);

                    if (response.Code == "99")
                    {
                        while (response.Code == "99" && count <= 3)
                        {
                            response = await _premiumPayment.ProcessPremiumPayment(request);

                            count++;
                        }
                    }
                }
                else
                {
                    response = new APIResponse {
                        Code = "99", Description = "Your payment cannot be processed", Data = ""
                    };
                }

                var paymentState = new PaymentState();
                paymentState.CorrelationId  = Guid.NewGuid().ToString();
                paymentState.PayDate        = DateTime.Now;
                paymentState.RequestString  = JsonTranformer.SerializeObject(request);
                paymentState.ResponseString = JsonTranformer.SerializeObject(response);
                if (response.Code == "00")
                {
                    paymentState.State = State.processed;
                }
                if (response.Code == "99")
                {
                    paymentState.State = State.failed;
                }
                else
                {
                    paymentState.State = State.pending;
                }

                _repositoryWrapper.PaymentStateRepository.Create(paymentState);
                await _repositoryWrapper.SaveAsync();
            }
            catch (Exception)
            {
                response = new APIResponse {
                    Code = "99", Description = "Internal Server Error", Data = ""
                };
                throw;
            }
            return(response);
        }