Exemplo n.º 1
0
        /// <summary>
        /// Make payment for an order...
        /// </summary>
        /// <param name="storeId"></param>
        /// <param name="myVars"></param>
        /// <param name="userName"></param>
        /// <param name="userPwd"></param>
        /// <param name="dbType"></param>
        /// <param name="uvAddress"></param>
        /// <param name="uvAccount"></param>
        /// <param name="cacheTIme"></param>
        /// <param name="dblCache"></param>
        /// <param name="strd3PortNumber"></param>
        /// <param name="useEncryption"></param>
        /// <param name="d3PortNumber"></param>
        public CheckoutMessageModel DoPayment(string storeId, object myVars, string userName, string userPwd, string dbType,
                             string uvAddress, string uvAccount, string cacheTIme, string dblCache,
                             string strd3PortNumber, string useEncryption, string d3PortNumber)
        {
            var strPickDataReturn = DbAccess.GetStringResult(storeId, Constants.OrderPayment, myVars, userName, userPwd,
                                                             dbType, uvAddress, uvAccount, cacheTIme, dblCache,
                                                             strd3PortNumber, useEncryption, d3PortNumber);

            //Read XML data
            var doc = new XmlDocument();

            doc.LoadXml(strPickDataReturn);

            var checkoutMessageModel = new CheckoutMessageModel();

            var xmlResult = XElement.Parse(strPickDataReturn);

            if (xmlResult.Descendants("ERROR").Any())
            {
                //If not set error message
                //objTaxModel.ErrorMsg = xmlResult.Descendants("ERROR").SingleOrDefault().Value;
            }
            else
            {

                checkoutMessageModel.Line1 = xmlResult.Descendants("LINE1").FirstOrDefault().Value;
                checkoutMessageModel.Line2 = xmlResult.Descendants("LINE2").FirstOrDefault().Value;
                checkoutMessageModel.Line3 = xmlResult.Descendants("LINE3").FirstOrDefault().Value;
                checkoutMessageModel.TrasactionNumber = xmlResult.Descendants("DATA").FirstOrDefault().Value;
                checkoutMessageModel.Emails = xmlResult.Descendants("EMAILS").FirstOrDefault().Value;

            }
            return checkoutMessageModel;
        }
        /// <summary>
        /// Do payment of shopping cart
        /// </summary>
        /// <returns></returns>
        public JsonResult JsonDoPayment()
        {
            var dtPayment = new DataTable();

            var cardtype = Request["CardType"];

            var expdate = Request["ExpiryDate"];

            var cardno = Request["CardNo"];

            var cid = Request["CIDNo"];

            var promocode = Request["PromoCode"];

            var subtotal = Request["SubTotal"];

             subtotal = "$0.1";

            var objUserModel = (UserModel)Session["USERINFO"];

            var confnumber = Convert.ToString(Session["CONFNUMBER"]);

            var checkoutMessageModel = new CheckoutMessageModel();

            switch (cardtype)
            {
                case "CC":
                    {
                        if (!string.IsNullOrEmpty(cardno) && !string.IsNullOrEmpty(cid))
                        {
                            dtPayment = TryPayment(cardno, expdate, cid, subtotal);
                        }
                    }
                    break;
                case "GC":
                case "FA":
                case "CA":
                    dtPayment = TryPayment(cardno, expdate, cid, subtotal);
                    break;
                case "NA":
                    {
                        return Json(new {success = false, errorMsg = "Please select method of Payment."});
                    }
                default:
                    {
                        return Json(new {success = false, errorMsg = "Please select method of Payment."});
                    }
            }

            if (dtPayment !=null &&dtPayment.Rows.Count>0)
            {

                var verified = Convert.ToInt16(dtPayment.Rows[0].ItemArray.GetValue(0).ToString());

                if (verified == 1)
                {
                    //credit card is valid then do payment
                    checkoutMessageModel = ShippingService.DoPayment(StoreNumber, confnumber, objUserModel.UserName, cardno, cid, expdate,
                                              promocode, cardtype, UvUsername, UvPassword, DbType, UvAddress, UvAccount,
                                              CacheTime, CacheTime, Strd3PortNumber, UseEncryption,
                                              Strd3PortNumber);
                }
                else
                {
                    //credit card is no good!
                    var errorcode = dtPayment.Rows[0]["MessageCode"].ToString();

                    switch (errorcode)
                    {
                        case "D101":
                            {
                                // Still do payment...
                              checkoutMessageModel=  ShippingService.DoPayment(StoreNumber, confnumber, objUserModel.UserName, cardno, cid, expdate,
                                             promocode, cardtype, UvUsername, UvPassword, DbType, UvAddress, UvAccount,
                                             CacheTime, CacheTime, Strd3PortNumber, UseEncryption,
                                             Strd3PortNumber);
                            }
                            break;

                        default:
                            {
                                return
                                    Json(new { success = false, errorMsg = dtPayment.Rows[0].ItemArray.GetValue(1).ToString() });
                            }
                    }
                }
            }
            else
            {

              checkoutMessageModel=  ShippingService.DoPayment(StoreNumber, confnumber, objUserModel.UserName, cardno, cid, expdate,
                                             promocode, cardtype, UvUsername, UvPassword, DbType, UvAddress, UvAccount,
                                             CacheTime, CacheTime, Strd3PortNumber, UseEncryption,
                                             Strd3PortNumber);
            }

            Session["ADMINEMAILADDRESSLIST"] = checkoutMessageModel.Emails;
            Session["TMPORDERNUMBER"] = checkoutMessageModel.TrasactionNumber;
            Session["SHIPSELECTED"] = null;

            return Json(new {success = true});
        }