public PaymentResult GetResponse(Uri uri, NameValueCollection form)
        {
            var result = new PaymentResult()
            {
                Uri = uri,
                Form = form
            };

            var querystring = new Dictionary<string, string>();
            foreach (var query in uri.Query.TrimStart('?').Split('&'))
            {
                var queryPart = query.Split('=');
                querystring.Add(queryPart[0], queryPart[1]);
            }

            return result;
        }
        public PaymentResult GetResponse(Uri uri, NameValueCollection form)
        {
            var result = new PaymentResult()
            {
                Uri = uri,
                Form = form
            };

            var querystring = new Dictionary<string, string>();
            foreach (var query in uri.Query.TrimStart('?').Split('&'))
            {
                var queryPart = query.Split('=');
                querystring.Add(queryPart[0], queryPart[1]);
            }

            //var statusCode = querystring["paymentstatus"];
            var statusCode = querystring["status"];
            result.Token = (querystring.ContainsKey("token")) ? querystring["token"] : "";
            //var transactionState = querystring["lapResponseCode"];
            //result.Attempt = Convert.ToInt32(querystring["referenceCode"].Split('-')[1]);
            //result.TransactionRecord = querystring["reference_pol"];
            result.PaymentType = querystring["PM"];
            result.OrderID = Convert.ToInt32(querystring["orderID"].Replace("WinExigoOrder",""));
            //result.CustomerID = Convert.ToInt32(querystring["_cid"]);
            result.ProviderType = querystring["_p"];
            //result.QueryString = querystring;
            //result.ErrorMessage = GetResponseMessage(statusCode, transactionState);
            result.Status = (statusCode == "success") ? PaymentStatus.Success : PaymentStatus.Fail;

            return result;
        }
        // Gets the Response from the Payment Provider to determine what View Actions we will execute
        public PaymentResult GetResponse(Uri uri, NameValueCollection form)
        {
            // Ingenico Account is configured to return to the following Action: Replicated Site - AppController - PaymentRedirectLanding

            // Based on the type of Shopping Cart identified in the Properties Region of the Shopping Controllers, Enrollment Controller, and Account Controller, the Action, Replicated Site - App Controller - PaymentRedirectLandingComplete determines to which URL / page to redirect the customer when they are being returned to our site from the 3rd Party site - Alan C - 25 June 2015

            var result = new PaymentResult()
            {
                Uri = uri,
                Form = form
            };

            var querystring = new Dictionary<string, string>();
            foreach (var query in uri.Query.TrimStart('?').Split('&'))
            {
                var queryPart = query.Split('=');
                querystring.Add(queryPart[0], queryPart[1]);
            }

            //var statusCode = querystring["paymentstatus"];
            var updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Pending; // Set our order status to Pending by Default - Meaning it is Pending Payment when we do our redirect - Alan C 30, June 2015
            var statusCode = "";

            if (querystring.ContainsKey("ps")) // Look for url paramater "ps" to tell us what the outcome of the redirect was - Alan C, 29 June 2015
            {
                statusCode = querystring["ps"];
            }
            else if (querystring.ContainsKey("STATUS"))
            {
                if (querystring["STATUS"] == "9")
                {
                    statusCode = "success"; // Look for form paramater "STATUS" to tell us what the outcome of the redirect was - Alan C, 29 June 2015
                }
                else
                {
                    statusCode = "fail";
                }

            }
            else if (querystring.ContainsKey("ACCEPTANCE"))
            {
                if (querystring["ACCEPTANCE"].IsNotNullOrEmpty())
                {
                    statusCode = "success"; // Look for the string "Acceptance" to tell us the outcome - Alan C, 29 June 2015
                }
                else
                {
                    statusCode = "fail";
                }
            }
            else statusCode = "fail";

            result.Token = (querystring.ContainsKey("token")) ? querystring["token"] : "";

            if (querystring.ContainsKey("PM"))
            {
                result.PaymentType = querystring["PM"];
            }
            else if (querystring.ContainsKey("BRAND"))
            {
                result.PaymentType = querystring["BRAND"];
            }
            else result.PaymentType = "iDEAL";

            result.OrderID = (querystring.ContainsKey("orderID")) ? Convert.ToInt32(querystring["orderID"]) : Convert.ToInt32(querystring["_oID"]);

            var orderInfo = GetOrderInformation(result.OrderID);

            result.CustomerID = (querystring.ContainsKey("_cid")) ? Convert.ToInt32(querystring["_cid"]) : orderInfo.CustomerID;
            if (querystring["_p"] == "1")
            result.ProviderType = "Ingenico";
            //result.QueryString = querystring;
            result.Status = (statusCode == "success") ? PaymentStatus.Success : PaymentStatus.Fail;

            //switch (statusCode)
            //{
            //    case "success":
            //        updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Accepted;
            //        break;
            //    case "decline":
            //        updatedStatus = Common.Api.ExigoWebService.OrderStatusType.CCDeclined;
            //        break;
            //    case "cancel":
            //        updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Canceled;
            //        break;
            //    default:
            //        updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Pending; // Default - leave order status as Pending per James H at WIN - Alan C 30 June 2015
            //        break;
            //}

            // For displaying feedback data to customer if we are not leaving the sit eto enter payment data - not needed - Alan C, 25 June 2015
            //var transactionState = querystring["lapResponseCode"];
            //result.Attempt = Convert.ToInt32(querystring["referenceCode"].Split('-')[1]);
            //result.TransactionRecord = querystring["reference_pol"];
            //result.ErrorMessage = GetResponseMessage(Convert.ToInt32(statusCode), transactionState);
            //result.ErrorMessage = GetResponseMessage(statusCode, transactionState);

            // Get the Status Code and Determine Which Exigo Order Status Type we will use to update the Order Status in the Admin Portal - Do not try to update an Order Status as "Accepted"
            // per Client - they get that information from deferred data from Ingenico so that customers cannot hack the URL feedback;
            //The deferred response is pointed to the Action "PaymentRedirectLanding" in the Replicated Site App Controller -
            //responses for both the Backoffice and the Replicated Site return here - Alan C, 29 June 2015

            switch (querystring["STATUS"])
            {
                case "0":
                    updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Pending; // Means an error has occurred - We change the Status to Pending so the customer will know to follow up on the Payment due - Alan C 30 June 2015
                    break;
                case "1":
                    updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Canceled; // This code means that the "Cancel" button was clicked on Ingenico - we change the order status to Canceled - Alan C 30 June 2015
                    break;
                //case "5":
                //    updatedStatus = Common.Api.ExigoWebService.OrderStatusType.ACHPending;
                //    break;
                case "7":
                    updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Canceled; // Means the payment has been deleted - so we cancel the order - Alan C 30 June 2015
                    break;
                default:
                    updatedStatus = Common.Api.ExigoWebService.OrderStatusType.Pending; // Default - leave order status as Pending per James H at WIN - Alan C 30 June 2015
                    break;
            }

            // Update the Order Status before we return our result
            var contextcall = Exigo.WebService();
            var request = new ChangeOrderStatusRequest()
            {
                OrderID = result.OrderID,
                OrderStatus = updatedStatus
            };
            var response = contextcall.ChangeOrderStatus(request);

            //var context = Exigo.ODataLogging();
            //var logging = context.Logs.Where(l => l.OrderID == result.OrderID).FirstOrDefault();
            //logging.Response = result.Uri.ToString();
            //logging.ResponseDate = DateTime.Now;
            //context.UpdateObject(logging);
            //context.SaveChanges();

            return result; // Return our result and response data to the Controller to execute the final actions we need to occur in the Views and Controller
        }