public ViewResult CapturePayment(string paymentId) { RazorpayClient client = new RazorpayClient(_key, _secret); Razorpay.Api.Payment payment = client.Payment.Fetch(paymentId); var amount = payment.Attributes["amount"]; var currency = payment.Attributes["currency"]; Dictionary <string, object> options = new Dictionary <string, object>(); options.Add("amount", amount); options.Add("currency", currency); Razorpay.Api.Payment paymentCaptured = payment.Capture(options); ViewBag.Message = "Payment capatured!"; return(View("Success")); }
public ActionResult PaymentComplete() { string paymentId = Request.Params["rzp_paymentid"]; // This is orderId string orderId = Request.Params["rzp_orderid"]; Razorpay.Api.RazorpayClient client = new Razorpay.Api.RazorpayClient(razorKey, razorSecred); Razorpay.Api.Payment payment = client.Payment.Fetch(paymentId); PreBookingDtl obj = Session["OrderDetails"] as PreBookingDtl; // This code is for capture the payment Dictionary <string, object> options = new Dictionary <string, object>(); options.Add("amount", payment.Attributes["amount"]); Razorpay.Api.Payment paymentCaptured = payment.Capture(options); string amt = paymentCaptured.Attributes["amount"]; if (paymentCaptured.Attributes["status"] == "captured") { obj.BookingStatus = "Booked"; obj.PaymentGatewayCode = paymentId; string jsonStr = JsonConvert.SerializeObject(obj); string result = objAPI.PostRecordtoApI("webrequest", "PayNow", jsonStr); TempData["ErrMsg"] = result; return(RedirectToAction("PaymentSuccess", "Home", new { BookingID = result })); } else { obj.BookingStatus = "Failed"; //obj.PaymentGatewayCode = paymentId; //string jsonStr = JsonConvert.SerializeObject(obj); //string result = objAPI.PostRecordtoApI("webrequest", "PayNow", jsonStr); TempData["ErrMsg"] = "Failed"; return(RedirectToAction("PaymentFailed", "Home", new { obj.HotelID })); } }
private bool CapturePayment(ref Model.PaymentModel pViewModel) { try { decimal netPrice = pViewModel.AmountCharged; if (netPrice > 0) { string paymentId = pViewModel.GatewayResponse; Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("amount", netPrice * 100); // this amount should be same as transaction amount string key = ImTech.Service.Common.ConfigurationManager.PaymentGatewayKey; string secret = ImTech.Service.Common.ConfigurationManager.PaymentGatewaySecret; RazorpayClient client = new RazorpayClient(key, secret); Razorpay.Api.Payment payment = client.Payment.Fetch(paymentId); Razorpay.Api.Payment capturedPayment = payment.Capture(input); string json = capturedPayment.Attributes.ToString(); dynamic JsonDe = JsonConvert.DeserializeObject(json); PaymentStatus status = JsonDe.status.ToString().ToUpper() == "captured".ToUpper() ? PaymentStatus.Capture : PaymentStatus.CaptureFailed; pViewModel.GatewayResponse = paymentId + "-->ResponseJson-->" + json; if (status == PaymentStatus.Capture) { if (WebCommon.NotificationEnabled) { var consultationDetails = _dataServices.ConsultationService.GetConsultationDetails(pViewModel.ConsultationID, pViewModel.TenantID); var doctor = _dataServices.DoctorService.GetDoctor(consultationDetails.DoctorId, pViewModel.TenantID); if (consultationDetails != null) { var userDetails = _dataServices.UserService.GetUser(consultationDetails.CreatedBy, pViewModel.TenantID); List <object> additionalParameters = new List <object>(); additionalParameters.Add(userDetails.Email); additionalParameters.Add(userDetails.PhoneNumber); additionalParameters.Add(doctor.EmailAddress); additionalParameters.Add(doctor.PhoneNumber); additionalParameters.Add(consultationDetails.Patient.PatientName); additionalParameters.Add(doctor.FirstName + " " + doctor.LastName); additionalParameters.Add(pViewModel.AmountCharged); additionalParameters.Add(consultationDetails.ConsultationMode); NotificationClient.Instance.SendMessage(null, ImTech.Notification.Messages.MessageType.Consultation_User, additionalParameters); NotificationClient.Instance.SendMessage(null, ImTech.Notification.Messages.MessageType.Consultation_Doctor, additionalParameters); } } return(true); } else { return(true); } } else { return(true); } } catch (Exception ex) { string errorMsg = string.Empty; if (ex.InnerException != null) { errorMsg = ex.InnerException.Message; } else { errorMsg = ex.Message; } _logger.LogError(new LogMessage { Summary = errorMsg, Exception = Convert.ToString(ex.StackTrace), UserId = 0, UserType = 0, Application = "Web" }); return(true); } }