Ejemplo n.º 1
0
        public ActionResult AfterCheckResponse(PaytmResponse paytmResponse)
        {
            try
            {
                // Get the IntermediarOrderDetail with the id provided
                InterimOrderDeatils interimOrderDetail = _context.InterimOrderDeatils.FirstOrDefault(t => t.UniqueReference.ToLower() == paytmResponse.UniqueReference.ToLower());
                if (interimOrderDetail == null)
                {
                    throw new Exception("No record found.");
                }

                //Get the Care4uPgConfig with the groupEntityId available in the IntermediarOrderDetail fetched.
                // Get configuaration by ApplicationName,ModuleName,GroupEntityID,PaymentGateWay
                Care4UPgConfig pgConfig = _context.Care4uPgConfig.FirstOrDefault(t => t.Module.ToUpper().Equals(interimOrderDetail.PaymentForModule.ToUpper()) &&
                                                                                 t.PaymentGateWayType.ToUpper().Equals("PAYTM") &&
                                                                                 t.IsActive);

                if (pgConfig == null)
                {
                    throw new Exception("Payment for this module has not been enabled.");
                }


                //PaytmResponse paytmResponse = new PaytmResponse();
                String merchantKey = pgConfig.Paytm_MerchantKey;// "jBIWVeuQ0AKxUU%R";

                Dictionary <string, string> parameters = new Dictionary <string, string>();
                string paytmChecksum = "";
                foreach (string key in Request.Form.Keys)
                {
                    parameters.Add(key.Trim(), Request.Form[key].Trim());
                }

                if (parameters.ContainsKey("CHECKSUMHASH"))
                {
                    paytmChecksum = parameters["CHECKSUMHASH"];
                    parameters.Remove("CHECKSUMHASH");
                }

                //paytmResponse.BANKNAME = parameters["BANKNAME"];
                //paytmResponse.BANKTXNID = parameters["BANKTXNID"];
                //paytmResponse.CHECKSUMHASH = paytmChecksum;
                //paytmResponse.CURRENCY = parameters["CURRENCY"];
                //paytmResponse.GATEWAYNAME = parameters["BANKNAME"];
                //paytmResponse.MID = parameters["MID"];
                //paytmResponse.ORDERID = parameters["ORDERID"];
                //paytmResponse.PAYMENTMODE = parameters["PAYMENTMODE"];
                //// PaytmResponse.PROMO_CAMP_ID = parameters["PROMO_CAMP_ID"];
                ////PaytmResponse.PROMO_RESPCODE = parameters["PROMO_RESPCODE"];
                //// PaytmResponse.PROMO_STATUS = parameters["PROMO_STATUS"];
                //paytmResponse.RESPCODE = parameters["RESPCODE"];
                //paytmResponse.RESPMSG = parameters["RESPMSG"];
                //paytmResponse.STATUS = parameters["STATUS"];
                //paytmResponse.TXNAMOUNT = parameters["TXNAMOUNT"];
                //paytmResponse.TXNDATE = parameters["TXNDATE"];
                //paytmResponse.TXNID = parameters["TXNID"];

                //paytmResponse.UniqueReference = interimOrderDetail.UniqueReference;

                //String merchantKey = parameters["MerchantKey"];


                string redirectAction = "";

                if (paytmResponse.STATUS == "TXN_SUCCESS")
                {
                    //Update the IntermediarOrderDetails payment status, response and other records.
                    interimOrderDetail.PaymentStatus   = true;
                    interimOrderDetail.PaymentResponse = "Success";

                    //  Response.Write("Checksum Matched");
                    redirectAction = "PaymentSuccessResponse";
                    //return RedirectToAction("PaymentSuccessResponse", PaytmResponse);
                }
                else if (paytmResponse.STATUS == "TXN_FAILURE")
                {
                    //Update the IntermediarOrderDetails payment status, response and other records.
                    interimOrderDetail.PaymentStatus   = false;
                    interimOrderDetail.PaymentResponse = "Failure";

                    redirectAction = "PaymentFailureResponse";
                    //return RedirectToAction("PaymentFailureResponse", PaytmResponse);
                }
                else
                {
                    //Update the IntermediarOrderDetails payment status, response and other records.
                    interimOrderDetail.PaymentStatus   = false;
                    interimOrderDetail.PaymentResponse = "Pending";

                    redirectAction = "PaymentPendingResponse";
                    //return RedirectToAction("PaymentPendingResponse", PaytmResponse);
                }

                //using (var db = new Care4UContext())
                //{
                //	db.InterimOrderDeatils.Attach(interimOrderDetail);
                //	db.Entry(interimOrderDetail).Property(p => p.PaymentStatus).IsModified = true;
                //	db.SaveChanges();
                //}

                _context.InterimOrderDeatils.Attach(interimOrderDetail);
                _context.Entry(interimOrderDetail).Property(p => p.PaymentStatus).IsModified = true;
                //_context.Entry(interimOrderDetail).Property(p => p.PaymentResponse).IsModified = true;
                _context.SaveChanges();
                var result = PerformPostPaymentJobs(paytmResponse);
                if (paytmResponse.STATUS == "TXN_SUCCESS")
                {
                    if (agentType == "MobileApp")
                    {
                        return(RedirectToAction("PaymentSuccessResponse"));
                    }
                    else if (agentType == "WebSite")
                    {
                        return(View("../Payment/HealthProWebAfterPgResponse", interimOrderDetail));
                    }
                    else
                    {
                        return(RedirectToAction("PaymentSuccessResponse"));
                    }
                }
                else if (paytmResponse.STATUS == "TXN_FAILURE")
                {
                    if (agentType == "MobileApp")
                    {
                        return(RedirectToAction("PaymentFailureResponse"));
                    }
                    else if (agentType == "WebSite")
                    {
                        return(View("../Payment/HealthProWebAfterPgResponse", interimOrderDetail));
                    }
                    else
                    {
                        return(RedirectToAction("PaymentSuccessResponse"));
                    }
                }
                else
                {
                    if (agentType == "MobileApp")
                    {
                        return(RedirectToAction("PaymentPendingResponse"));
                    }
                    else if (agentType == "WebSite")
                    {
                        return(View("../Payment/HealthProWebAfterPgResponse", interimOrderDetail));
                    }
                    else
                    {
                        return(RedirectToAction("PaymentSuccessResponse"));
                    }
                }
                //if (res.Data)
                //	return RedirectToAction(redirectAction, paytmResponse);
                //else
                //	return RedirectToAction("PaymentFailureResponse", paytmResponse);

                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }

            //return View();
        }
