public ActionResult Config(ConfigModel model, FormCollection form) { var paymentMethods = _methodRepo.LoadPaymentMethods(_hiddenMethods); PaymentGateway gateway = model.GatewayId.HasValue ? _gatewayRepo.Load(model.GatewayId.Value) : null; model.ShowConfirmationMessage = true; if (gateway == null) { string classId = Misc.GetClassId(typeof(EPProvider)); var provider = Activator.CreateInstance(Type.GetType(classId)) as IPaymentProvider; gateway = new PaymentGateway(); gateway.ClassId = classId; gateway.Name = provider.Name; gateway.Store = AbleContext.Current.Store; model.ShowConfirmationMessage = false; } Dictionary <string, string> configData = new Dictionary <string, string>(); configData.Add("UseDebugMode", model.UseDebugMode.ToString()); configData.Add("ExecutionMode", model.ExecutionMode.ToString()); configData.Add("UseAuthCapture", model.UseAuthCapture.ToString()); gateway.UpdateConfigData(configData); _gatewayRepo.Save(gateway); //UPDATE PAYMENT METHODS var selectedKeys = form.AllKeys.Where(key => key.ToUpper().StartsWith("METHOD_CHK_", StringComparison.InvariantCultureIgnoreCase)).ToList(); foreach (var key in selectedKeys) { int paymentMethodId = AlwaysConvert.ToInt(key.Substring(11)); PaymentMethod method = paymentMethods.Where(m => m.Id == paymentMethodId).FirstOrDefault(); if (method != null) { if (form[key].Contains("true")) { method.PaymentGateway = gateway; } else if (method.PaymentGateway != null && method.PaymentGateway.Id == gateway.Id) { method.PaymentGateway = null; } _methodRepo.Save(method); } } if (model.SaveOnly.Equals("true")) { return(Json(new { status = "Success", Id = gateway.Id, showMessage = model.ShowConfirmationMessage })); } else { return(Json(new { status = "Redirect", Url = Url.Action("Gateways", "Payments") })); } }
public ActionResult Save(PaymentMethods model) { try { var data = repository.Save(model); return(Ok(new { success = true, successMessage = "Saved Successfully!" })); } catch (Exception ex) { return(Ok(new { success = false, errorMessage = ex.GetBaseException() })); } }
public int Save(PaymentMethod paymentMethod) { int saveIndex = 0; try { paymentMethod.IsActive = true; paymentMethod.CreatedDate = DateTime.Now; saveIndex = _paymentMethodRepository.Save(paymentMethod); } catch (Exception exception) { throw new Exception(exception.Message); } return(saveIndex); }
public IActionResult EditPaymentMethod(PaymentMethod model) { if (ModelState.IsValid) { if (model.ID > 0) { PaymentMethod old = _payRepo.PaymentMethods.Where(x => x.ID == model.ID).First(); if (old.IsCredit && !model.IsCredit) { _creditRepo.Delete(old.CreditBalance.ID); } } _payRepo.Save(model); if (model.IsCredit) { CreditBalance c = new CreditBalance { Amount = 0.00, PaymentMethodID = _payRepo.PaymentMethods.Last().ID }; _creditRepo.Save(c); } TempData["message"] = $"{model.Method} has been saved"; return(RedirectToAction("PaymentMethods")); } else { if (model.ID == 0) { ViewBag.FormTitle = "Create Payment Method"; } else { ViewBag.FormTitle = "Edit Payment Method"; } return(View(model)); } }