Beispiel #1
0
 public ActionResult MakePayment([FromBody] PaymentModel model)
 {
     try
     {
         string    SuccessUrl = "http://localhost:5001/api/payment/success";
         string    FailureUrl = "http://localhost:5001/api/payment/failed";
         string    txnId      = PU.GetTxnId();
         string    hashString = PU.GetHashString(txnId, model);
         string    hash       = PU.Generatehash512(hashString).ToLower();
         string    action     = GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("url").First().Value + "/_payment";
         Hashtable data       = new Hashtable();
         data.Add("hash", hash);
         data.Add("txnid", txnId);
         data.Add("key", "gtKFFx");
         string AmountForm = Convert.ToDecimal(model.Amount).ToString("g29");
         data.Add("amount", AmountForm);
         data.Add("firstname", model.FirstName);
         data.Add("email", model.Email);
         data.Add("phone", model.PhoneNumber);
         data.Add("productinfo", model.ProductInfo);
         data.Add("surl", SuccessUrl);
         data.Add("furl", FailureUrl);
         data.Add("lastname", model.LastName);
         data.Add("curl", "");
         data.Add("address1", model.AddressLine1);
         data.Add("address2", model.AddressLine2);
         data.Add("city", model.City);
         data.Add("state", model.State);
         data.Add("country", model.Country);
         data.Add("zipcode", model.ZipCode);
         data.Add("udf1", "");
         data.Add("udf2", "");
         data.Add("udf3", "");
         data.Add("udf4", "");
         data.Add("udf5", "");
         data.Add("pg", "");
         data.Add("service_provider", "PayUMoney");
         StringBuilder strForm  = PU.PreparePOSTForm(action, data);
         var           form     = PU.PreparePOSTForm(action, data);
         dynamic       UserInfo = new System.Dynamic.ExpandoObject();
         UserInfo.form = form;
         return(Ok(new ResponseData
         {
             Code = "200",
             Content = UserInfo,
             Data = null
         }));
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("PaymentController", "MakePayment", "MakePayment", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = null
         }));
     }
 }
Beispiel #2
0
 public ActionResult Return([FromBody] FormCollection form, string responce)
 {
     try
     {
         if (form["status"].ToString() == "success")
         {
             string[] hashSequence = ("key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10").Split('|');
             Array.Reverse(hashSequence);
             string hashString = GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("saltkey").First().Value + "|" + form["status"].ToString();
             foreach (string data in hashSequence)
             {
                 hashString += "|";
                 hashString  = hashString + (form[data].ToString() != null ? form[data].ToString() : "");
             }
             //Response.Write(merc_hash_string);
             string  hash     = PU.Generatehash512(hashString).ToLower();
             dynamic UserInfo = new System.Dynamic.ExpandoObject();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Content = null,
                 Data = null
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Payment failed",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("PaymentController", "Return", "Return", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = null
         }));
     }
 }
Beispiel #3
0
        public async Task <ActionResult> PaymentSuccess(IFormCollection paymentResponse)
        {
            if (paymentResponse != null)
            {
                PaymentModel paymentModel = new PaymentModel
                {
                    Email       = paymentResponse["email"],
                    OrderId     = Convert.ToInt16(paymentResponse["udf1"]),
                    UserName    = paymentResponse["udf2"],
                    ProductInfo = paymentResponse["productinfo"],
                    FirstName   = paymentResponse["firstname"],
                    Amount      = paymentResponse["amount"],
                };
                try
                {
                    if (PU.Generatehash512(PU.GetReverseHashString(paymentResponse["txnid"], paymentModel)) == paymentResponse["hash"])
                    {
                        var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString()));

                        var updatePaymentDetails = await MH.UpdatePaymentDetails(paymentModel.OrderId);

                        var removeCartItems    = MH.RemoveCartItems(paymentModel.OrderId, paymentModel.UserName, paymentModel.Email);
                        var sendGift           = GlobalHelper.SendGift(paymentModel.OrderId);
                        var sendProductDetails = EmailHelper.SendEmail_ProductDetails(paymentModel.Email, paymentModel.OrderId);
                        return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectsuccess").First().Value));
                    }
                    else
                    {
                        var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString()));

                        PaymentMethod     paymentDetails = new PaymentMethod();
                        List <StatusCode> statusCodeList = new List <StatusCode>();
                        var orderData = BsonSerializer.Deserialize <OrderInfo>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo").Result);
                        foreach (var detail in orderData.PaymentDetails.Status)
                        {
                            statusCodeList.Add(detail);
                        }
                        statusCodeList.Add(new StatusCode {
                            StatusId = 3, Description = "Payment Failed", Date = DateTime.UtcNow
                        });
                        paymentDetails.Status = statusCodeList;
                        var updatePaymentDetails = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentDetails", paymentDetails));

                        return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectfailure").First().Value));
                    }
                }
                catch (Exception ex)
                {
                    LoggerDataAccess.CreateLog("PaymentController", "PaymentSuccess", ex.Message);
                    var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString()));

                    PaymentMethod     paymentDetails = new PaymentMethod();
                    List <StatusCode> statusCodeList = new List <StatusCode>();
                    var orderData = BsonSerializer.Deserialize <OrderInfo>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo").Result);
                    foreach (var detail in orderData.PaymentDetails.Status)
                    {
                        statusCodeList.Add(detail);
                    }
                    statusCodeList.Add(new StatusCode {
                        StatusId = 3, Description = "Payment Failed", Date = DateTime.UtcNow
                    });
                    paymentDetails.Status = statusCodeList;
                    var updatePaymentDetails = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentDetails", paymentDetails));

                    return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectfailure").First().Value));
                }
            }
            else
            {
                return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectfailure").First().Value));
            }
        }