Ejemplo n.º 2
0
        public ActionResult PaytmPamentGateway(string interimOrderDeatilsId, string agent = null)
        {
            agentType = agent;
            // Get the IntermediarOrderDetail with the id provided
            InterimOrderDeatils interimOrderDetail = _context.InterimOrderDeatils.FirstOrDefault(t => t.UniqueReference.ToLower() == interimOrderDeatilsId.ToLower());

            if (interimOrderDetail == null)
            {
                throw new Exception("No record found.");
            }

            var response = System.Web.Helpers.Json.Decode(interimOrderDetail.OrderDetails.ToString())[0];
            //Get the Care4uPgConfig with the groupEntityId available in the IntermediarOrderDetail fetched.
            // Get configuaration by ApplicationName,ModuleName,GroupEntityID,PaymentGateWay
            Care4UPgConfig pgConfig = _context.Care4uPgConfig.FirstOrDefault(t => t.Module.ToUpper().Equals(interimOrderDetail.PaymentForModule.ToUpper()) &&
                                                                             t.PaymentGateWayType.ToUpper().Equals("PAYTM") &&
                                                                             t.IsActive);

            if (pgConfig == null)
            {
                throw new Exception("Payment for this module has not been enabled.");
            }

            //Form the PaytmRequest

            Random generator    = new Random();
            String randomNumber = generator.Next(0, 999999).ToString("D6");

            PaytmRequest PaytmRequest = new PaytmRequest();

            PaytmRequest.MerchantKey      = pgConfig.Paytm_MerchantKey;                                                                                                                                                       //"jBIWVeuQ0AKxUU%R";
            PaytmRequest.MID              = pgConfig.Paytm_MID;                                                                                                                                                               //"Kare4U04848812903368";
            PaytmRequest.CHANNEL_ID       = pgConfig.Paytm_CHANNEL_ID;                                                                                                                                                        // "WAP";
            PaytmRequest.INDUSTRY_TYPE_ID = pgConfig.Paytm_INDUSTRY_TYPE_ID;                                                                                                                                                  // "Retail";
            PaytmRequest.WEBSITE          = pgConfig.Paytm_WEBSITE;                                                                                                                                                           // "APPSTAGING";
            PaytmRequest.MOBILE_NO        = response.ContactNo != null ? response.ContactNo : "0123456789";                                                                                                                   // "9439421021";
            PaytmRequest.EMAIL            = !String.IsNullOrEmpty(response.Email) ? response.Email : "*****@*****.**";                                                                                                   // "*****@*****.**";
            PaytmRequest.CUST_ID          = (interimOrderDetail.ConsumerID.ToString() != "" && interimOrderDetail.ConsumerID.ToString() != null) ? "Cust" + interimOrderDetail.ConsumerID.ToString() : "Cust" + randomNumber; // interimOrderDetail.ConsumerID.ToString();
                                                                                                                                                                                                                              // PaytmRequest.CUST_ID = "Cust1023515"; // interimOrderDetail.ConsumerID.ToString();            //This property may change if any problem occurs //"Cust10235123"
            PaytmRequest.ORDER_ID     = randomNumber;                                                                                                                                                                         // interimOrderDetail.InterimOrderDeatilsID.ToString();//This property may change if any problem occurs
            PaytmRequest.TXN_AMOUNT   = Math.Round(interimOrderDetail.AmountToBeCharged, 0).ToString();
            PaytmRequest.CALLBACK_URL = pgConfig.Paytm_CALLBACK_URL + "?interimOrderDeatilsId=" + interimOrderDeatilsId;                                                                                                      // "http://*****:*****@gmail.com";
            ////PaytmRequest.MOBILE_NO = "9439421021";
            ////PaytmRequest.CUST_ID = "Cust10235124";
            ////PaytmRequest.ORDER_ID = randomNumber;
            ////PaytmRequest.TXN_AMOUNT = "10";
            ////PaytmRequest.CALLBACK_URL = "http://localhost:63661/Payment/PaymentResponse1";
            ////PaytmRequest.PaytmURL = "https://securegw-stage.paytm.in/theia/processTransaction";


            Dictionary <string, string> parameters = new Dictionary <string, string>();

            //parameters.Add("REQUEST_TYPE", "DEFAULT");
            //parameters.Add("AUTH_MODE", "3D");
            // parameters.Add("PAYMENT_TYPE_ID", "DC");

            parameters.Add("MID", PaytmRequest.MID);
            parameters.Add("CHANNEL_ID", PaytmRequest.CHANNEL_ID);
            parameters.Add("INDUSTRY_TYPE_ID", PaytmRequest.INDUSTRY_TYPE_ID);
            parameters.Add("WEBSITE", PaytmRequest.WEBSITE);
            parameters.Add("EMAIL", PaytmRequest.EMAIL);
            parameters.Add("MOBILE_NO", PaytmRequest.MOBILE_NO);
            parameters.Add("CUST_ID", PaytmRequest.CUST_ID);
            parameters.Add("ORDER_ID", PaytmRequest.ORDER_ID);
            parameters.Add("TXN_AMOUNT", PaytmRequest.TXN_AMOUNT);
            parameters.Add("CALLBACK_URL", PaytmRequest.CALLBACK_URL); //This parameter is not mandatory. Use this to pass the callback url dynamically.


            //parameters.Add("MerchantKey", PaytmRequest.MerchantKey);
            //parameters.Add("InterimOrderDetailsId", interimOrderDeatilsId.ToString());


            string checksum = CheckSum.generateCheckSum(PaytmRequest.MerchantKey, parameters);

            PaytmRequest.CheckSum = checksum;


            //  string paytmURL = "https://securegw-stage.paytm.in/theia/processTransaction?orderid=" + r;
            // string paytmURL = "https://securegw-stage.paytm.in/theia/processTransaction";
            string outputHTML = "<html>";

            outputHTML += "<head>";
            outputHTML += "<title>Merchant Check Out Page</title>";
            outputHTML += "</head>";
            outputHTML += "<body>";
            outputHTML += "<center><h1>Please do not refresh this page...</h1></center>";
            outputHTML += "<form method='post' action='" + PaytmRequest.PaytmURL + "' name='f1'>";
            outputHTML += "<table border='1'>";
            outputHTML += "<tbody>";
            foreach (string key in parameters.Keys)
            {
                outputHTML += "<input type='hidden' name='" + key + "' value='" + parameters[key] + "'>";
            }
            outputHTML += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "'>";
            outputHTML += "</tbody>";
            outputHTML += "</table>";
            outputHTML += "<script type='text/javascript'>";
            outputHTML += "document.f1.submit();";
            outputHTML += "</script>";
            outputHTML += "</form>";
            outputHTML += "</body>";
            outputHTML += "</html>";
            PaytmRequest.PaymentUrl = outputHTML;
            ViewBag.PaymentUrl      = outputHTML;
            return(View(PaytmRequest));
        }
