public IHttpActionResult getPayment([FromBody] ProcessPaymentDTO processPaymentDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid payment details"));
            }

            //update the paymentdetails table
            var paymentFound = _context.PaymentDetails.FirstOrDefault(p => p.txtRef == processPaymentDTO.txnref);

            if (paymentFound == null)
            {
                return(BadRequest("Invalid payment detail transaction Ref!"));
            }

            //return payment details
            var paymentResponseDTO = new PaymentResponseDTO
            {
                responseCode        = paymentFound.ResponseCode,
                responsedescription = paymentFound.Description,
                txtref = paymentFound.txtRef,
                payref = paymentFound.Payref,
                retref = paymentFound.RetRef
            };

            return(Ok(paymentResponseDTO));
        }
        public ActionResult <string> CompleteProcessing(ProcessPaymentDTO paymentDTO)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:3797");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                HttpResponseMessage response = client.GetAsync("api/ProcessPayment?creditCardNumber=" + paymentDTO.CardNumber + "&creditLimit=" + paymentDTO.CardLimit + "&processingCharge=" + paymentDTO.ProcessCharge).Result;
                if (response.IsSuccessStatusCode)
                {
                    double balance = response.Content.ReadAsAsync <double>().Result;
                    if (balance >= 0)
                    {
                        //_repo.UpdataBalance(cardNumber, balance);
                        return(Ok(balance.ToString()));
                    }
                    else
                    {
                        return(BadRequest("Insufficient Balance"));
                    }
                }
                else
                {
                    return(BadRequest("Something went wrong"));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public HttpResponseMessage UpdatePayment([FromBody] ProcessPaymentDTO processPaymentDTO)
        {
            var updatedTime = DateTime.UtcNow;
            //update the paymentdetails table
            var paymentFound =
                _context.DstvTransactionPaymentsDetails.FirstOrDefault(p => p.txtRef == processPaymentDTO.txnref);

            //update paymentdetail table
            try
            {
                if (String.IsNullOrEmpty(processPaymentDTO.txnref.Trim()) ||
                    String.IsNullOrEmpty(processPaymentDTO.payRef.Trim()) ||
                    String.IsNullOrEmpty(processPaymentDTO.retRef.Trim()))
                {
                    paymentFound.ResponseCode = "";
                    paymentFound.Description  = "";
                }
                else
                {
                    // insert in dstvTransactionCode table

                    paymentFound.ResponseCode = "00";
                    paymentFound.Description  = "Approved Successful";
                }

                paymentFound.txtRef     = processPaymentDTO.txnref;
                paymentFound.Payref     = processPaymentDTO.payRef;
                paymentFound.RetRef     = processPaymentDTO.retRef;
                paymentFound.updated_at = updatedTime;

                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                paymentFound.ResponseCode = "";
                paymentFound.Description  = "";
                paymentFound.txtRef       = processPaymentDTO.txnref;
                paymentFound.Payref       = processPaymentDTO.payRef;
                paymentFound.RetRef       = processPaymentDTO.retRef;
                paymentFound.updated_at   = updatedTime;

                _context.SaveChanges();
            }

            var redirect_url = ConfigurationManager.AppSettings["dstvResponsePage"];
            var response     = Request.CreateResponse(HttpStatusCode.Moved);

            response.Headers.Location = new Uri(redirect_url +
                                                "?txnRef=" + processPaymentDTO.txnref
                                                //"&payRef=" + processPaymentDTO.payRef +
                                                //"&retRef=" + processPaymentDTO.retRef
                                                );

            return(response);
        }
        public async Task <IActionResult> ProcessPayment([FromBody] ProcessPaymentDTO request)
        {
            var validateCardDetails = Validators.ValidateCardDetails(request);

            if (validateCardDetails.Count > 0)
            {
                return(new BadRequestObjectResult(new ApiValidationErrorResponse
                {
                    StatusCode = 404,
                    Message = "Validation failed",
                    Errors = (IEnumerable <string>)validateCardDetails
                }));
            }

            var cardDetails = _mapper.Map <CardDetails>(request);
            var result      = await _paymentHandler.ProcessPayment(cardDetails);

            return(Ok(result));
        }
Example #5
0
        public static List <string> ValidateCardDetails(ProcessPaymentDTO cardDetails)
        {
            var listError = new List <string>();

            if (!ValidateCreditCard(cardDetails.CreditCardNumber))
            {
                listError.Add(string.Format("Not a valid credit card number : {0}.", cardDetails.CreditCardNumber));
            }
            if (!string.IsNullOrEmpty(cardDetails.SecurityCode) && cardDetails.SecurityCode.Length != 3)
            {
                listError.Add(string.Format("Not a valid security code : {0}.", cardDetails.SecurityCode));
            }
            if (cardDetails.ExpirationDate.Year < System.DateTime.Now.Year || cardDetails.ExpirationDate.Month < System.DateTime.Now.Month)
            {
                listError.Add(string.Format("Not a valid expiration date : {0}.", cardDetails.ExpirationDate));
            }
            if (cardDetails.Amount < 0)
            {
                listError.Add(string.Format("Not a valid amount : {0}.", cardDetails.Amount));
            }
            return(listError);
        }
        public HttpResponseMessage UpdatePayment([FromBody] ProcessPaymentDTO processPaymentDTO)
        {
            var updatedTime = DateTime.UtcNow;
            //update the paymentdetails table
            var paymentFound = _context.PaymentDetails.FirstOrDefault(p => p.txtRef == processPaymentDTO.txnref);

            //update paymentdetail table
            if (processPaymentDTO.txnref.Trim() == "" || processPaymentDTO.payRef.Trim() == "" || processPaymentDTO.retRef.Trim() == "")
            {
                paymentFound.ResponseCode = "";
                paymentFound.Description  = "";
            }
            else
            {
                paymentFound.ResponseCode = "00";
                paymentFound.Description  = "Approved Successful";
            }

            paymentFound.txtRef          = processPaymentDTO.txnref;
            paymentFound.Payref          = processPaymentDTO.payRef;
            paymentFound.RetRef          = processPaymentDTO.retRef;
            paymentFound.TransactionDate = updatedTime;

            _context.SaveChanges();

            var redirect_url = ConfigurationManager.AppSettings["responsePage"];
            var response     = Request.CreateResponse(HttpStatusCode.Moved);

            response.Headers.Location = new Uri(redirect_url +
                                                "?txnRef=" + processPaymentDTO.txnref
                                                //"&payRef=" + processPaymentDTO.payRef +
                                                //"&retRef=" + processPaymentDTO.retRef
                                                );

            return(response);
        }