Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sTranId = Request.QueryString["code"];

            if (string.IsNullOrEmpty(sTranId))
            {
                Response.Redirect("/SmartLink/", true);
            }

            CacheInfo oCache = (CacheInfo)CacheProvider.Get(string.Format(KeyCache.KeyUserSmartlink, sTranId));

            if (oCache == null)
            {
                Response.Redirect("/SmartLink/", true);
            }

            SmartlinkQueryInfo oQueryInfo = new SmartlinkQueryInfo()
            {
                CreateDate = DateTime.Now
            };

            try
            {
                string sStatus = SmartLinkHelper.GetQuery(sTranId, ref oQueryInfo);
                if (!string.IsNullOrEmpty(sStatus))
                {
                    String[] arr = sStatus.Split('&');
                    foreach (String item in arr)
                    {
                        String[] temp = item.Split('=');
                        if ("vpc_DRExists".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_DRExists = temp[1];
                        }
                        if ("vpc_FoundMultipleDRs".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_FoundMultipleDRs = temp[1];
                        }
                        if ("vpc_Message".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_Message = temp[1];
                        }
                        if ("vpc_SecureHash".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_SecureHash = temp[1];
                        }
                        if ("vpc_TxnResponseCode".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_TxnResponseCode = temp[1];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                oQueryInfo.vpc_TxnResponseCode = ex.GetHashCode().ToString();
                oQueryInfo.vpc_Message         = ex.Message;
                //throw;
            }
            finally
            {
                CacheProvider.Remove(string.Format(KeyCache.KeyUserSmartlink, sTranId));
                SmartlinkQueryData.instance.Add(oQueryInfo);
                //Session[Config.GetSessionsResultFail] =oQueryInfo.vpc_TxnResponseCode==null?"Giao dịch bị hủy bỏ": SmartLinkHelper.getResponseDescription(oQueryInfo.vpc_TxnResponseCode);
                Session[Config.GetSessionsResultFail] = "Giao dịch không thành công";
                Response.Redirect("/SmartLink/#" + sTranId + "|F", false);
            }
        }
Ejemplo n.º 2
0
        private void SetInfo(HttpContext context)
        {
            string vouchers = context.Request["vouchers"];

            if (string.IsNullOrEmpty(vouchers))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 5, "Hãy nhập gói cước"));
                return;
            }

            var oUser = (CustomerGateInfo)context.Session[Config.GetSessionUser];

            if (oUser == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 6, "Hết phiên làm việc, hãy thực hiện lại"));
                return;
            }

            if (!Utility.isOnlyNumber(vouchers))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 7, "Gói cước không phù hợp"));
                return;
            }

            List <voucher> list     = oUser.vouchers;
            voucher        oVoucher = null;

            foreach (voucher item in list)
            {
                if (vouchers == item.vouchervalue)
                {
                    oVoucher = item;
                    break;
                }
            }

            if (oVoucher == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 8, "Gói cước không phù hợp"));
                return;
            }

            SmartlinkRedirectUrlInfo oRedirectUrlInfo = new SmartlinkRedirectUrlInfo()
            {
                CreateDate = DateTime.Now
            };

            try
            {
                string sUrl = SmartLinkHelper.getRedirectUrl(vouchers, ref oRedirectUrlInfo);

                //save cached
                CacheInfo oCacheInfo = new CacheInfo()
                {
                    Voucher   = oVoucher,
                    sTrans_Id = oRedirectUrlInfo.vpc_MerchTxnRef,
                    User      = oUser
                };

                CacheProvider.AddWithTimeOut(string.Format(KeyCache.KeyUserSmartlink, oRedirectUrlInfo.vpc_MerchTxnRef), oCacheInfo, 720);
                //
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 0, sUrl));
            }
            catch (Exception ex)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", ex.GetHashCode().ToString(), ex.Message));
            }
            finally
            {
                SmartlinkRedirectUrlData.instance.Add(oRedirectUrlInfo);
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sTranId = Request.QueryString["vpc_MerchTxnRef"];

            if (string.IsNullOrEmpty(sTranId))
            {
                Response.Redirect("/SmartLink/", true);
            }

            //Check info Smartlink
            Hashtable hash = new Hashtable();

            foreach (String key in Request.QueryString.AllKeys)
            {
                if (key.StartsWith("vpc_"))
                {
                    hash.Add(key, Request.QueryString[key]);
                }
            }

            bool isEmptysecureSecret;
            bool isValidsecureHash = SmartLinkHelper.checkSum(hash, out isEmptysecureSecret);

            if (isEmptysecureSecret)
            {
                Response.Redirect("/SmartLink/", true);
            }
            if (!isValidsecureHash)
            {
                Response.Redirect("/SmartLink/", true);
            }

            //check info AV
            CacheInfo oCache = (CacheInfo)CacheProvider.Get(string.Format(KeyCache.KeyUserSmartlink, sTranId));

            if (oCache == null)
            {
                Response.Redirect("/SmartLink/", true);
            }

            string sDerection = "";

            SmartlinkQueryInfo oQueryInfo = new SmartlinkQueryInfo()
            {
                CreateDate = DateTime.Now
            };

            try
            {
                string sStatus = SmartLinkHelper.GetQuery(sTranId, ref oQueryInfo);//chư thấy trả về
                if (!string.IsNullOrEmpty(sStatus))
                {
                    String[] arr = sStatus.Split('&');
                    foreach (String item in arr)
                    {
                        String[] temp = item.Split('=');
                        if ("vpc_DRExists".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_DRExists = temp[1];
                        }
                        if ("vpc_FoundMultipleDRs".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_FoundMultipleDRs = temp[1];
                        }
                        if ("vpc_Message".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_Message = temp[1];
                        }
                        if ("vpc_SecureHash".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_SecureHash = temp[1];
                        }
                        if ("vpc_TxnResponseCode".ToUpper().Equals(temp[0].ToUpper()))
                        {
                            oQueryInfo.vpc_TxnResponseCode = temp[1];
                        }
                    }

                    //giao dịch thành công
                    if (oQueryInfo.vpc_TxnResponseCode == "0")
                    {
                        //submit voucher
                        SubmitVoucherInfo oSVInfo = new SubmitVoucherInfo()
                        {
                            GatePayId  = Config.ClientIdSmartLink,
                            UserId     = oCache.User.subnum,
                            Amount     = int.Parse(oCache.Voucher.vouchervalue),
                            CreateDate = DateTime.Now,
                            TransId    = sTranId
                        };
                        try
                        {
                            WSClient wsclient = new WSClient();
                            var      cred     = new credential {
                                clientId = Config.ClientIdSmartLink
                            };
                            var wsResult = wsclient.submitVoucher(cred, oSVInfo.UserId, oSVInfo.Amount.ToString(), oSVInfo.TransId);

                            oSVInfo.returnCode            = wsResult.returnCode;
                            oSVInfo.returnCodeDescription = wsResult.returnCodeDescription;
                            string sResultDate = XMLReader.ReadResultVocher(wsResult.responseData);//dt
                            oSVInfo.responseData = sResultDate;
                            oSVInfo.signature    = wsResult.signature;

                            if (oSVInfo.returnCode == "")
                            {
                                Session[Config.GetSessionsResultDate] = sResultDate;//ss

                                sDerection = "/SmartLink/#" + sTranId + "|T";
                            }
                            else
                            {
                                //Session[Config.GetSessionsResultFail] = wsResult.returnCodeDescription;//ss
                                Session[Config.GetSessionsResultFail] = "Giao dịch không thành công";
                                sDerection = "/SmartLink/#" + sTranId + "|F|Y";
                            }
                        }
                        catch (Exception ex)
                        {
                            //log error
                            Session[Config.GetSessionsResultFail] = ex.Message;
                            oSVInfo.returnCode            = ex.GetHashCode().ToString();
                            oSVInfo.returnCodeDescription = ex.Message;
                            sDerection = "/SmartLink/#" + sTranId + "|F|Y";
                        }
                        finally
                        {
                            SubmitVoucherData.instance.Add(oSVInfo);
                            //Response.Redirect(sDerection);
                        }
                    }
                    else
                    {
                        //Session[Config.GetSessionsResultFail] = SmartLinkHelper.getResponseDescription(oQueryInfo.vpc_TxnResponseCode??"");
                        Session[Config.GetSessionsResultFail] = "Giao dịch không thành công";
                        sDerection = "/SmartLink/#" + sTranId + "|F";
                    }
                }
                else
                {
                    sDerection = "/SmartLink/#" + sTranId + "|F";
                }
            }
            catch (Exception ex)
            {
                oQueryInfo.vpc_TxnResponseCode = ex.GetHashCode().ToString();
                oQueryInfo.vpc_Message         = ex.Message;
                sDerection = "/SmartLink/#" + sTranId + "|F";
            }
            finally
            {
                CacheProvider.Remove(string.Format(KeyCache.KeyUserSmartlink, sTranId));
                SmartlinkQueryData.instance.Add(oQueryInfo);
                if (sDerection != "")
                {
                    Response.Redirect(sDerection);
                }
            }
        }