public ActionResult DonateCampaign(CampaignMainViewModel ViewModel) { try { ViewModel.CampaignDonations.StoryId = ViewModel.Id; ViewModel.CampaignDonations.Latitude = ViewModel.Latitude; ViewModel.CampaignDonations.Longitude = ViewModel.Longitude; var DId = IService.AddCampaignDonation(ViewModel.CampaignDonations); var m = IService.GetCamapign(ViewModel.Id); //{ m.CampaignDonations.DonationMoneyType = "0"; } MiniDonationModel model = new MiniDonationModel(); model.DonateId = DId; model.Amount = ViewModel.CampaignDonations.DonationAmnt; model.MType = ViewModel.CampaignDonations.DonationMoneyType; model.Uname = ViewModel.CampaignDonations.IdentityName; model.Email = ViewModel.CampaignDonations.EMail; model.PhNo = ViewModel.CampaignDonations.PhNo != "" ? ViewModel.CampaignDonations.PhNo : "9999999999"; return(RedirectToAction("PayYourDonations", model)); } catch (Exception ex) { throw ex; } }
public MiniDonationModel CreateOrderRazorPay(MiniDonationModel model) { try { var typeNmae = model.MType; Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("amount", model.Amount * 100); // this amount should be same as transaction amount input.Add("currency", typeNmae); input.Add("receipt", model.DonateId.ToString()); input.Add("payment_capture", 1); Dictionary <string, string> notees = new Dictionary <string, string>(); notees.Add("CampaignId", model.campaignId.ToString()); // this amount should be same as transaction amount input.Add("notes", notees); string key = ConfigurationManager.AppSettings["RPapikey"]; string secret = ConfigurationManager.AppSettings["RPSecretkey"]; //string key = "rzp_test_5iPslGRlz5M0ss"; //string secret = "qEsCxVcyaRoSAatpBaVZMBdp"; ////string key = "rzp_live_S9v0s4ePfuxE1p"; ////string secret = "KJylHsBzeIlVeF336TPxjk6w"; System.Net.ServicePointManager.SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12; RazorpayClient client = new RazorpayClient(key, secret); Razorpay.Api.Order order = client.Order.Create(input); var orderId = order["id"].ToString(); model.orderId = orderId; model.RazorPayKey = key; UpdateCampaignDonationorder(model.DonateId, orderId, "", ""); return(model); } catch (Exception ex) { throw ex; } }
public ActionResult PayYourDonations(MiniDonationModel model) { var typeM = (MoneyType)(Convert.ToInt32(model.MType)); var typeNmae = typeM.DisplayName(); Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("amount", model.Amount * 100); // this amount should be same as transaction amount input.Add("currency", typeNmae); input.Add("receipt", model.DonateId.ToString()); input.Add("payment_capture", 0); string key = ConfigurationManager.AppSettings["RPapikey"]; string secret = ConfigurationManager.AppSettings["RPSecretkey"]; //string key = "rzp_test_5iPslGRlz5M0ss"; //string secret = "qEsCxVcyaRoSAatpBaVZMBdp"; ////string key = "rzp_live_S9v0s4ePfuxE1p"; ////string secret = "KJylHsBzeIlVeF336TPxjk6w"; ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; RazorpayClient client = new RazorpayClient(key, secret); Razorpay.Api.Order order = client.Order.Create(input); var orderId = order["id"].ToString(); ViewBag.Order = orderId; model.orderId = orderId; ViewBag.Amount = model.Amount * 100; ViewBag.EMail = model.Email; ViewBag.RPkey = key; IService.UpdateCampaignDonationorder(model.DonateId, orderId, "", ""); return(View(model)); }
// POST api/<controller> public async Task <HttpResponseMessage> Post([FromBody] CampaignMiniDonation viewModel) { try { MiniDonationModel model = await serve.AddCampaignDonation(viewModel); ResponseObject response = new ResponseObject(); response.campaignId = viewModel.CampaignId.ToString(); response.ResponseMsg = "Campaign Donation with order id created successfully"; return(Request.CreateResponse(HttpStatusCode.OK, model)); } catch (Exception ex) { ResponseObject response = new ResponseObject(); response.ExceptionMsg = ex.ToString(); response.ResponseMsg = "Campaign Donation with order id creation - is not successful"; response.ErrorCode = HttpStatusCode.InternalServerError.ToString(); return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } }
public async Task <MiniDonationModel> AddCampaignDonation(CampaignMiniDonation viewModel) { try { if (viewModel.id == 0) { Tbl_CampaignDonation donation = new Tbl_CampaignDonation(); donation.StoryId = viewModel.CampaignId; donation.DonatedBy = viewModel.DonorName; donation.DonatedOn = DateTime.Now; donation.MoneyType = viewModel.DonationMoneyType; donation.DonationAmnt = viewModel.DonationAmnt; donation.PhoneNumber = viewModel.PhoneNumber; donation.Email = viewModel.EMail; donation.isAnanymous = viewModel.isAnanymous; string RazorPayProcessingFeePerc = ConfigurationManager.AppSettings["RazorPayProcessingFeePerc"]; string RazorPayGSTPerc = ConfigurationManager.AppSettings["RazorPayGSTPerc"]; donation.PayGSTPerc = Convert.ToInt32(Convert.ToDecimal(RazorPayGSTPerc) * 100); donation.PayProcessingFeePerc = Convert.ToInt32(Convert.ToDecimal(RazorPayProcessingFeePerc) * 100); donation.PayProcessingFeeAmnt = viewModel.DonationAmnt * Convert.ToDecimal(RazorPayProcessingFeePerc); donation.PayGSTAmnt = donation.PayProcessingFeeAmnt * Convert.ToDecimal(RazorPayGSTPerc); donation.PaidDOnationAmt = viewModel.DonationAmnt - (donation.PayProcessingFeeAmnt + donation.PayGSTAmnt); donation.Status = true; Entity.Tbl_CampaignDonation.Add(donation); Entity.SaveChanges(); var donateId = donation.Id; MiniDonationModel model = new MiniDonationModel(); model.Amount = viewModel.DonationAmnt; model.MType = viewModel.DonationMoneyType; model.DonateId = donateId; model.PhNo = viewModel.PhoneNumber; model.Email = viewModel.EMail; model.campaignId = viewModel.CampaignId; model = CreateOrderRazorPay(model); var CurrentDetail = await(from cm in Entity.Tbl_Campaign.AsNoTracking() join Dn in Entity.Tbl_CampaignDonation.AsNoTracking() on cm.Id equals Dn.StoryId into outerJoinDon from Dn in outerJoinDon.DefaultIfEmpty() where cm.Id == viewModel.CampaignId select new { CampaignId = cm.Id, cm.TargetAmount, DonationId = Dn != null ? Dn.Id : 0, DonatedBy = Dn != null ? Dn.DonatedBy : "", DonatedOn = Dn != null ? Dn.DonatedOn : DateTime.Now, isAnanymous = Dn != null ? Dn.isAnanymous : true, DonationAmnt = Dn != null ? Dn.DonationAmnt : 0, isPaid = Dn != null ? Dn.isPaid : false }).ToListAsync(); var DonList = CurrentDetail.Where(x => x.isPaid == true).GroupBy(x => x.CampaignId) .Select(g => new { DonatedBy = g.Key, Total = g.Sum(x => x.DonationAmnt) }); var DonorList = CurrentDetail.Where(x => x.isPaid == true) .GroupBy(x => x.DonatedBy) .Select(g => new { DonatedBy = g.Key, Total = g.Sum(x => x.DonationAmnt) }); var targetAmount = CurrentDetail.FirstOrDefault() != null?CurrentDetail.FirstOrDefault().TargetAmount.Value : 0; var RaisedAmt = DonList.Any() ? DonList.ToList().FirstOrDefault().Total : 0; decimal difference = targetAmount - RaisedAmt; var RaisedBy = DonorList.Any() ? DonorList.Distinct().ToList().Count() : 0; model.TotalDonorsCount = RaisedBy; model.CanDonate = difference > 0 ? true : false; model.TotalRaisedAmnt = RaisedAmt; model.EligibleTarget = difference > 0 ? difference : 0; return(model); } else { var donation = (from S in Entity.Tbl_CampaignDonation where S.Id == viewModel.id select S).FirstOrDefault(); if (donation != null) { donation.DonatedBy = viewModel.DonorName; donation.DonatedOn = DateTime.Now; donation.MoneyType = viewModel.DonationMoneyType; donation.DonationAmnt = viewModel.DonationAmnt; donation.PhoneNumber = viewModel.PhoneNumber; donation.Email = viewModel.EMail; donation.isAnanymous = viewModel.isAnanymous; string RazorPayProcessingFeePerc = ConfigurationManager.AppSettings["RazorPayProcessingFeePerc"]; string RazorPayGSTPerc = ConfigurationManager.AppSettings["RazorPayGSTPerc"]; donation.PayGSTPerc = Convert.ToInt32(Convert.ToDecimal(RazorPayGSTPerc) * 100); donation.PayProcessingFeePerc = Convert.ToInt32(Convert.ToDecimal(RazorPayProcessingFeePerc) * 100); donation.PayProcessingFeeAmnt = viewModel.DonationAmnt * Convert.ToDecimal(RazorPayProcessingFeePerc); donation.PayGSTAmnt = donation.PayProcessingFeeAmnt * Convert.ToDecimal(RazorPayGSTPerc); donation.PaidDOnationAmt = viewModel.DonationAmnt - (donation.PayProcessingFeeAmnt + donation.PayGSTAmnt); donation.Status = true; donation.UpdatedOn = DateTime.UtcNow; Entity.SaveChanges(); MiniDonationModel model = new MiniDonationModel(); model.Amount = viewModel.DonationAmnt; model.MType = viewModel.DonationMoneyType; model.DonateId = viewModel.id; model.PhNo = viewModel.PhoneNumber; model.Email = viewModel.EMail; model = CreateOrderRazorPay(model); var CurrentDetail = await(from cm in Entity.Tbl_Campaign.AsNoTracking() join Dn in Entity.Tbl_CampaignDonation.AsNoTracking() on cm.Id equals Dn.StoryId into outerJoinDon from Dn in outerJoinDon.DefaultIfEmpty() where cm.Id == viewModel.CampaignId select new { CampaignId = cm.Id, cm.TargetAmount, DonationId = Dn != null ? Dn.Id : 0, DonatedBy = Dn != null ? Dn.DonatedBy : "", DonatedOn = Dn != null ? Dn.DonatedOn : DateTime.Now, isAnanymous = Dn != null ? Dn.isAnanymous : true, DonationAmnt = Dn != null ? Dn.DonationAmnt : 0, isPaid = Dn != null ? Dn.isPaid : false }).ToListAsync(); var DonList = CurrentDetail.Where(x => x.isPaid == true).GroupBy(x => x.CampaignId) .Select(g => new { DonatedBy = g.Key, Total = g.Sum(x => x.DonationAmnt) }); var DonorList = CurrentDetail.Where(x => x.isPaid == true) .GroupBy(x => x.DonatedBy) .Select(g => new { DonatedBy = g.Key, Total = g.Sum(x => x.DonationAmnt) }); var targetAmount = CurrentDetail.FirstOrDefault() != null?CurrentDetail.FirstOrDefault().TargetAmount.Value : 0; var RaisedAmt = DonList.Any() ? DonList.ToList().FirstOrDefault().Total : 0; decimal difference = targetAmount - RaisedAmt; var RaisedBy = DonorList.Any() ? DonorList.Distinct().ToList().Count() : 0; model.TotalDonorsCount = RaisedBy; model.CanDonate = difference > 0 ? true : false; model.TotalRaisedAmnt = RaisedAmt; model.EligibleTarget = difference > 0 ? difference : 0; return(model); } else { return(new MiniDonationModel()); } } } catch (Exception ex) { throw ex; } }