public async Task <ActionResult> MakePayment(MembershipFeeVM model) { var userId = User.Identity.GetUserId(); var hasPayed = await db.MembershipFee.AsNoTracking().Where(x => x.ActiveMemberId.Equals(userId)) .FirstOrDefaultAsync(); if (hasPayed != null) { return(RedirectToAction("RetryMembershipRegistration", new { orderId = hasPayed.OrderId })); } var member = await db.ActiveMember.AsNoTracking().Where(x => x.ActiveMemberId.Equals(userId)) .FirstOrDefaultAsync(); var paylist = new List <Paylist>(); var paymentList = await db.MembershipFee.AsNoTracking().ToListAsync(); foreach (var pay in paylist) { var myPay = new Paylist { PayTypeName = pay.PayTypeName, Amount = pay.Amount, Description = pay.Description }; paylist.Add(myPay); } var confirmPayment = new SelectPaymentVm { ActiveMemberId = User.Identity.GetUserId(), FeeCategory = model.FeeCategory, TotalAmount = paymentList.Sum(s => s.PaidFee), }; var paytype = from PaymentType p in Enum.GetValues(typeof(PaymentType)) select new { ID = p, Name = p.ToString() }; ViewBag.PayType = new SelectList(paytype, "Name", "Name"); ViewBag.ActiveMemberId = new SelectList(db.ActiveMember, "ActiveMemberId", "FullName"); return(RedirectToAction("Create", confirmPayment)); }
//GET public async Task <ActionResult> Create(MembershipFeeVM model) { if (model.FeeCategory.Equals(PaymentType.MembershipRegistration.ToString()) && _IsPayedMembershipRegistration.Equals(true)) { return(RedirectToAction("Index")); } if (model.FeeCategory.Equals(PaymentType.MonthlyDues.ToString()) && _IsPayedMonthlyDues.Equals(true)) { return(RedirectToAction("Index")); } var memberId = User.Identity.GetUserId(); var hasPayedList = await db.MembershipFee.AsNoTracking().Where(x => x.ActiveMemberId == memberId && x.FeeCategory == model.FeeCategory) .ToListAsync(); var member = await db.ActiveMember.AsNoTracking() .Where(x => x.ActiveMemberId == memberId).FirstOrDefaultAsync(); var paymentList = await db.MemberFeeType.AsNoTracking() .Where(x => x.FeeCategory == model.FeeCategory) .ToListAsync(); var fullName = $"{member.Fullname}"; var paylist = new List <Paylist>(); foreach (var fee in paymentList) { var myFee = new Paylist { PayTypeName = fee.FeeName, Amount = fee.Amount, Description = fee.Description }; paylist.Add(myFee); } System.Threading.Thread.Sleep(1); long milliseconds = DateTime.Now.Ticks; var url = Url.Action("ConfrimPayment", "MembershipFee", new { }, protocol: Request.Url.Scheme); if (hasPayedList != null) { foreach (var hasPayed in hasPayedList) { if (hasPayed.Status.Equals(false)) { string serviceTypeId = string.Empty; if (hasPayed.FeeCategory.Equals(PaymentType.MembershipRegistration.ToString())) { serviceTypeId = RemitaConfigParam.MEMBERSHIPREGISTRATION; } else if (hasPayed.FeeCategory.Equals(PaymentType.MonthlyDues.ToString())) { serviceTypeId = RemitaConfigParam.MONTHLYDUES; } //var amount = paymentList.Sum(s => s.Amount).ToString(); var hashed = _query.HashRemitedValidate(hasPayed.OrderId, RemitaConfigParam.APIKEY, RemitaConfigParam.MERCHANTID); string checkurl = RemitaConfigParam.CHECKSTATUSURL + "/" + RemitaConfigParam.MERCHANTID + "/" + hasPayed.OrderId + "/" + hashed + "/" + "orderstatus.reg"; string jsondata = new WebClient().DownloadString(checkurl); var result = JsonConvert.DeserializeObject <RemitaResponse>(jsondata); if (string.IsNullOrEmpty(result.Rrr)) { var entry = db.Entry(hasPayed); if (entry.State == EntityState.Detached) { db.MembershipFee.Attach(hasPayed); } db.MembershipFee.Remove(hasPayed); await db.SaveChangesAsync(); } else { return(RedirectToAction("ConfrimPayment", new { orderID = hasPayed.OrderId })); } } } } var confirmPaymentVm = new ConfirmPaymentVM(); confirmPaymentVm.Paylist = paylist; confirmPaymentVm.MemberName = fullName; confirmPaymentVm.ActiveMemberId = memberId; confirmPaymentVm.FeeCategory = model.FeeCategory; confirmPaymentVm.TotalAmount = paymentList.Sum(s => s.Amount); confirmPaymentVm.payerName = fullName; confirmPaymentVm.payerPhone = member.PhoneNumber; if (model.FeeCategory.Equals(PaymentType.MembershipRegistration.ToString())) { confirmPaymentVm.amt = paymentList.Sum(s => s.Amount).ToString(); confirmPaymentVm.TotalAmount = paymentList.Sum(s => s.Amount); } if (model.FeeCategory.Equals(PaymentType.MonthlyDues.ToString())) { confirmPaymentVm.amt = paymentList.Sum(s => s.Amount).ToString(); confirmPaymentVm.TotalAmount = paymentList.Sum(s => s.Amount); } confirmPaymentVm.merchantId = RemitaConfigParam.MERCHANTID; confirmPaymentVm.orderId = $"NACCPlateau{milliseconds}"; confirmPaymentVm.responseurl = url; confirmPaymentVm.serviceTypeId = RemitaConfigParam.MEMBERSHIPREGISTRATION; confirmPaymentVm.paymentType = model.MemberFeeType; return(View(confirmPaymentVm)); }