public ApiResult <PaymentOrderResponceViewModel> GetOrderDetails(int orderId) { var OrderId = new SqlParameter("@Order_Id", System.Data.SqlDbType.Int) { Value = orderId }; try { var Data = _context.ExecuteStoreProcedure("dbo.usp_GetTotalOrderPricdeByOrderID", OrderId); PaymentOrderResponceViewModel resultModel = null; string orderRef = string.Empty; if (Data != null && Data.Tables.Count > 0 && Data.Tables[0].Rows.Count > 0) { foreach (System.Data.DataRow row in Data.Tables[0].Rows) { resultModel = new PaymentOrderResponceViewModel { Price = (row["TotalOrderPrice"] != DBNull.Value) ? Convert.ToDecimal(row["TotalOrderPrice"]) : 0, InvoiceNo = (row["InvoiceNo"] != DBNull.Value) ? Convert.ToString(row["InvoiceNo"]) : string.Empty, EmailId = (row["EmailId"] != DBNull.Value) ? Convert.ToString(row["EmailId"]) : string.Empty, CustomerId = (row["CustomerId"] != DBNull.Value) ? Convert.ToString(row["CustomerId"]) : string.Empty, CustomerName = (row["CustomerName"] != DBNull.Value) ? Convert.ToString(row["CustomerName"]) : string.Empty, MobileNo = (row["MobileNo"] != DBNull.Value) ? Convert.ToString(row["MobileNo"]) : string.Empty, DeviceType = (row["DeviceType"] != DBNull.Value) ? Convert.ToString(row["DeviceType"]) : string.Empty, IsBookingOn = true }; } } if (resultModel != null) { return(new ApiResult <PaymentOrderResponceViewModel>(new ApiResultCode(ApiResultType.Success), resultModel)); } return(new ApiResult <PaymentOrderResponceViewModel>(new ApiResultCode(ApiResultType.Error), resultModel)); } catch (Exception ex) { ErrorTrace.Logger(LogArea.ApplicationTier, ex); return(new ApiResult <PaymentOrderResponceViewModel>(new ApiResultCode(ApiResultType.ExceptionDuringOpration, 3, "Please contact system administrator"))); } }
public async Task <ActionResult> Index(int orderId, string pgType) { PaymetIfoRequestViewModel model = null; var resultData = new PaymentOrderResponceViewModel(); var data = new PaymentOrderResponceViewModel(); if (string.IsNullOrEmpty(pgType)) { pgType = _appSettings.PGType; } if (pgType.Equals("2")) { pgType = _appSettings.PGType; } EnumType.PaymentGateWayType paymentGateWayType = (EnumType.PaymentGateWayType)Enum.Parse(typeof(EnumType.PaymentGateWayType), pgType); string pgRequestData = string.Empty; bool isExist = false; switch (paymentGateWayType) { #region RAZORPAY PAYMENT GATEWAY REQUEST case EnumType.PaymentGateWayType.RAZORPAY: ViewBag.PGType = EnumType.PaymentGateWayType.RAZORPAY.ToString(); resultData = _unit.IOrder.GetOrderDetails(orderId).UserObject; if (resultData.IsBookingOn == false) { var redirectUrl = _appSettings.ReturnUrl + "?Status=" + "BookingClosed"; Response.Redirect(redirectUrl); } if (resultData != null) { var options = new Dictionary <string, object>(); var hashData = new Hashtable(); var htNotes = new Hashtable(); htNotes.Add("amount", resultData.Price); options.Add("notes", htNotes); //order detail options.Add("amount", (resultData.Price * 100)); options.Add("receipt", resultData.InvoiceNo); options.Add("currency", _appSettings.TransactionCurrency); options.Add("payment_capture", "1"); //Razor pay client RazorpayClient client = new RazorpayClient(_appSettings.RazorpayKey, _appSettings.RazorpaySecret); Order order = client.Order.Create(options); //hash data hashData.Add("data-key", _appSettings.RazorpayKey); hashData.Add("data-amount", (resultData.Price * 100)); hashData.Add("data-name", _appSettings.Company); hashData.Add("data-description", _appSettings.RazorPayDescription); hashData.Add("data-order_id", order["id"].ToString()); hashData.Add("data-image", _appSettings.RazorPayLogo); hashData.Add("data-prefill.name", resultData.CustomerName); hashData.Add("data-prefill.email", resultData.EmailId); hashData.Add("data-prefill.contact", resultData.MobileNo); hashData.Add("data-theme.color", _appSettings.RazorPayColor); //serialized object var orderSerialized = JsonConvert.SerializeObject(order); var orderResponse = JsonConvert.DeserializeObject <RazorpayGateWayOrderResponseViewModel>(orderSerialized); model = new PaymetIfoRequestViewModel { InvoiceNo = orderResponse.Attributes.Receipt, PgRequest = orderSerialized, PgType = EnumType.PaymentGateWayType.RAZORPAY.ToString() }; try { if (!isExist) { var result = _unit.IOrder.SaveCustomerPaymentInfo(model); } } catch (Exception ex) { ErrorTrace.Logger(LogArea.ApplicationTier, ex); } //post form data var hashtable = new Hashtable(hashData); pgRequestData = PostFormData("PaymentResponse", hashtable); } break; #endregion #region PAYTM PAYMENT GATEWAY REQUEST case EnumType.PaymentGateWayType.PAYTM: data = _unit.IOrder.GetOrderDetails(orderId).UserObject; if (data != null) { if (data.IsBookingOn == false) { var redirectUrl = _appSettings.ReturnUrl + "?Status=" + "BookingClosed"; Response.Redirect(redirectUrl); } } // var data = _unit.Order.GetRezorPaymenOrdertDetails(orderId).UserObject; if (data != null) { if (data.IsBookingOn == false) { var redirectUrl = _appSettings.ReturnUrl + "?Status=" + "BookingClosed"; Response.Redirect(redirectUrl); } isExist = _unit.IOrder.IsOrderRefExist(data.InvoiceNo, pgType).UserObject; /* initialize a TreeMap object */ Dictionary <String, String> paytmParams = new Dictionary <String, String>(); /* Find your MID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ paytmParams.Add("MID", _appSettings.PAYTM_MID); /* Find your WEBSITE in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ paytmParams.Add("WEBSITE", _appSettings.PAYTM_WEBSITE); /* Find your INDUSTRY_TYPE_ID in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys */ paytmParams.Add("INDUSTRY_TYPE_ID", _appSettings.PAYTM_INDUSTRY_TYPE_ID); /* WEB for website and WAP for Mobile-websites or App */ paytmParams.Add("CHANNEL_ID", _appSettings.PAYTM_CHANNEL_ID); /* Enter your unique order id */ paytmParams.Add("ORDER_ID", data.InvoiceNo); /* unique id that belongs to your customer */ paytmParams.Add("CUST_ID", data.CustomerId); /* customer's mobile number */ paytmParams.Add("MOBILE_NO", data.MobileNo); /* customer's email */ paytmParams.Add("EMAIL", data.EmailId); /* Amount in INR that is payble by customer * this should be numeric with optionally having two decimal points*/ paytmParams.Add("TXN_AMOUNT", data.Price.ToString()); /* on completion of transaction, we will send you the response on this URL */ paytmParams.Add("CALLBACK_URL", _appSettings.ReturnUrl); /* Generate checksum for parameters we have */ string checksum = Paytm.Checksum.CheckSum.GenerateCheckSum(_appSettings.PAYTM_MERCHANT_KEY, paytmParams); try { model = new PaymetIfoRequestViewModel { InvoiceNo = data.InvoiceNo, PgRequest = JsonConvert.SerializeObject(paytmParams, Formatting.Indented), PgType = EnumType.PaymentGateWayType.PAYTM.ToString() }; if (!isExist) { var result = _unit.IOrder.SaveCustomerPaymentInfo(model); } } catch (Exception ex) { ErrorTrace.Logger(LogArea.ApplicationTier, ex); } /* Prepare HTML Form and Submit to Paytm */ string htmlString = ""; htmlString += "<html>"; htmlString += "<head>"; htmlString += "<title>Merchant Checkout Page</title>"; htmlString += "</head>"; htmlString += "<body>"; htmlString += "<center><h1>Please do not refresh this page...</h1></center>"; htmlString += "<form method='post' action='" + (_appSettings.IsLivePayment == "Y" ? _appSettings.PAYTM_LIVE_URL : _appSettings.PAYTM_STAGING_URL) + "' name='paytm_form'>"; foreach (string key in paytmParams.Keys) { htmlString += "<input type='hidden' name='" + key + "' value='" + paytmParams[key] + "'>"; } htmlString += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "'>"; htmlString += "</form>"; htmlString += "<script type='text/javascript'>"; htmlString += "document.paytm_form.submit();"; htmlString += "</script>"; htmlString += "</body>"; htmlString += "</html>"; //request data pgRequestData = htmlString; } break; #endregion } TempData["PaytmType"] = pgType; return(View(model: pgRequestData)); }