Ejemplo n.º 1
0
        public ActionResult Config(int?id)
        {
            int            gatewayId = id ?? 0;
            PaymentGateway gateway   = _gatewayRepo.Load(gatewayId);

            var    aName        = GetType().Assembly.GetName();
            string assemblyInfo = aName.Name.ToString() + " (v" + aName.Version.ToString() + ")";

            var model = new ConfigModel();

            model.AssemblyInfo   = assemblyInfo;
            model.ExecutionModes = Enum.GetNames(typeof(EPProvider.GatewayExecutionMode))
                                   .Select(name => new SelectListItem()
            {
                Text = name, Value = name
            })
                                   .ToList();
            model.PaymentMethods = _methodRepo.LoadPaymentMethods(_hiddenMethods).Select(method => new PaymentMethodModel()
            {
                Id   = method.Id,
                Name = method.Name
            }
                                                                                         ).ToList();

            if (gateway != null)
            {
                model.GatewayId = gateway.Id;
                model.PaymentMethods.ForEach(method => method.IsSelected = gateway.PaymentMethods.Any(pm => pm.Id == method.Id));

                var configurationData = gateway.ParseConfigData();
                if (configurationData.ContainsKey("UseDebugMode"))
                {
                    model.UseDebugMode = AlwaysConvert.ToBool(configurationData["UseDebugMode"], false);
                }
                if (configurationData.ContainsKey("ExecutionMode"))
                {
                    model.ExecutionMode = AlwaysConvert.ToEnum <EPProvider.GatewayExecutionMode>(configurationData["ExecutionMode"], EPProvider.GatewayExecutionMode.AlwaysAccept);
                }
                if (configurationData.ContainsKey("UseAuthCapture"))
                {
                    model.UseAuthCapture = AlwaysConvert.ToBool(configurationData["UseAuthCapture"], true);
                }
            }

            return(View("~/Plugins/ExamplePaymentPlugin/Views/Config.cshtml", model));
        }