Ejemplo n.º 3
0
        public ActionResult PaymentResponse(string interimOrderDeatilsId)
        {
            try
            {
                InterimOrderDeatils interimOrderDetail = _context.InterimOrderDeatils.FirstOrDefault(t => t.UniqueReference.ToLower() == interimOrderDeatilsId.ToLower());
                var response = System.Web.Helpers.Json.Decode(interimOrderDetail.OrderDetails.ToString())[0];

                if (interimOrderDetail == null)
                {
                    throw new Exception("No record found.");
                }

                //Get the Care4uPgConfig with the groupEntityId available in the IntermediarOrderDetail fetched.
                // Get configuaration by ApplicationName,ModuleName,GroupEntityID,PaymentGateWay
                Care4UPgConfig pgConfig = _context.Care4uPgConfig.FirstOrDefault(t => t.Module.ToUpper().Equals(interimOrderDetail.PaymentForModule.ToUpper()) &&
                                                                                 t.PaymentGateWayType.ToUpper().Equals("PAYTM") &&
                                                                                 t.IsActive);

                if (pgConfig == null)
                {
                    throw new Exception("Payment for this module has not been enabled.");
                }

                PaytmResponse paytmResponse = new PaytmResponse();
                String        merchantKey   = pgConfig.Paytm_MerchantKey;// "jBIWVeuQ0AKxUU%R";

                Dictionary <string, string> parameters = new Dictionary <string, string>();
                string paytmChecksum = "";
                foreach (string key in Request.Form.Keys)
                {
                    parameters.Add(key.Trim(), Request.Form[key].Trim());
                }

                if (parameters.ContainsKey("CHECKSUMHASH"))
                {
                    paytmChecksum = parameters["CHECKSUMHASH"];
                    parameters.Remove("CHECKSUMHASH");
                }

                paytmResponse.BANKNAME     = parameters["BANKNAME"];
                paytmResponse.BANKTXNID    = parameters["BANKTXNID"];
                paytmResponse.CHECKSUMHASH = paytmChecksum;
                paytmResponse.CURRENCY     = parameters["CURRENCY"];
                paytmResponse.GATEWAYNAME  = parameters["BANKNAME"];
                paytmResponse.MID          = parameters["MID"];
                paytmResponse.ORDERID      = parameters["ORDERID"];
                paytmResponse.PAYMENTMODE  = parameters["PAYMENTMODE"];
                // PaytmResponse.PROMO_CAMP_ID = parameters["PROMO_CAMP_ID"];
                //PaytmResponse.PROMO_RESPCODE = parameters["PROMO_RESPCODE"];
                // PaytmResponse.PROMO_STATUS = parameters["PROMO_STATUS"];
                paytmResponse.RESPCODE  = parameters["RESPCODE"];
                paytmResponse.RESPMSG   = parameters["RESPMSG"];
                paytmResponse.STATUS    = parameters["STATUS"];
                paytmResponse.TXNAMOUNT = parameters["TXNAMOUNT"];
                paytmResponse.TXNDATE   = parameters["TXNDATE"];
                paytmResponse.TXNID     = parameters["TXNID"];
                //string checksum = CheckSum.generateCheckSum(PaytmRequest.MerchantKey, parameters);
                paytmResponse.UniqueReference = interimOrderDeatilsId;


                //String merchantKey = parameters["MerchantKey"];



                Dictionary <string, string> parameters1 = new Dictionary <string, string>();
                //parameters.Add("REQUEST_TYPE", "DEFAULT");
                //parameters.Add("AUTH_MODE", "3D");
                // parameters.Add("PAYMENT_TYPE_ID", "DC");

                parameters1.Add("MID", paytmResponse.MID);

                parameters1.Add("ORDER_ID", paytmResponse.ORDERID);

                string checksum = CheckSum.generateCheckSum(merchantKey, parameters1);

                paytmResponse.CHECKSUMHASH = checksum;
                return(View(paytmResponse));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }