public static void ParseIPN(int orderID, string transID, string status, int storeID, int portalID, string userName, int customerID, string sessionCode)
 {
     MoneybookersHandler ph = new MoneybookersHandler();
     try
     {
         OrderDetailsCollection ot = new OrderDetailsCollection();
         OrderDetailsInfo odinfo = new OrderDetailsInfo();
         CartManageSQLProvider cms = new CartManageSQLProvider();
         CommonInfo cf = new CommonInfo();
         cf.StoreID = storeID;
         cf.PortalID = portalID;
         cf.AddedBy = userName;
         // UpdateOrderDetails
         AspxOrderDetails objad = new AspxOrderDetails();
         SQLHandler sqlH = new SQLHandler();
         // use split to split array we already have using "=" as delimiter
         // WcfSession ws = new WcfSession();
         odinfo.OrderID = orderID;//ws.GetSessionVariable("OrderID");
         odinfo.ResponseReasonText = status;
         odinfo.TransactionID = transID;
         ot.ObjOrderDetails = odinfo;
         ot.ObjCommonInfo = cf;
         odinfo.OrderStatusID = 8;
         objad.UpdateOrderDetails(ot);
         // UpdateItemQuantity
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void ParseIPN(int orderId, string transId, string status, int storeId, int portalId, string userName, int customerId, string sessionCode)
        {
            var ph = new PayPalHandler();
            try
            {

                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo {StoreID = storeId, PortalID = portalId, AddedBy = userName};
                // UpdateOrderDetails
            
                var sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                // WcfSession ws = new WcfSession();
                odinfo.OrderID = orderId;//ws.GetSessionVariable("OrderID");
                odinfo.ResponseReasonText = status;
                odinfo.TransactionID = transId;
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                odinfo.OrderStatusID = 8;
                AspxOrderController.UpdateOrderDetails(ot);

               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static PayPalHandler ParseIPN(int orderID, string transID, string status, int storeID, int portalID, string userName, int customerID, string sessionCode)
        {
            PayPalHandler ph = new PayPalHandler();

            try
            {
                OrderDetailsCollection ot     = new OrderDetailsCollection();
                OrderDetailsInfo       odinfo = new OrderDetailsInfo();
                CartManageSQLProvider  cms    = new CartManageSQLProvider();
                CommonInfo             cf     = new CommonInfo();
                cf.StoreID  = storeID;
                cf.PortalID = portalID;
                cf.AddedBy  = userName;
                // UpdateOrderDetails
                AspxOrderDetails objad = new AspxOrderDetails();
                SQLHandler       sqlH  = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                // WcfSession ws = new WcfSession();
                odinfo.OrderID            = orderID;//ws.GetSessionVariable("OrderID");
                odinfo.ResponseReasonText = status;
                odinfo.TransactionID      = transID;
                ot.ObjOrderDetails        = odinfo;
                ot.ObjCommonInfo          = cf;
                odinfo.OrderStatusID      = 8;
                objad.UpdateOrderDetails(ot);

                return(ph);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int AddItemstoCart(int itemID, decimal itemPrice, int itemQuantity, bool isItemPage, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                var cartobj            = new CartManageSQLProvider();
                StoreSettingConfig ssc = new StoreSettingConfig();

                if (cartobj.CheckItemCart(itemID, aspxCommonObj.StoreID, aspxCommonObj.PortalID, "0@"))
                {
                    List <KeyValuePair <string, object> > parameter = CommonParmBuilder.GetParamNoCID(aspxCommonObj);
                    parameter.Add(new KeyValuePair <string, object>("ItemID", itemID));
                    parameter.Add(new KeyValuePair <string, object>("Price", itemPrice));
                    parameter.Add(new KeyValuePair <string, object>("Quantity", itemQuantity));
                    OracleHandler sqlH = new OracleHandler();
                    int           i;
                    if (isItemPage)
                    {
                        i = sqlH.ExecuteNonQueryAsGivenType <int>("usp_Aspx_CheckCostVariantForItemDetail", parameter, "IsExist");
                    }
                    else
                    {
                        // i = sqlH.ExecuteNonQueryAsGivenType<int>("usp_Aspx_CheckCostVariantForItem", parameter, "IsExist");
                        i = sqlH.ExecuteNonQueryAsGivenType <int>("usp_Aspx_CheckCostVariantForIt", parameter, "IsExist");
                    }
                    return(i);
                }
                else
                {
                    if (bool.Parse(ssc.GetStoreSettingsByKey(StoreSetting.AllowOutStockPurchase, aspxCommonObj.StoreID, aspxCommonObj.PortalID, aspxCommonObj.CultureName)))
                    {
                        List <KeyValuePair <string, object> > parameter = CommonParmBuilder.GetParamNoCID(aspxCommonObj);
                        parameter.Add(new KeyValuePair <string, object>("ItemID", itemID));
                        parameter.Add(new KeyValuePair <string, object>("Price", itemPrice));
                        parameter.Add(new KeyValuePair <string, object>("Quantity", itemQuantity));
                        parameter.Add(new KeyValuePair <string, object>("isItemPage", isItemPage));
                        OracleHandler sqlH = new OracleHandler();
                        int           i;
                        if (isItemPage)
                        {
                            i = sqlH.ExecuteNonQueryAsGivenType <int>("usp_Aspx_CheckCostVariantForItemDetail", parameter, "IsExist");
                        }
                        else
                        {
                            i = sqlH.ExecuteNonQueryAsGivenType <int>("usp_Aspx_CheckCostVariantForIt", parameter, "IsExist");
                        }
                        //i = sqlH.ExecuteNonQueryAsGivenType<int>("usp_Aspx_CheckCostVariantForItem", parameter, "IsExist");
                        return(i);
                    }
                    else
                    {
                        return(2);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static string Parse(int orderId, string transId, string invoice, string POrderno, int responseCode, int responsereasonCode,
                                   string responsetext, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                OrderDetailsCollection ot     = new OrderDetailsCollection();
                OrderDetailsInfo       odinfo = new OrderDetailsInfo();
                CartManageSQLProvider  cms    = new CartManageSQLProvider();
                CommonInfo             cf     = new CommonInfo();
                cf.StoreID  = aspxCommonObj.StoreID;
                cf.PortalID = aspxCommonObj.PortalID;
                cf.AddedBy  = aspxCommonObj.UserName;
                // UpdateOrderDetails

                odinfo.OrderID             = orderId;
                odinfo.TransactionID       = odinfo.ResponseCode.ToString(transId);
                odinfo.InvoiceNumber       = Convert.ToString(invoice);
                odinfo.PurchaseOrderNumber = Convert.ToString(POrderno);
                odinfo.ResponseCode        = Convert.ToInt32(responseCode);
                odinfo.ResponseReasonCode  = Convert.ToInt32(responsereasonCode);
                odinfo.ResponseReasonText  = Convert.ToString(responsetext);
                ot.ObjOrderDetails         = odinfo;
                ot.ObjCommonInfo           = cf;
                //GIFT CARD PURCHAGE PAYMENT COMPLETED
                odinfo.OrderStatusID = 3;
                AspxOrderController.UpdateOrderDetails(ot);

                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    var orderdata2 = new OrderDetailsCollection();
                    orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    AspxOrderController.UpdateItemQuantity(orderdata2);
                    IssueGiftCard(orderdata2.LstOrderItemsInfo, orderId, true, aspxCommonObj);
                }
                HttpContext.Current.Session.Remove("OrderID");
                cms.ClearCartAfterPayment(aspxCommonObj);
                return("This transaction has been approved");
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static string Parse(string transId, string invoice, string POrderno, int responseCode, int responsereasonCode, string responsetext, int storeID, int portalID, string userName, int customerID, string sessionCode)
        {
            try
            {
                OrderDetailsCollection ot = new OrderDetailsCollection();
                OrderDetailsInfo odinfo = new OrderDetailsInfo();
                CartManageSQLProvider cms = new CartManageSQLProvider();
                CommonInfo cf = new CommonInfo();
                cf.StoreID = storeID;
                cf.PortalID = portalID;
                cf.AddedBy = userName;
                // UpdateOrderDetails
                AspxOrderDetails objad = new AspxOrderDetails();
                SQLHandler sqlH = new SQLHandler();
                WcfSession ws = new WcfSession();
                odinfo.OrderID = ws.GetSessionVariable("OrderID");
                odinfo.TransactionID = odinfo.ResponseCode.ToString(transId);
                odinfo.InvoiceNumber = Convert.ToString(invoice);
                odinfo.PurchaseOrderNumber = Convert.ToString(POrderno);
                odinfo.ResponseCode = Convert.ToInt32(responseCode);
                odinfo.ResponseReasonCode = Convert.ToInt32(responsereasonCode);
                odinfo.ResponseReasonText = Convert.ToString(responsetext);
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                odinfo.OrderStatusID = 8;
                objad.UpdateOrderDetails(ot);
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                    orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    objad.UpdateItemQuantity(orderdata2);
                }
                ws.ClearSessionVariable("OrderID");
                cms.ClearCartAfterPayment(customerID, sessionCode, storeID, portalID);
                return "This transaction has been approved";
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
Beispiel #7
0
 public static string Parse(string transId, string invoice, string POrderno, int responseCode, int responsereasonCode, string responsetext, int storeID, int portalID, string userName, int customerID, string sessionCode)
 {
     try
     {
         OrderDetailsCollection ot     = new OrderDetailsCollection();
         OrderDetailsInfo       odinfo = new OrderDetailsInfo();
         CartManageSQLProvider  cms    = new CartManageSQLProvider();
         CommonInfo             cf     = new CommonInfo();
         cf.StoreID  = storeID;
         cf.PortalID = portalID;
         cf.AddedBy  = userName;
         // UpdateOrderDetails
         AspxOrderDetails objad = new AspxOrderDetails();
         SQLHandler       sqlH  = new SQLHandler();
         WcfSession       ws    = new WcfSession();
         odinfo.OrderID             = ws.GetSessionVariable("OrderID");
         odinfo.TransactionID       = odinfo.ResponseCode.ToString(transId);
         odinfo.InvoiceNumber       = Convert.ToString(invoice);
         odinfo.PurchaseOrderNumber = Convert.ToString(POrderno);
         odinfo.ResponseCode        = Convert.ToInt32(responseCode);
         odinfo.ResponseReasonCode  = Convert.ToInt32(responsereasonCode);
         odinfo.ResponseReasonText  = Convert.ToString(responsetext);
         ot.ObjOrderDetails         = odinfo;
         ot.ObjCommonInfo           = cf;
         odinfo.OrderStatusID       = 8;
         objad.UpdateOrderDetails(ot);
         if (HttpContext.Current.Session["OrderCollection"] != null)
         {
             OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
             orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
             objad.UpdateItemQuantity(orderdata2);
         }
         ws.ClearSessionVariable("OrderID");
         cms.ClearCartAfterPayment(customerID, sessionCode, storeID, portalID);
         return("This transaction has been approved");
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static string ParseForMobile(string transId, OrderInfo orderInfo, string POrderno, int responseCode, int responsereasonCode, string responsetext)
        {
            try
            {
                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo
                             {StoreID = orderInfo.StoreId, PortalID = orderInfo.PortalId, AddedBy = orderInfo.AddedBy};
                // UpdateOrderDetails
              
                odinfo.OrderID = orderInfo.OrderId;
                odinfo.TransactionID = odinfo.ResponseCode.ToString(transId);
                odinfo.InvoiceNumber = orderInfo.InvoiceNumber;
                odinfo.PurchaseOrderNumber = Convert.ToString(POrderno);
                odinfo.ResponseCode = Convert.ToInt32(responseCode);
                odinfo.ResponseReasonCode = Convert.ToInt32(responsereasonCode);
                odinfo.ResponseReasonText = Convert.ToString(responsetext);
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                odinfo.OrderStatusID = 8;
                AspxOrderController.UpdateOrderDetails(ot);
                AspxCommonInfo aspxCommonObj = new AspxCommonInfo();
                aspxCommonObj.CustomerID = orderInfo.CustomerId;
                aspxCommonObj.SessionCode = orderInfo.SessionCode;
                aspxCommonObj.StoreID = orderInfo.StoreId;
                aspxCommonObj.PortalID = orderInfo.PortalId;
                cms.ClearCartAfterPayment(aspxCommonObj);
                return "This transaction has been approved";
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static string Parse(string transId, string invoice, string POrderno, int responseCode, int responsereasonCode, string responsetext, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo {StoreID = aspxCommonObj.StoreID, PortalID = aspxCommonObj.PortalID, AddedBy = aspxCommonObj.UserName};
                // UpdateOrderDetails
              
                odinfo.OrderID =int.Parse(HttpContext.Current.Session["OrderID"].ToString());
                odinfo.TransactionID = odinfo.ResponseCode.ToString(transId);
                odinfo.InvoiceNumber = Convert.ToString(invoice);
                odinfo.PurchaseOrderNumber = Convert.ToString(POrderno);
                odinfo.ResponseCode = Convert.ToInt32(responseCode);
                odinfo.ResponseReasonCode = Convert.ToInt32(responsereasonCode);
                odinfo.ResponseReasonText = Convert.ToString(responsetext);
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                odinfo.OrderStatusID = 8;
                AspxOrderController.UpdateOrderDetails(ot);
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    var orderdata2 =  (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    AspxOrderController.UpdateItemQuantity(orderdata2);
                }
                HttpContext.Current.Session.Remove("OrderID");
                cms.ClearCartAfterPayment(aspxCommonObj);
                return "This transaction has been approved";
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public static PayPalHandler Parse(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode)
        {
            String sKey, sValue;
            PayPalHandler ph = new PayPalHandler();
            string transID = string.Empty;

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */
                OrderDetailsCollection ot = new OrderDetailsCollection();
                OrderDetailsInfo odinfo = new OrderDetailsInfo();
                CartManageSQLProvider cms = new CartManageSQLProvider();
                CommonInfo cf = new CommonInfo();
                cf.StoreID = storeID;
                cf.PortalID = portalID;
                cf.AddedBy = userName;
                // UpdateOrderDetails
                AspxOrderDetails objad = new AspxOrderDetails();
                SQLHandler sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                WcfSession ws = new WcfSession();
                odinfo.OrderID = ws.GetSessionVariable("OrderID");
                int i;
                for (i = 1; i < StringArray.Length - 1; i++)
                {
                    String[] StringArray1 = StringArray[i].Split('=');

                    sKey = StringArray1[0];
                    sValue = HttpUtility.UrlDecode(StringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                        case "payment_status":
                            odinfo.ResponseReasonText = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            // ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "payer_email":
                            // ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            // ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            odinfo.TransactionID = Convert.ToString(sValue);
                            transID = Convert.ToString(sValue);
                            break;

                    }
                }
                // odinfo.InvoiceNumber = DateTime.Now.ToString("yyyyMMddhhmmss");
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                odinfo.OrderStatusID = 8;
                objad.UpdateOrderDetails(ot);
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                    orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    objad.UpdateItemQuantity(orderdata2);
                }
                ws.ClearSessionVariable("OrderID");
                cms.ClearCartAfterPayment(customerID, sessionCode, storeID, portalID);

                //invoice  transID
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    //StringBuilder emailbody = new StringBuilder();
                    //emailbody.Append("<div style=\"width:600px;min-height:auto;background-color:#f2f2f2;color:#707070;font:13px/24px Verdana,Geneva,sans-serif;\"><div style=\"color:#49B8F4;  font-size:20px;margin:auto 0; font-family:Verdana,Geneva,sans-serif;\"> <label>Thank you for Order </label></div>");
                    //OrderDetailsCollection orderdata = new OrderDetailsCollection();
                    //orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    //emailbody.Append("<p> <strong>Dear </strong> " + orderdata.ObjBillingAddressInfo.FirstName.ToString() + "</p>");
                    ////if customer is registered
                    // if (orderdata.ObjCommonInfo.AddedBy.ToString().ToLower() == "anonymoususer" && orderdata.ObjOrderDetails.CustomerID ==0)
                    //{
                    //    emailbody.Append("<div>  You have ordered items from <strong>AspxCommerce</strong>. <br /> Thanks for using <strong>AspxCommerce</strong>. You can now ship any items. To see all the transaction details, log in to your <b>AspxCommerce</b> <a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Register.aspx?session="+sessionCode +"" + ">account</a>.<br /> It may take a few moments for this transaction to appear in your account.<br /></div> ");
                    //}
                    //else
                    //{//if customer is guest..send session code 
                    //    emailbody.Append("<div> You have ordered items from <strong>AspxCommerce</strong>. <br /> Thanks for using <strong>AspxCommerce</strong>. You can now ship any items. To see all the transaction details, Please Resister and log in to your <b>AspxCommerce</b> <a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Login.aspx" + ">account</a>.<br /> It may take a few moments for this transaction to appear in your account.<br /></div>");
                    //}
                    //emailbody.Append("<div> <strong>Your Order Details </strong><br />  Transaction ID: <strong >" + odinfo.TransactionID.ToString() + "</strong><br />Invoice No: <strong>" + odinfo.InvoiceNumber.ToString() + "</strong><br />Paymenet System Used: <strong>" + orderdata.ObjPaymentInfo.PaymentMethodName + "</strong><br /> </div> ");
                    //emailbody.Append("<div> If you having Issuses with transaction or any further inquiry then you can mail [email protected].</div><div> Please do not reply to this email. This mail is automatic generated after you have ordered .</div><div>Thank You, <br /><a href=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "\"><img src=\"" + "http://www.aspxcommerce.com" + "/Templates/AspxCommerce/images/aspxcommerce.png\" alt=\"AspxCommerce Team\"/></a></div></div>");
                    //string body = emailbody.ToString();
                    //SageFrameConfig pagebase = new SageFrameConfig();
                    //string emailSuperAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SuperUserEmail);//"*****@*****.**";
                    //string emailSiteAdmin =  pagebase.GetSettingsByKey(SageFrameSettingKeys.SiteAdminEmailAddress);
                    //MailHelper.SendMailNoAttachment("*****@*****.**", orderdata.ObjBillingAddressInfo.EmailAddress.ToString(), "Your Order Details", body, emailSuperAdmin, emailSiteAdmin);
                    //ws.ClearSessionVariable("OrderCollection");
                    string sendEmailFrom = StoreSetting.GetStoreSettingValueByKey(StoreSetting.SendEcommerceEmailsFrom, storeID, portalID, "en-US");
                    string sendOrderNotice = StoreSetting.GetStoreSettingValueByKey(StoreSetting.SendOrderNotification, storeID, portalID, "en-US");
                    if (sendOrderNotice.ToLower() == "true")
                    {
                        StringBuilder emailbody = new StringBuilder();
                        OrderDetailsCollection orderdata = new OrderDetailsCollection();
                        orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        emailbody.Append("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"5\" bgcolor=\"#e0e0e0\" style=\"font: 12px Arial,Helvetica,sans-serif;\"> <tr><td align=\"center\" valign=\"top\"><table width=\"680\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> <td><img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" /></td></tr><tr><td><table width=\"680\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> <td width=\"300\">");
                        emailbody.Append("<a href=\"http://www.aspxcommerce.com\" target=\"_blank\" style=\"outline: none; border: none;\"> <img src=\"http://www.aspxcommerce.com/Templates/AspxCommerce/images/aspxcommerce.png\" width=\"143\" height=\"62\" alt=\"AspxCommerce\" title=\"AspxCommerce\" /></a></td><td width=\"191\" align=\"left\" valign=\"middle\">");
                        emailbody.Append("&nbsp;</td><td width=\"189\" align=\"right\" valign=\"middle\"><b style=\"padding: 0 20px 0 0; text-shadow: 1px 1px 0 #fff;\">" + DateTime.Now.ToString("dd MMMM yyyy ") + "</b>");
                        emailbody.Append("</td> </tr></table> </td> </tr> <tr>  <td bgcolor=\"#fff\"><div style=\"border:1px solid #c7c7c7; background:#fff; padding:20px\">  <img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" /><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\">  <tr> <td> <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 17px; line-height: 16px;color: #278ee6; margin: 0; padding: 0 0 5px 0; font-weight: bold;\"> ");
                        emailbody.Append(" Dear " + orderdata.ObjBillingAddressInfo.FirstName.ToString() + "</p> <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; color: #393939; margin: 0; padding: 0 0 10px 0; font-weight: bold;\">  Thank you for Order</p>");
                        emailbody.Append("<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; color: #393939; margin: 0; padding: 8px 0 15px 0; font-weight: normal;\">You have ordered items from <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>.<br />");
                        emailbody.Append("Thanks for using <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>. You can now ship any items. To see all the transaction details,");
                        // emailbody.Append("  Please Register and log in to your <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>");
                        string account = "";
                        if (orderdata.ObjCommonInfo.AddedBy.ToString().ToLower() == "anonymoususer" && orderdata.ObjOrderDetails.CustomerID == 0)
                        {   // future login process for annoymoususr 
                            emailbody.Append("Please Register and log in to your <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>");

                            account = "<a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/User-Registration.aspx" + ">account</a>";
                        }
                        else
                        {
                            emailbody.Append("  Please log in to your <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>");

                            account = "<a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Login.aspx" + ">account</a>";
                        }


                        emailbody.Append(" " + account + ".<br />  It may take a few moments for this transaction to appear in your account</p>  </td></tr>  </table><div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 10px\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><h3 style=\"font-size: 15px; font-family: Arial, Helvetica, sans-serif; line-height: 20px; font-weight: bold; margin: 0; text-transform: capitalize; color: #000; text-shadow: 1px 1px 0 #fff;\">  Your Order Details</h3></td></tr><tr><td><img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" /></td>");
                        emailbody.Append(" </tr><tr><td bgcolor=\"#fff\"><div style=\"border: 1px solid #c7c7c7; background: #fff; padding: 10px\">");
                        emailbody.Append("<div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 10px\">");
                        emailbody.Append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append("<tr>  <td height=\"25\" style=\"border-bottom: 1px solid #fff;\">");
                        emailbody.Append("<h3 style=\"font-size: 15px; font-family: Arial, Helvetica, sans-serif; line-height: 20px;");
                        emailbody.Append("font-weight: bold; margin: 0; text-transform: capitalize; color: #000; text-shadow: 1px 1px 0 #fff;\">Order Information</h3>");
                        emailbody.Append("</td></tr><tr> <td> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append(" <tr><td width=\"120\" height=\"20\"><span style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;\">");
                        emailbody.Append(" Merchant:</span> </td> <td>");
                        //  merchant Name
                        emailbody.Append("Aspx Commerce");
                        emailbody.Append(" </td> <td width=\"150\" style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px;");
                        emailbody.Append(" font-weight: bold; border-left: 1px solid #fff; padding-left: 20px;\"> Customer Id:  <td>");
                        // customer ID
                        emailbody.Append("" + customerID.ToString() + "");
                        emailbody.Append(" </td> </tr>  <tr>  <td height=\"20\"> <span style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;\">");
                        emailbody.Append(" Description:</span>  </td> <td> Order Remarks</td> <td style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;");
                        emailbody.Append(" border-left: 1px solid #fff; padding-left: 20px;\"> Phone No: </td> <td>");
                        // customer Phone No
                        emailbody.Append("" + orderdata.ObjBillingAddressInfo.Phone.ToString() + "");
                        emailbody.Append("  </td> </tr> <td height=\"20\"><span style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;\">");
                        emailbody.Append(" Invoice Number:</span> </td><td>");
                        //   invoice no 
                        emailbody.Append("" + orderdata.ObjOrderDetails.InvoiceNumber.ToString() + "");
                        // emailbody.Append("" + invoice + "");                        
                        emailbody.Append(" </td> <td style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;  border-left: 1px solid #fff; padding-left: 20px;\">");
                        emailbody.Append("  &nbsp;</td><td> &nbsp;</td></tr></table>  </td> </tr> </table> </div>");
                        emailbody.Append(" <div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 0; margin: 10px 0 0 0;\">");
                        emailbody.Append(" <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append(" <tr> <td width=\"300\" style=\"background: #e0e0e0;\"> <h2 style=\"margin: 0; padding: 0; font-weight: bold; font-family: Arial, Helvetica, sans-serif;");
                        emailbody.Append("  font-size: 15px; padding: 3px 0 3px 10px; text-shadow: 1px 1px 0 #fff;\">");
                        emailbody.Append("  Billing Information</h2>  </td><td style=\"background: #e0e0e0; border-left: 1px solid #fff;\">");
                        emailbody.Append("   <h2 style=\"margin: 0; padding: 0; font-weight: bold; font-family: Arial, Helvetica, sans-serif;");
                        emailbody.Append("  font-size: 15px; padding: 3px 0 3px 10px; text-shadow: 1px 1px 0 #fff;\">");
                        emailbody.Append(" Shipping Information</h2> </td></tr><tr><td valign=\"top\"> <p style=\"margin: 0; padding: 10px; font-family: Arial, Helvetica, sans-serif; font-weight: normal;");
                        emailbody.Append("  line-height: 18px; font-size: 12px;\">");
                        //Milson Munakami<br />
                        //                                                               Bd<br />
                        //                                                               sda<br />
                        //                                                               Dsad, Alberta 3232<br />
                        //                                                               Afghanistan<br />
                        //                                                               [email protected]<br />
                        //                                                               +000 000 0000<br />
                        //                                                               Fax: 2222222</p>
                        //                                                       </td>

                        string billing = orderdata.ObjBillingAddressInfo.FirstName.ToString() + " " +
                          orderdata.ObjBillingAddressInfo.LastName.ToString() + "<br />";

                        if (orderdata.ObjBillingAddressInfo.CompanyName != null)
                        {
                            billing += orderdata.ObjBillingAddressInfo.CompanyName.ToString() + "<br />";
                        }

                        billing += orderdata.ObjBillingAddressInfo.City.ToString() + ", " + orderdata.ObjBillingAddressInfo.Address.ToString() + "<br />" +
                        orderdata.ObjBillingAddressInfo.Country.ToString() + "<br />" +
                        orderdata.ObjBillingAddressInfo.EmailAddress.ToString() + "<br />" +
                        orderdata.ObjBillingAddressInfo.Phone.ToString() + "<br />" + "<p>";

                        emailbody.Append("" + billing + "");
                        emailbody.Append("</td><td style=\"border-left: 1px solid #fff;\" valign=\"top\"> <p style=\"margin: 0; padding: 10px; font-family: Arial, Helvetica, sans-serif; font-weight: normal;");
                        emailbody.Append("line-height: 18px; font-size: 12px;\">");
                        //Milson Munakami<br />
                        //                                                              Bd<br />
                        //                                                              sda<br />
                        //                                                              Dsad, Alberta 3232<br />
                        //                                                              Afghanistan<br />
                        //                                                              [email protected]<br />
                        //                                                              +000 000 0000<br />
                        //                                                              Fax: 2222222</p>

                        if (!orderdata.ObjOrderDetails.IsDownloadable)
                        {
                            if (orderdata.ObjOrderDetails.IsMultipleCheckOut == false)
                            {
                                string shipping = orderdata.ObjShippingAddressInfo.FirstName.ToString() + " " +
                                    orderdata.ObjShippingAddressInfo.LastName.ToString() + "<br />";
                                if (orderdata.ObjShippingAddressInfo.CompanyName != null)
                                {
                                    shipping += orderdata.ObjShippingAddressInfo.CompanyName.ToString() + "<br />";
                                }

                                shipping += orderdata.ObjShippingAddressInfo.City.ToString() + ", " + orderdata.ObjShippingAddressInfo.Address.ToString() + "<br />" +
                                      orderdata.ObjShippingAddressInfo.Country.ToString() + "<br />" +
                                      orderdata.ObjShippingAddressInfo.EmailAddress.ToString() + "<br />" +
                                      orderdata.ObjShippingAddressInfo.Phone.ToString() + "<br />" + "<p>";
                                emailbody.Append("" + shipping + "");
                            }
                            else
                            {
                                emailbody.Append("Multiple addresses<br />Plese log in to view.");
                            }

                        }
                        emailbody.Append("</td> </tr> </table></div><div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 0; margin: 10px 0 0 0;\">");
                        emailbody.Append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append("<tr><td style=\"background: #e0e0e0;\" colspan=\"2\"><h2 style=\"margin: 0; padding: 0; font-weight: bold; font-family: Arial, Helvetica, sans-serif;");
                        emailbody.Append("font-size: 15px; padding: 3px 0 3px 10px; text-shadow: 1px 1px 0 #fff;\">");
                        // card type Visa
                        emailbody.Append("" + orderdata.ObjPaymentInfo.PaymentMethodName.ToString() + "");
                        // emailbody.Append("" + orderdata.ObjPaymentInfo.CardType.ToString() + "");
                        emailbody.Append("</h2> </td></tr><tr><td style=\"padding: 5px 10px;\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append("<tr><td width=\"100\" height=\"20\" style=\"width: 200\">  <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;");
                        emailbody.Append(" margin: 0; padding: 0;\"> Date/Time:</p></td><td>");
                        //    order date
                        emailbody.Append("" + DateTime.Now.ToString("dddd, dd MMMM yyyy") + "");
                        emailbody.Append("</td></tr><tr><td height=\"20\"><p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;");
                        emailbody.Append(" margin: 0; padding: 0;\">Transaction Id:</p> </td>  <td>");
                        //     transaction ID
                        emailbody.Append("" + transID + "");
                        //emailbody.Append("" + transID + "");
                        emailbody.Append("</td> </tr></table> </td> </tr> </table></div></div>  </td> </tr>  </table>  </div>");
                        emailbody.Append(" <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #000;\">");
                        emailbody.Append(" if you having Issues with transaction or any further inquiry then you can mail <a");
                        emailbody.Append("href=\"mailto:[email protected]\" style=\"color: #278ee6;\">[email protected]</a></p>");
                        emailbody.Append("<p style=\"margin: 0; padding: 5px 0 0 0; font: bold 11px Arial, Helvetica, sans-serif; color: #666;\">");
                        emailbody.Append("Please do not reply to this email. This mail is automatic generated after you have ordered.</a><br />");
                        emailbody.Append("<br /> Thank You,<br />  <span style=\"font-weight: normal; font-size: 12px; font-family: Arial, Helvetica, sans-serif;\">");
                        emailbody.Append("AXPXCommerce Team </span> </p> </div> </td>  </tr>");
                        emailbody.Append("  <tr> <td>   <img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"20\" alt=\" \" /> </td>");
                        emailbody.Append("</tr> <tr> <td align=\"center\" valign=\"top\"> <p style=\"font-size: 11px; color: #4d4d4d\">");
                        emailbody.Append("  © " + DateTime.Now.Year.ToString() + " AspxCommerce. All Rights Reserved.</p></td>  </tr> <tr>");
                        emailbody.Append("  <td align=\"center\" valign=\"top\"> <img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" />");
                        emailbody.Append("   </td>  </tr> </table></div>   </td> </tr> </table>");
                        string body = emailbody.ToString();
                        SageFrameConfig pagebase = new SageFrameConfig();
                        string emailSuperAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SuperUserEmail);//"*****@*****.**";
                        string emailSiteAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SiteAdminEmailAddress);
                        MailHelper.SendMailNoAttachment(sendEmailFrom, orderdata.ObjBillingAddressInfo.EmailAddress.ToString(), "Your Order Details", body, emailSuperAdmin, emailSiteAdmin);
                    }
                    ws.ClearSessionVariable("OrderCollection");
                }

                return ph;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static PayPalHandler Parse(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode)
        {
            String        sKey, sValue;
            PayPalHandler ph      = new PayPalHandler();
            string        transID = string.Empty;

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:

                /*
                 * loop is set to start at 1 rather than 0 because first
                 * string in array will be single word SUCCESS or FAIL
                 * Only used to verify post data
                 */
                OrderDetailsCollection ot     = new OrderDetailsCollection();
                OrderDetailsInfo       odinfo = new OrderDetailsInfo();
                CartManageSQLProvider  cms    = new CartManageSQLProvider();
                CommonInfo             cf     = new CommonInfo();
                cf.StoreID  = storeID;
                cf.PortalID = portalID;
                cf.AddedBy  = userName;
                // UpdateOrderDetails
                AspxOrderDetails objad = new AspxOrderDetails();
                SQLHandler       sqlH  = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                WcfSession ws = new WcfSession();
                odinfo.OrderID = ws.GetSessionVariable("OrderID");
                int i;
                for (i = 1; i < StringArray.Length - 1; i++)
                {
                    String[] StringArray1 = StringArray[i].Split('=');

                    sKey   = StringArray1[0];
                    sValue = HttpUtility.UrlDecode(StringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                    case "payment_status":
                        odinfo.ResponseReasonText = Convert.ToString(sValue);
                        break;

                    case "mc_fee":
                        // ph.PaymentFee = Convert.ToDouble(sValue);
                        break;

                    case "payer_email":
                        // ph.PayerEmail = Convert.ToString(sValue);
                        break;

                    case "Tx Token":
                        // ph.TxToken = Convert.ToString(sValue);
                        break;

                    case "txn_id":
                        odinfo.TransactionID = Convert.ToString(sValue);
                        transID = Convert.ToString(sValue);
                        break;
                    }
                }
                // odinfo.InvoiceNumber = DateTime.Now.ToString("yyyyMMddhhmmss");
                ot.ObjOrderDetails   = odinfo;
                ot.ObjCommonInfo     = cf;
                odinfo.OrderStatusID = 8;
                objad.UpdateOrderDetails(ot);
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                    orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    objad.UpdateItemQuantity(orderdata2);
                }
                ws.ClearSessionVariable("OrderID");
                cms.ClearCartAfterPayment(customerID, sessionCode, storeID, portalID);

                //invoice  transID
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    //StringBuilder emailbody = new StringBuilder();
                    //emailbody.Append("<div style=\"width:600px;min-height:auto;background-color:#f2f2f2;color:#707070;font:13px/24px Verdana,Geneva,sans-serif;\"><div style=\"color:#49B8F4;  font-size:20px;margin:auto 0; font-family:Verdana,Geneva,sans-serif;\"> <label>Thank you for Order </label></div>");
                    //OrderDetailsCollection orderdata = new OrderDetailsCollection();
                    //orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    //emailbody.Append("<p> <strong>Dear </strong> " + orderdata.ObjBillingAddressInfo.FirstName.ToString() + "</p>");
                    ////if customer is registered
                    // if (orderdata.ObjCommonInfo.AddedBy.ToString().ToLower() == "anonymoususer" && orderdata.ObjOrderDetails.CustomerID ==0)
                    //{
                    //    emailbody.Append("<div>  You have ordered items from <strong>AspxCommerce</strong>. <br /> Thanks for using <strong>AspxCommerce</strong>. You can now ship any items. To see all the transaction details, log in to your <b>AspxCommerce</b> <a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Register.aspx?session="+sessionCode +"" + ">account</a>.<br /> It may take a few moments for this transaction to appear in your account.<br /></div> ");
                    //}
                    //else
                    //{//if customer is guest..send session code
                    //    emailbody.Append("<div> You have ordered items from <strong>AspxCommerce</strong>. <br /> Thanks for using <strong>AspxCommerce</strong>. You can now ship any items. To see all the transaction details, Please Resister and log in to your <b>AspxCommerce</b> <a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Login.aspx" + ">account</a>.<br /> It may take a few moments for this transaction to appear in your account.<br /></div>");
                    //}
                    //emailbody.Append("<div> <strong>Your Order Details </strong><br />  Transaction ID: <strong >" + odinfo.TransactionID.ToString() + "</strong><br />Invoice No: <strong>" + odinfo.InvoiceNumber.ToString() + "</strong><br />Paymenet System Used: <strong>" + orderdata.ObjPaymentInfo.PaymentMethodName + "</strong><br /> </div> ");
                    //emailbody.Append("<div> If you having Issuses with transaction or any further inquiry then you can mail [email protected].</div><div> Please do not reply to this email. This mail is automatic generated after you have ordered .</div><div>Thank You, <br /><a href=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "\"><img src=\"" + "http://www.aspxcommerce.com" + "/Templates/AspxCommerce/images/aspxcommerce.png\" alt=\"AspxCommerce Team\"/></a></div></div>");
                    //string body = emailbody.ToString();
                    //SageFrameConfig pagebase = new SageFrameConfig();
                    //string emailSuperAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SuperUserEmail);//"*****@*****.**";
                    //string emailSiteAdmin =  pagebase.GetSettingsByKey(SageFrameSettingKeys.SiteAdminEmailAddress);
                    //MailHelper.SendMailNoAttachment("*****@*****.**", orderdata.ObjBillingAddressInfo.EmailAddress.ToString(), "Your Order Details", body, emailSuperAdmin, emailSiteAdmin);
                    //ws.ClearSessionVariable("OrderCollection");
                    string sendEmailFrom   = StoreSetting.GetStoreSettingValueByKey(StoreSetting.SendEcommerceEmailsFrom, storeID, portalID, "en-US");
                    string sendOrderNotice = StoreSetting.GetStoreSettingValueByKey(StoreSetting.SendOrderNotification, storeID, portalID, "en-US");
                    if (sendOrderNotice.ToLower() == "true")
                    {
                        StringBuilder          emailbody = new StringBuilder();
                        OrderDetailsCollection orderdata = new OrderDetailsCollection();
                        orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        emailbody.Append("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"5\" bgcolor=\"#e0e0e0\" style=\"font: 12px Arial,Helvetica,sans-serif;\"> <tr><td align=\"center\" valign=\"top\"><table width=\"680\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> <td><img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" /></td></tr><tr><td><table width=\"680\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr> <td width=\"300\">");
                        emailbody.Append("<a href=\"http://www.aspxcommerce.com\" target=\"_blank\" style=\"outline: none; border: none;\"> <img src=\"http://www.aspxcommerce.com/Templates/AspxCommerce/images/aspxcommerce.png\" width=\"143\" height=\"62\" alt=\"AspxCommerce\" title=\"AspxCommerce\" /></a></td><td width=\"191\" align=\"left\" valign=\"middle\">");
                        emailbody.Append("&nbsp;</td><td width=\"189\" align=\"right\" valign=\"middle\"><b style=\"padding: 0 20px 0 0; text-shadow: 1px 1px 0 #fff;\">" + DateTime.Now.ToString("dd MMMM yyyy ") + "</b>");
                        emailbody.Append("</td> </tr></table> </td> </tr> <tr>  <td bgcolor=\"#fff\"><div style=\"border:1px solid #c7c7c7; background:#fff; padding:20px\">  <img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" /><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#FFFFFF\">  <tr> <td> <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 17px; line-height: 16px;color: #278ee6; margin: 0; padding: 0 0 5px 0; font-weight: bold;\"> ");
                        emailbody.Append(" Dear " + orderdata.ObjBillingAddressInfo.FirstName.ToString() + "</p> <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; color: #393939; margin: 0; padding: 0 0 10px 0; font-weight: bold;\">  Thank you for Order</p>");
                        emailbody.Append("<p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; color: #393939; margin: 0; padding: 8px 0 15px 0; font-weight: normal;\">You have ordered items from <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>.<br />");
                        emailbody.Append("Thanks for using <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>. You can now ship any items. To see all the transaction details,");
                        // emailbody.Append("  Please Register and log in to your <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>");
                        string account = "";
                        if (orderdata.ObjCommonInfo.AddedBy.ToString().ToLower() == "anonymoususer" && orderdata.ObjOrderDetails.CustomerID == 0)
                        {   // future login process for annoymoususr
                            emailbody.Append("Please Register and log in to your <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>");

                            account = "<a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/User-Registration.aspx" + ">account</a>";
                        }
                        else
                        {
                            emailbody.Append("  Please log in to your <span style=\"font-weight: bold; font-size: 11px;\">AspxCommerce</span>");

                            account = "<a href=" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Login.aspx" + ">account</a>";
                        }


                        emailbody.Append(" " + account + ".<br />  It may take a few moments for this transaction to appear in your account</p>  </td></tr>  </table><div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 10px\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><h3 style=\"font-size: 15px; font-family: Arial, Helvetica, sans-serif; line-height: 20px; font-weight: bold; margin: 0; text-transform: capitalize; color: #000; text-shadow: 1px 1px 0 #fff;\">  Your Order Details</h3></td></tr><tr><td><img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" /></td>");
                        emailbody.Append(" </tr><tr><td bgcolor=\"#fff\"><div style=\"border: 1px solid #c7c7c7; background: #fff; padding: 10px\">");
                        emailbody.Append("<div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 10px\">");
                        emailbody.Append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append("<tr>  <td height=\"25\" style=\"border-bottom: 1px solid #fff;\">");
                        emailbody.Append("<h3 style=\"font-size: 15px; font-family: Arial, Helvetica, sans-serif; line-height: 20px;");
                        emailbody.Append("font-weight: bold; margin: 0; text-transform: capitalize; color: #000; text-shadow: 1px 1px 0 #fff;\">Order Information</h3>");
                        emailbody.Append("</td></tr><tr> <td> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append(" <tr><td width=\"120\" height=\"20\"><span style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;\">");
                        emailbody.Append(" Merchant:</span> </td> <td>");
                        //  merchant Name
                        emailbody.Append("Aspx Commerce");
                        emailbody.Append(" </td> <td width=\"150\" style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px;");
                        emailbody.Append(" font-weight: bold; border-left: 1px solid #fff; padding-left: 20px;\"> Customer Id:  <td>");
                        // customer ID
                        emailbody.Append("" + customerID.ToString() + "");
                        emailbody.Append(" </td> </tr>  <tr>  <td height=\"20\"> <span style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;\">");
                        emailbody.Append(" Description:</span>  </td> <td> Order Remarks</td> <td style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;");
                        emailbody.Append(" border-left: 1px solid #fff; padding-left: 20px;\"> Phone No: </td> <td>");
                        // customer Phone No
                        emailbody.Append("" + orderdata.ObjBillingAddressInfo.Phone.ToString() + "");
                        emailbody.Append("  </td> </tr> <td height=\"20\"><span style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;\">");
                        emailbody.Append(" Invoice Number:</span> </td><td>");
                        //   invoice no
                        emailbody.Append("" + orderdata.ObjOrderDetails.InvoiceNumber.ToString() + "");
                        // emailbody.Append("" + invoice + "");
                        emailbody.Append(" </td> <td style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;  border-left: 1px solid #fff; padding-left: 20px;\">");
                        emailbody.Append("  &nbsp;</td><td> &nbsp;</td></tr></table>  </td> </tr> </table> </div>");
                        emailbody.Append(" <div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 0; margin: 10px 0 0 0;\">");
                        emailbody.Append(" <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append(" <tr> <td width=\"300\" style=\"background: #e0e0e0;\"> <h2 style=\"margin: 0; padding: 0; font-weight: bold; font-family: Arial, Helvetica, sans-serif;");
                        emailbody.Append("  font-size: 15px; padding: 3px 0 3px 10px; text-shadow: 1px 1px 0 #fff;\">");
                        emailbody.Append("  Billing Information</h2>  </td><td style=\"background: #e0e0e0; border-left: 1px solid #fff;\">");
                        emailbody.Append("   <h2 style=\"margin: 0; padding: 0; font-weight: bold; font-family: Arial, Helvetica, sans-serif;");
                        emailbody.Append("  font-size: 15px; padding: 3px 0 3px 10px; text-shadow: 1px 1px 0 #fff;\">");
                        emailbody.Append(" Shipping Information</h2> </td></tr><tr><td valign=\"top\"> <p style=\"margin: 0; padding: 10px; font-family: Arial, Helvetica, sans-serif; font-weight: normal;");
                        emailbody.Append("  line-height: 18px; font-size: 12px;\">");
                        //Milson Munakami<br />
                        //                                                               Bd<br />
                        //                                                               sda<br />
                        //                                                               Dsad, Alberta 3232<br />
                        //                                                               Afghanistan<br />
                        //                                                               [email protected]<br />
                        //                                                               +000 000 0000<br />
                        //                                                               Fax: 2222222</p>
                        //                                                       </td>

                        string billing = orderdata.ObjBillingAddressInfo.FirstName.ToString() + " " +
                                         orderdata.ObjBillingAddressInfo.LastName.ToString() + "<br />";

                        if (orderdata.ObjBillingAddressInfo.CompanyName != null)
                        {
                            billing += orderdata.ObjBillingAddressInfo.CompanyName.ToString() + "<br />";
                        }

                        billing += orderdata.ObjBillingAddressInfo.City.ToString() + ", " + orderdata.ObjBillingAddressInfo.Address.ToString() + "<br />" +
                                   orderdata.ObjBillingAddressInfo.Country.ToString() + "<br />" +
                                   orderdata.ObjBillingAddressInfo.EmailAddress.ToString() + "<br />" +
                                   orderdata.ObjBillingAddressInfo.Phone.ToString() + "<br />" + "<p>";

                        emailbody.Append("" + billing + "");
                        emailbody.Append("</td><td style=\"border-left: 1px solid #fff;\" valign=\"top\"> <p style=\"margin: 0; padding: 10px; font-family: Arial, Helvetica, sans-serif; font-weight: normal;");
                        emailbody.Append("line-height: 18px; font-size: 12px;\">");
                        //Milson Munakami<br />
                        //                                                              Bd<br />
                        //                                                              sda<br />
                        //                                                              Dsad, Alberta 3232<br />
                        //                                                              Afghanistan<br />
                        //                                                              [email protected]<br />
                        //                                                              +000 000 0000<br />
                        //                                                              Fax: 2222222</p>

                        if (!orderdata.ObjOrderDetails.IsDownloadable)
                        {
                            if (orderdata.ObjOrderDetails.IsMultipleCheckOut == false)
                            {
                                string shipping = orderdata.ObjShippingAddressInfo.FirstName.ToString() + " " +
                                                  orderdata.ObjShippingAddressInfo.LastName.ToString() + "<br />";
                                if (orderdata.ObjShippingAddressInfo.CompanyName != null)
                                {
                                    shipping += orderdata.ObjShippingAddressInfo.CompanyName.ToString() + "<br />";
                                }

                                shipping += orderdata.ObjShippingAddressInfo.City.ToString() + ", " + orderdata.ObjShippingAddressInfo.Address.ToString() + "<br />" +
                                            orderdata.ObjShippingAddressInfo.Country.ToString() + "<br />" +
                                            orderdata.ObjShippingAddressInfo.EmailAddress.ToString() + "<br />" +
                                            orderdata.ObjShippingAddressInfo.Phone.ToString() + "<br />" + "<p>";
                                emailbody.Append("" + shipping + "");
                            }
                            else
                            {
                                emailbody.Append("Multiple addresses<br />Plese log in to view.");
                            }
                        }
                        emailbody.Append("</td> </tr> </table></div><div style=\"border: 1px solid #cfcfcf; background: #f1f1f1; padding: 0; margin: 10px 0 0 0;\">");
                        emailbody.Append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append("<tr><td style=\"background: #e0e0e0;\" colspan=\"2\"><h2 style=\"margin: 0; padding: 0; font-weight: bold; font-family: Arial, Helvetica, sans-serif;");
                        emailbody.Append("font-size: 15px; padding: 3px 0 3px 10px; text-shadow: 1px 1px 0 #fff;\">");
                        // card type Visa
                        emailbody.Append("" + orderdata.ObjPaymentInfo.PaymentMethodName.ToString() + "");
                        // emailbody.Append("" + orderdata.ObjPaymentInfo.CardType.ToString() + "");
                        emailbody.Append("</h2> </td></tr><tr><td style=\"padding: 5px 10px;\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
                        emailbody.Append("<tr><td width=\"100\" height=\"20\" style=\"width: 200\">  <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;");
                        emailbody.Append(" margin: 0; padding: 0;\"> Date/Time:</p></td><td>");
                        //    order date
                        emailbody.Append("" + DateTime.Now.ToString("dddd, dd MMMM yyyy") + "");
                        emailbody.Append("</td></tr><tr><td height=\"20\"><p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold;");
                        emailbody.Append(" margin: 0; padding: 0;\">Transaction Id:</p> </td>  <td>");
                        //     transaction ID
                        emailbody.Append("" + transID + "");
                        //emailbody.Append("" + transID + "");
                        emailbody.Append("</td> </tr></table> </td> </tr> </table></div></div>  </td> </tr>  </table>  </div>");
                        emailbody.Append(" <p style=\"font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #000;\">");
                        emailbody.Append(" if you having Issues with transaction or any further inquiry then you can mail <a");
                        emailbody.Append("href=\"mailto:[email protected]\" style=\"color: #278ee6;\">[email protected]</a></p>");
                        emailbody.Append("<p style=\"margin: 0; padding: 5px 0 0 0; font: bold 11px Arial, Helvetica, sans-serif; color: #666;\">");
                        emailbody.Append("Please do not reply to this email. This mail is automatic generated after you have ordered.</a><br />");
                        emailbody.Append("<br /> Thank You,<br />  <span style=\"font-weight: normal; font-size: 12px; font-family: Arial, Helvetica, sans-serif;\">");
                        emailbody.Append("AXPXCommerce Team </span> </p> </div> </td>  </tr>");
                        emailbody.Append("  <tr> <td>   <img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"20\" alt=\" \" /> </td>");
                        emailbody.Append("</tr> <tr> <td align=\"center\" valign=\"top\"> <p style=\"font-size: 11px; color: #4d4d4d\">");
                        emailbody.Append("  © " + DateTime.Now.Year.ToString() + " AspxCommerce. All Rights Reserved.</p></td>  </tr> <tr>");
                        emailbody.Append("  <td align=\"center\" valign=\"top\"> <img src=\"" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/blank.gif\" width=\"1\" height=\"10\" alt=\" \" />");
                        emailbody.Append("   </td>  </tr> </table></div>   </td> </tr> </table>");
                        string          body            = emailbody.ToString();
                        SageFrameConfig pagebase        = new SageFrameConfig();
                        string          emailSuperAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SuperUserEmail);//"*****@*****.**";
                        string          emailSiteAdmin  = pagebase.GetSettingsByKey(SageFrameSettingKeys.SiteAdminEmailAddress);
                        MailHelper.SendMailNoAttachment(sendEmailFrom, orderdata.ObjBillingAddressInfo.EmailAddress.ToString(), "Your Order Details", body, emailSuperAdmin, emailSiteAdmin);
                    }
                    ws.ClearSessionVariable("OrderCollection");
                }

                return(ph);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void ParseAfterIPN(string postData, AspxCommonInfo aspxCommonObj, string templateName, string addressPath)
        {
            var ph = new PayPalHandler();
            string transId = string.Empty;
            string orderStatus = string.Empty;

            try
            {
                //split response into string array using whitespace delimeter
                String[] stringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */
                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo {StoreID = aspxCommonObj.StoreID, PortalID = aspxCommonObj.PortalID, AddedBy = aspxCommonObj.UserName};
                // UpdateOrderDetails
            
                var sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
             
                int i;
                for (i = 1; i < stringArray.Length - 1; i++)
                {
                    String[] stringArray1 = stringArray[i].Split('=');

                    String sKey = stringArray1[0];
                    String sValue = HttpUtility.UrlDecode(stringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                        case "payment_status":
                            odinfo.ResponseReasonText = Convert.ToString(sValue);
                            orderStatus = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            // ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "payer_email":
                            // ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            // ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            odinfo.TransactionID = Convert.ToString(sValue);
                            transId = Convert.ToString(sValue);
                            break;

                    }
                }
             
                ot.ObjCommonInfo = cf;
                //odinfo.OrderStatusID = 8;
                //objad.UpdateOrderDetails(ot);
                if (odinfo.ResponseReasonText.ToLower().Trim() == "completed")
                {
                    if (HttpContext.Current.Session["OrderCollection"] != null)
                    {
                        var orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        AspxOrderController.UpdateItemQuantity(orderdata2);
                    }
                }
                cms.ClearCartAfterPayment(aspxCommonObj);

                //invoice  transID
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    var orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    orderdata.ObjOrderDetails.OrderStatus = orderStatus;
                    EmailTemplate.SendEmailForOrder(aspxCommonObj.PortalID, orderdata, addressPath, templateName, transId);
                }
                HttpContext.Current.Session.Remove("OrderCollection");
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static PayPalHandler ParseAfterIPN(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode, string TemplateName, string addressPath)
        {
            String        sKey, sValue;
            PayPalHandler ph      = new PayPalHandler();
            string        transID = string.Empty;

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:

                /*
                 * loop is set to start at 1 rather than 0 because first
                 * string in array will be single word SUCCESS or FAIL
                 * Only used to verify post data
                 */
                OrderDetailsCollection ot     = new OrderDetailsCollection();
                OrderDetailsInfo       odinfo = new OrderDetailsInfo();
                CartManageSQLProvider  cms    = new CartManageSQLProvider();
                CommonInfo             cf     = new CommonInfo();
                cf.StoreID  = storeID;
                cf.PortalID = portalID;
                cf.AddedBy  = userName;
                // UpdateOrderDetails
                AspxOrderDetails objad = new AspxOrderDetails();
                SQLHandler       sqlH  = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                WcfSession ws = new WcfSession();
                odinfo.OrderID = ws.GetSessionVariable("OrderID");
                int i;
                for (i = 1; i < StringArray.Length - 1; i++)
                {
                    String[] StringArray1 = StringArray[i].Split('=');

                    sKey   = StringArray1[0];
                    sValue = HttpUtility.UrlDecode(StringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                    case "payment_status":
                        odinfo.ResponseReasonText = Convert.ToString(sValue);
                        break;

                    case "mc_fee":
                        // ph.PaymentFee = Convert.ToDouble(sValue);
                        break;

                    case "payer_email":
                        // ph.PayerEmail = Convert.ToString(sValue);
                        break;

                    case "Tx Token":
                        // ph.TxToken = Convert.ToString(sValue);
                        break;

                    case "txn_id":
                        odinfo.TransactionID = Convert.ToString(sValue);
                        transID = Convert.ToString(sValue);
                        break;
                    }
                }

                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo   = cf;
                //odinfo.OrderStatusID = 8;
                //objad.UpdateOrderDetails(ot);
                if (odinfo.ResponseReasonText.ToLower().Trim() == "completed")
                {
                    if (HttpContext.Current.Session["OrderCollection"] != null)
                    {
                        OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                        orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        objad.UpdateItemQuantity(orderdata2);
                    }
                }
                ws.ClearSessionVariable("OrderID");
                cms.ClearCartAfterPayment(customerID, sessionCode, storeID, portalID);

                //invoice  transID
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    OrderDetailsCollection orderdata = new OrderDetailsCollection();
                    orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    EmailTemplate.SendEmailForOrder(portalID, orderdata, addressPath, TemplateName, transID);
                }
                ws.ClearSessionVariable("OrderCollection");

                return(ph);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void ParseAfterIPNMobile(OrderInfo orderInfo,List<CouponSession> coupons,List<OrderItem> itemsInfo,string postData,UserAddressInfo billingAddress,UserAddressInfo shippingAddress, string templateName, string addressPath)
        {

            string transId = string.Empty;

            try
            {

                String[] stringArray = postData.Split('\n');
                var ot = new OrderDetailsCollection();
                var odinfo = new OrderDetailsInfo();
                var cms = new CartManageSQLProvider();
                var cf = new CommonInfo
                             {StoreID = orderInfo.StoreId, PortalID = orderInfo.PortalId, AddedBy = orderInfo.AddedBy};
                // UpdateOrderDetails
            
                var sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter

                int i;
                for (i = 1; i < stringArray.Length - 1; i++)
                {
                    String[] stringArray1 = stringArray[i].Split('=');

                    String sKey = stringArray1[0];
                    String sValue = HttpUtility.UrlDecode(stringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                        case "payment_status":
                            odinfo.ResponseReasonText = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            // ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "payer_email":
                            // ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            // ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            odinfo.TransactionID = Convert.ToString(sValue);
                            transId = Convert.ToString(sValue);
                            break;

                    }
                }

                ot.ObjCommonInfo = cf;
                //odinfo.OrderStatusID = 8; var orderInfo = (OrderInfo) HttpContext.Current.Session["OrderCollection"];

                UpdateItemQuantityAndCoupon(orderInfo, itemsInfo, coupons, orderInfo.StoreId, orderInfo.PortalId,
                                            orderInfo.AddedBy);
                AspxCommonInfo aspxCommonObj = new AspxCommonInfo();
                aspxCommonObj.CustomerID = orderInfo.CustomerId;
                aspxCommonObj.SessionCode = orderInfo.SessionCode;
                aspxCommonObj.StoreID = orderInfo.StoreId;
                aspxCommonObj.PortalID = orderInfo.PortalId;
                cms.ClearCartAfterPayment(aspxCommonObj);
                EmailTemplate.SendEmailForOrderMobile(orderInfo, billingAddress, shippingAddress, addressPath,
                                                      templateName, transId);


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    private static void HandleNewOrderNotification(GCheckout.AutoGen.NewOrderNotification inputNewOrderNotification)
    {


        try
        {
            if (inputNewOrderNotification.shoppingcart.merchantprivatedata != null && inputNewOrderNotification.shoppingcart.merchantprivatedata.Any != null && inputNewOrderNotification.shoppingcart.merchantprivatedata.Any.Length > 0)
            {
                //Retrieve data from MerchantPrivateData
                GCheckout.AutoGen.anyMultiple oneAnyMultiple = inputNewOrderNotification.shoppingcart.merchantprivatedata;
                System.Xml.XmlNode[] oneXmlNodeArray = oneAnyMultiple.Any;
                foreach (XmlNode xn in oneXmlNodeArray)
                {


                    if (xn.Name == "OrderID")
                    {
                        orderID = Int32.Parse(xn.InnerText.ToString());
                    }

                    if (xn.Name == "userName")
                    {
                        userName = xn.InnerText.ToString();
                    }

                    if (xn.Name == "amount")
                    {
                        totalAmount = decimal.Parse(xn.InnerText.ToString());
                    }

                    if (xn.Name == "selectedCurrency")
                    {
                        selectedCurrency = xn.InnerText.ToString();
                    }

                    if (xn.Name == "portalID")
                    {
                        portalID = int.Parse(xn.InnerText.ToString());
                    }
                    if (xn.Name == "customerID")
                    {
                        customerID = int.Parse(xn.InnerText.ToString());
                    }
                    if (xn.Name == "itemIds")
                    {
                        itemIds = xn.InnerText.ToString();
                    }
                    if (xn.Name == "storeID")
                    {
                        storeID = int.Parse(xn.InnerText.ToString());
                    }
                    if (xn.Name == "couponCode")
                    {
                        couponCode = xn.InnerText.ToString();
                    }
                    if (xn.Name == "sessionCode")
                    {
                        sessionCode = xn.InnerText.ToString();
                    }
                    if (xn.Name == "pgID")
                    {
                        pgID = int.Parse(xn.InnerText.ToString());
                    }
                    if (xn.Name == "MerchantID")
                    {
                        MerchantID = xn.InnerText.ToString();
                    }
                    if (xn.Name == "MerchantKey")
                    {
                        MerchantID = xn.InnerText.ToString();
                    }
                }
                paymentStatus = GCNotificationStatus.Succeeded.ToString();
                transID = inputNewOrderNotification.googleordernumber;

                if (paymentStatus == "Succeeded")
                {
                    TransactionLogInfo tinfo = new TransactionLogInfo();
                    TransactionLog Tlog = new TransactionLog();
                    OrderDetailsCollection odc = new OrderDetailsCollection();
                   
                    tinfo.ResponseReasonText = "Succeeded";
                    tinfo.OrderID = orderID;
                    tinfo.StoreID = storeID;
                    tinfo.PortalID = portalID;
                    tinfo.AddedBy = userName;
                    tinfo.CustomerID = customerID;
                    tinfo.SessionCode = sessionCode;
                    tinfo.PaymentGatewayID = pgID;
                    tinfo.PaymentStatus = paymentStatus;
                    tinfo.PayerEmail = "";
                    tinfo.CreditCard = "";
                    tinfo.TotalAmount = totalAmount;
                    tinfo.TransactionID = transID;
                    tinfo.RecieverEmail = "";
                    tinfo.CurrencyCode = selectedCurrency;
                    Tlog.SaveTransactionLog(tinfo);

                    GoogleCheckOutHandler.ParseIPN(orderID, transID, paymentStatus, storeID, portalID, userName, customerID, sessionCode);
                    GoogleCheckOutHandler.UpdateItemQuantity(itemIds, couponCode, storeID, portalID, userName);
                    CartManageSQLProvider cms = new CartManageSQLProvider();
                    AspxCommonInfo aspxCommonObj = new AspxCommonInfo();
                    aspxCommonObj.CustomerID = customerID;
                    aspxCommonObj.SessionCode = sessionCode;
                    aspxCommonObj.StoreID = storeID;
                    aspxCommonObj.PortalID = portalID;
                    aspxCommonObj.CultureName = null;
                    aspxCommonObj.UserName = null;                    
                    cms.ClearCartAfterPayment(aspxCommonObj);

                   
                   

                }

            }
        }
        catch (Exception ex)
        {

            throw ex;
        }
        
        // TODO: Process the MerchantPrivateData if provided

        foreach (GCheckout.AutoGen.Item oneItem in inputNewOrderNotification.shoppingcart.items)
        {
            // TODO: Get MerchantItemId from shopping cart item (oneItem.merchantitemid) and process it
        }

        // TODO: Add custom processing for this notification type
    }
      public string SendPaymentInfoAIM(OrderDetailsCollection OrderDetail, string TemplateName, string addressPath)
    {
        WebClient objRequest = new WebClient();
        System.Collections.Specialized.NameValueCollection objInf = new System.Collections.Specialized.NameValueCollection(30);

        string strError;

        //OrderDetail.ObjOrderDetails.CustomerID = int.Parse(Crypto.GenerateCustomerID());
        OrderDetail.ObjOrderDetails.InvoiceNumber = Crypto.GenerateInvoiceNumber();
        OrderDetail.ObjOrderDetails.PurchaseOrderNumber = Crypto.GeneratePurchaseOrderNumber();

        //merchant generated field
        objInf.Add("x_version", OrderDetail.ObjOrderDetails.Version);
        objInf.Add("x_delim_data", OrderDetail.ObjOrderDetails.DelimData);
        objInf.Add("x_login", OrderDetail.ObjOrderDetails.APILogin);
        objInf.Add("x_tran_key", OrderDetail.ObjOrderDetails.TransactionKey);
        objInf.Add("x_relay_response", OrderDetail.ObjOrderDetails.RelayResponse);
        objInf.Add("x_delim_char", OrderDetail.ObjOrderDetails.DelimChar);
        objInf.Add("x_encap_char", OrderDetail.ObjOrderDetails.EncapeChar);
        objInf.Add("x_invoice_num", OrderDetail.ObjOrderDetails.InvoiceNumber);
        objInf.Add("x_cust_id", OrderDetail.ObjOrderDetails.CustomerID.ToString());
        objInf.Add("x_po_num", OrderDetail.ObjOrderDetails.PurchaseOrderNumber);
        //for (int i = 0; i < arr; i++)
        //{

        //}

        // Billing Address
        objInf.Add("x_first_name", OrderDetail.ObjBillingAddressInfo.FirstName);
        objInf.Add("x_last_name", OrderDetail.ObjBillingAddressInfo.LastName);
        objInf.Add("x_company", OrderDetail.ObjBillingAddressInfo.CompanyName);
        objInf.Add("x_email", OrderDetail.ObjBillingAddressInfo.EmailAddress);
        objInf.Add("x_address", OrderDetail.ObjBillingAddressInfo.Address);
        objInf.Add("x_city", OrderDetail.ObjBillingAddressInfo.City);
        objInf.Add("x_state", OrderDetail.ObjBillingAddressInfo.State);
        objInf.Add("x_zip", OrderDetail.ObjBillingAddressInfo.Zip);
        objInf.Add("x_country", OrderDetail.ObjBillingAddressInfo.Country);
        objInf.Add("x_phone", OrderDetail.ObjBillingAddressInfo.Phone);
        objInf.Add("x_fax", OrderDetail.ObjBillingAddressInfo.Fax);
        objInf.Add("x_email_customer", OrderDetail.ObjOrderDetails.IsEmailCustomer);

        if (OrderDetail.ObjOrderDetails.IsMultipleCheckOut == false)
        {
            //shipping address
            objInf.Add("x_ship_to_first_name", OrderDetail.ObjShippingAddressInfo.FirstName);
            objInf.Add("x_ship_to_last_name", OrderDetail.ObjShippingAddressInfo.LastName);
            objInf.Add("x_ship_to_company", OrderDetail.ObjShippingAddressInfo.CompanyName);
            objInf.Add("x_ship_to_address", OrderDetail.ObjShippingAddressInfo.Address);
            objInf.Add("x_ship_to_city", OrderDetail.ObjShippingAddressInfo.City);
            objInf.Add("x_ship_to_state", OrderDetail.ObjShippingAddressInfo.State);
            objInf.Add("x_ship_to_zip", OrderDetail.ObjShippingAddressInfo.Zip);
            objInf.Add("x_ship_to_country", OrderDetail.ObjShippingAddressInfo.Country);
        }
        // Card Details
        objInf.Add("x_card_num", OrderDetail.ObjPaymentInfo.CardNumber);
        objInf.Add("x_card_type", OrderDetail.ObjPaymentInfo.CardType);
        objInf.Add("x_exp_date", OrderDetail.ObjPaymentInfo.ExpireDate);
        if (OrderDetail.ObjPaymentInfo.PaymentMethodCode=="CC")
        {
            // Authorization code of the card (CCV)
            objInf.Add("x_card_code", OrderDetail.ObjPaymentInfo.CardCode.ToString());
            objInf.Add("x_method", OrderDetail.ObjPaymentInfo.PaymentMethodCode);
            objInf.Add("x_type", OrderDetail.ObjPaymentInfo.TransactionType);
            string amount = Regex.Replace(OrderDetail.ObjOrderDetails.GrandTotal.ToString("0.00"), @"[A-Z]", String.Empty);
            objInf.Add("x_amount", amount);
            objInf.Add("x_description", OrderDetail.ObjOrderDetails.Remarks);
            objInf.Add("x_test_request", OrderDetail.ObjOrderDetails.IsTest);
        }
        else
        {


            //bank 
            objInf.Add("x_bank_aba_code", OrderDetail.ObjPaymentInfo.RoutingNumber);
            objInf.Add("x_bank_acct_num", OrderDetail.ObjPaymentInfo.AccountNumber);
            objInf.Add("x_bank_acct_type", OrderDetail.ObjPaymentInfo.AccountType);
            objInf.Add("x_bank_name", OrderDetail.ObjPaymentInfo.BankName);
            objInf.Add("x_bank_acct_name", OrderDetail.ObjPaymentInfo.AccountHolderName);
            objInf.Add("x_echeck_type", OrderDetail.ObjPaymentInfo.ChequeType);
            objInf.Add("x_bank_check_number", OrderDetail.ObjPaymentInfo.ChequeNumber);
        }

        // Currency setting. Check the guide for other supported currencies
        objInf.Add("x_currency_code", OrderDetail.ObjOrderDetails.CurrencyCode);
        objRequest.BaseAddress ="https://test.authorize.net/gateway/transact.dll";

        try
        {
            // POST request
            byte[] objRetBytes;
            string[] objRetVals;

            objRetBytes =
                objRequest.UploadValues(objRequest.BaseAddress, "POST", objInf);
            objRetVals =
                System.Text.Encoding.ASCII.GetString(objRetBytes).Split(",".ToCharArray());

            // Process Return Values
            OrderDetail.ObjOrderDetails.ResponseCode = int.Parse(objRetVals[0].Trim(char.Parse("|")));
            OrderDetail.ObjOrderDetails.ResponseReasonCode = int.Parse(objRetVals[2].Trim(char.Parse("|")));
            if (objRetVals[0].Trim(char.Parse("|")) == "1")
            {
                // Returned Authorisation Code
                //response.AuthorizationCode = objRetVals[4].Trim(char.Parse("|"));
                // Returned Transaction ID
                OrderDetail.ObjOrderDetails.TransactionID = Convert.ToString(objRetVals[6].Trim(char.Parse("|")));
                strError = "Transaction completed successfully.";
               // AspxCommerceWebService asws = new AspxCommerceWebService();
                AspxCoreController asws = new AspxCoreController();
                OrderDetail.ObjOrderDetails.OrderStatusID = 8;
                OrderDetail.ObjOrderDetails.TransactionID = Convert.ToString(objRetVals[6].Trim(char.Parse("|")));
                asws.AddOrderDetails(OrderDetail);
                CartManageSQLProvider cms = new CartManageSQLProvider();
                AspxCommonInfo aspxCommonObj = new AspxCommonInfo();
                aspxCommonObj.CustomerID = OrderDetail.ObjOrderDetails.CustomerID;
                aspxCommonObj.SessionCode = OrderDetail.ObjOrderDetails.SessionCode;
                aspxCommonObj.StoreID = OrderDetail.ObjCommonInfo.StoreID;
                aspxCommonObj.PortalID = OrderDetail.ObjCommonInfo.PortalID;
                cms.ClearCartAfterPayment(aspxCommonObj);

            }
            else
            {
                // Error!
                strError = objRetVals[3].Trim(char.Parse("|")) + " (" +
                           objRetVals[2].Trim(char.Parse("|")) + ")";

                if (objRetVals[2].Trim(char.Parse("|")) == "44")
                {
                    // CCV transaction decline
                    strError += "Our Card Code Verification (CCV) returned " +
                                "the following error: ";

                    switch (objRetVals[38].Trim(char.Parse("|")))
                    {
                        case "N":
                            strError += "Card Code does not match.";
                            break;
                        case "P":
                            strError += "Card Code was not processed.";
                            break;
                        case "S":
                            strError += "Card Code should be on card but was not indicated.";
                            break;
                        case "U":
                            strError += "Issuer was not certified for Card Code.";
                            break;
                    }
                }

                if (objRetVals[2].Trim(char.Parse("|")) == "45")
                {
                    if (strError.Length > 1)
                        strError += "<br />n";

                    // AVS transaction decline
                    strError += "Our Address Verification System (AVS) " +
                                "returned the following error: ";

                    switch (objRetVals[5].Trim(char.Parse("|")))
                    {
                        case "A":
                            strError += " the zip code entered does not match " +
                                        "the billing address.";
                            break;
                        case "B":
                            strError += " no information was provided for the AVS check.";
                            break;
                        case "E":
                            strError += " a general error occurred in the AVS system.";
                            break;
                        case "G":
                            strError += " the credit card was issued by a non-US bank.";
                            break;
                        case "N":
                            strError += " neither the entered street address nor zip " +
                                        "code matches the billing address.";
                            break;
                        case "P":
                            strError += " AVS is not applicable for this transaction.";
                            break;
                        case "R":
                            strError += " please retry the transaction; the AVS system " +
                                        "was unavailable or timed out.";
                            break;
                        case "S":
                            strError += " the AVS service is not supported by your " +
                                        "credit card issuer.";
                            break;
                        case "U":
                            strError += " address information is unavailable for the " +
                                        "credit card.";
                            break;
                        case "W":
                            strError += " the 9 digit zip code matches, but the " +
                                        "street address does not.";
                            break;
                        case "Z":
                            strError += " the zip code matches, but the address does not.";
                            break;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            strError = ex.Message;
        }
        OrderDetail.ObjOrderDetails.ResponseReasonText = strError;       
        return OrderDetail.ObjOrderDetails.ResponseReasonText;
    }
Beispiel #17
0
        public string SendPaymentInfoAIM(OrderDetailsCollection OrderDetail, string TemplateName, string addressPath)
        {
            var objRequest = new WebClient();
            var objInf     = new System.Collections.Specialized.NameValueCollection(30);

            string strError;

            //OrderDetail.ObjOrderDetails.CustomerID = int.Parse(Crypto.GenerateCustomerID());
            OrderDetail.ObjOrderDetails.InvoiceNumber       = Crypto.GenerateInvoiceNumber();
            OrderDetail.ObjOrderDetails.PurchaseOrderNumber = Crypto.GeneratePurchaseOrderNumber();

            //merchant generated field
            objInf.Add("x_version", OrderDetail.ObjOrderDetails.Version);
            objInf.Add("x_delim_data", "True");
            objInf.Add("x_login", OrderDetail.ObjOrderDetails.APILogin);
            objInf.Add("x_tran_key", OrderDetail.ObjOrderDetails.TransactionKey);
            objInf.Add("x_relay_response", "False");
            objInf.Add("x_delim_char", ",");
            objInf.Add("x_encap_char", "|");
            objInf.Add("x_invoice_num", OrderDetail.ObjOrderDetails.InvoiceNumber);
            objInf.Add("x_cust_id", OrderDetail.ObjOrderDetails.CustomerID.ToString(CultureInfo.InvariantCulture));
            objInf.Add("x_po_num", OrderDetail.ObjOrderDetails.PurchaseOrderNumber);

            // Billing Address
            objInf.Add("x_first_name", OrderDetail.ObjBillingAddressInfo.FirstName);
            objInf.Add("x_last_name", OrderDetail.ObjBillingAddressInfo.LastName);
            objInf.Add("x_company", OrderDetail.ObjBillingAddressInfo.CompanyName);
            objInf.Add("x_email", OrderDetail.ObjBillingAddressInfo.EmailAddress);
            objInf.Add("x_address", OrderDetail.ObjBillingAddressInfo.Address);
            objInf.Add("x_city", OrderDetail.ObjBillingAddressInfo.City);
            objInf.Add("x_state", OrderDetail.ObjBillingAddressInfo.State);
            objInf.Add("x_zip", OrderDetail.ObjBillingAddressInfo.Zip);
            objInf.Add("x_country", OrderDetail.ObjBillingAddressInfo.Country);
            objInf.Add("x_phone", OrderDetail.ObjBillingAddressInfo.Phone);
            objInf.Add("x_fax", OrderDetail.ObjBillingAddressInfo.Fax);
            objInf.Add("x_email_customer", OrderDetail.ObjOrderDetails.IsEmailCustomer);

            if (OrderDetail.ObjOrderDetails.IsMultipleCheckOut == false)
            {
                //shipping address
                objInf.Add("x_ship_to_first_name", OrderDetail.ObjShippingAddressInfo.FirstName);
                objInf.Add("x_ship_to_last_name", OrderDetail.ObjShippingAddressInfo.LastName);
                objInf.Add("x_ship_to_company", OrderDetail.ObjShippingAddressInfo.CompanyName);
                objInf.Add("x_ship_to_address", OrderDetail.ObjShippingAddressInfo.Address);
                objInf.Add("x_ship_to_city", OrderDetail.ObjShippingAddressInfo.City);
                objInf.Add("x_ship_to_state", OrderDetail.ObjShippingAddressInfo.State);
                objInf.Add("x_ship_to_zip", OrderDetail.ObjShippingAddressInfo.Zip);
                objInf.Add("x_ship_to_country", OrderDetail.ObjShippingAddressInfo.Country);
            }
            // Card Details
            objInf.Add("x_card_num", OrderDetail.ObjPaymentInfo.CardNumber);
            objInf.Add("x_card_type", OrderDetail.ObjPaymentInfo.CardType);
            objInf.Add("x_exp_date", OrderDetail.ObjPaymentInfo.ExpireDate);

            var            ssc = new StoreSettingConfig();
            double         rate;
            string         mainCurrency    = ssc.GetStoreSettingsByKey(StoreSetting.MainCurrency, OrderDetail.ObjCommonInfo.StoreID, OrderDetail.ObjCommonInfo.PortalID, OrderDetail.ObjCommonInfo.CultureName);
            const string   gateWayCurrency = "USD";
            AspxCommonInfo aspxCommonObj   = new AspxCommonInfo();

            aspxCommonObj.CustomerID  = OrderDetail.ObjOrderDetails.CustomerID;
            aspxCommonObj.SessionCode = OrderDetail.ObjOrderDetails.SessionCode;
            aspxCommonObj.StoreID     = OrderDetail.ObjCommonInfo.StoreID;
            aspxCommonObj.PortalID    = OrderDetail.ObjCommonInfo.PortalID;

            if (gateWayCurrency.ToLower().Trim() == mainCurrency.ToLower().Trim())
            {
                rate = 1;
            }
            else
            {
                AspxCoreController acc = new AspxCoreController();
                rate = acc.GetCurrencyRateOnChange(aspxCommonObj, mainCurrency, gateWayCurrency.Trim(), "en-US");
            }
            //double amountTotal = double.Parse(HttpContext.Current.Session["GrandTotalAll"].ToString()) * rate;
            double  amountTotal = double.Parse(CheckOutSessions.Get <Double>("GrandTotalAll", 0).ToString()) * rate;
            decimal amount      = decimal.Parse(amountTotal.ToString(CultureInfo.InvariantCulture));

            //string amount = Regex.Replace(OrderDetail.ObjOrderDetails.GrandTotal.ToString("0.00"), @"[A-Z]", String.Empty);
            objInf.Add("x_amount", Math.Round(amount, 2).ToString(CultureInfo.InvariantCulture));
            objInf.Add("x_test_request", "False");
            if (OrderDetail.ObjPaymentInfo.PaymentMethodCode == "CC")
            {
                // Authorization code of the card (CCV)
                objInf.Add("x_card_code", OrderDetail.ObjPaymentInfo.CardCode.Trim());
                objInf.Add("x_method", OrderDetail.ObjPaymentInfo.PaymentMethodCode.Trim());
                objInf.Add("x_type", OrderDetail.ObjPaymentInfo.TransactionType.Trim());
                // string amount = Regex.Replace(OrderDetail.ObjOrderDetails.GrandTotal.ToString("0.00"), @"[A-Z]", String.Empty);
                // objInf.Add("x_amount", amount);
                objInf.Add("x_description", OrderDetail.ObjOrderDetails.Remarks.Trim());
            }
            else
            {
                //bank
                objInf.Add("x_bank_aba_code", OrderDetail.ObjPaymentInfo.RoutingNumber.Trim());
                objInf.Add("x_bank_acct_num", OrderDetail.ObjPaymentInfo.AccountNumber.Trim());
                objInf.Add("x_bank_acct_type", OrderDetail.ObjPaymentInfo.AccountType.Trim());
                objInf.Add("x_bank_name", OrderDetail.ObjPaymentInfo.BankName.Trim());
                objInf.Add("x_bank_acct_name", OrderDetail.ObjPaymentInfo.AccountHolderName.Trim());
                objInf.Add("x_echeck_type", OrderDetail.ObjPaymentInfo.ChequeType.Trim());
                objInf.Add("x_bank_check_number", OrderDetail.ObjPaymentInfo.ChequeNumber.Trim());
            }

            // Currency setting. Check the guide for other supported currencies
            objInf.Add("x_currency_code", OrderDetail.ObjOrderDetails.CurrencyCode.Trim());

            if (OrderDetail.ObjOrderDetails.IsTest.ToLower().Trim() == "true" || OrderDetail.ObjOrderDetails.IsTest.ToLower() == "1")
            {
                objRequest.BaseAddress = "https://test.authorize.net/gateway/transact.dll";
            }
            else
            {
                objRequest.BaseAddress = "https://secure.authorize.net/gateway/transact.dll";
            }

            try
            {
                // POST request

                byte[]   objRetBytes = objRequest.UploadValues(objRequest.BaseAddress, "POST", objInf);
                string[] objRetVals  = System.Text.Encoding.ASCII.GetString(objRetBytes).Split(",".ToCharArray());

                // Process Return Values
                OrderDetail.ObjOrderDetails.ResponseCode       = int.Parse(objRetVals[0].Trim(char.Parse("|")));
                OrderDetail.ObjOrderDetails.ResponseReasonCode = int.Parse(objRetVals[2].Trim(char.Parse("|")));

                if (objRetVals[0].Trim(char.Parse("|")) == "1")
                {
                    // Returned Authorisation Code
                    //response.AuthorizationCode = objRetVals[4].Trim(char.Parse("|"));
                    // Returned Transaction ID
                    OrderDetail.ObjOrderDetails.TransactionID = Convert.ToString(objRetVals[6].Trim(char.Parse("|")));
                    strError = "Transaction completed successfully.";

                    AspxCoreController acc = new AspxCoreController();
                    OrderDetail.ObjOrderDetails.OrderStatusID = 8;
                    OrderDetail.ObjOrderDetails.TransactionID = Convert.ToString(objRetVals[6].Trim(char.Parse("|")));
                    acc.AddOrderDetails(OrderDetail);
                    HttpContext.Current.Session["TransDetailsAIM"] = OrderDetail.ObjOrderDetails.InvoiceNumber + "#" + OrderDetail.ObjOrderDetails.TransactionID + "#" + "AIM Authorize.Net";
                    if (HttpContext.Current.Session["OrderCollection"] != null)
                    {
                        OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                        if (HttpContext.Current.Session["OrderCollection"] != null)
                        {
                            orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        }

                        AspxOrderController.UpdateItemQuantity(orderdata2);
                        AspxGiftCardController.IssueGiftCard(orderdata2.LstOrderItemsInfo, orderdata2.ObjOrderDetails.OrderID, true, aspxCommonObj);
                        if (orderdata2.GiftCardDetail != null && HttpContext.Current.Session["UsedGiftCard"] != null)
                        {   //updating giftcard used in chekout
                            AspxGiftCardController.UpdateGiftCardUsage(orderdata2.GiftCardDetail, orderdata2.ObjCommonInfo.StoreID,
                                                                       orderdata2.ObjCommonInfo.PortalID, orderdata2.ObjOrderDetails.OrderID, orderdata2.ObjCommonInfo.AddedBy,
                                                                       orderdata2.ObjCommonInfo.CultureName);
                            HttpContext.Current.Session.Remove("UsedGiftCard");
                        }


                        var tinfo = new TransactionLogInfo();
                        var tlog  = new TransactionLog();

                        tinfo.TransactionID      = OrderDetail.ObjOrderDetails.TransactionID;
                        tinfo.AuthCode           = objRetVals[4].Trim(char.Parse("|"));//auth Code
                        tinfo.TotalAmount        = OrderDetail.ObjOrderDetails.GrandTotal;
                        tinfo.ResponseCode       = "1";
                        tinfo.ResponseReasonText = strError;
                        tinfo.OrderID            = orderdata2.ObjOrderDetails.OrderID;
                        tinfo.StoreID            = OrderDetail.ObjCommonInfo.StoreID;
                        tinfo.PortalID           = OrderDetail.ObjCommonInfo.PortalID;
                        tinfo.AddedBy            = OrderDetail.ObjCommonInfo.AddedBy;
                        tinfo.CustomerID         = OrderDetail.ObjOrderDetails.CustomerID;
                        tinfo.SessionCode        = OrderDetail.ObjOrderDetails.SessionCode;
                        tinfo.PaymentGatewayID   = OrderDetail.ObjOrderDetails.PaymentGatewayTypeID;
                        tinfo.PaymentStatus      = "Processed";
                        tinfo.PayerEmail         = OrderDetail.ObjBillingAddressInfo.EmailAddress;
                        tinfo.CreditCard         = OrderDetail.ObjPaymentInfo.CardNumber;
                        tinfo.CurrencyCode       = gateWayCurrency.Trim();
                        tlog.SaveTransactionLog(tinfo);
                    }

                    var cms = new AspxCommerce.Core.CartManageSQLProvider();
                    cms.ClearCartAfterPayment(aspxCommonObj);

                    // StoreSettingConfig ssc = new StoreSettingConfig();
                    string sendEmailFrom   = ssc.GetStoreSettingsByKey(StoreSetting.SendEcommerceEmailsFrom, OrderDetail.ObjCommonInfo.StoreID, OrderDetail.ObjCommonInfo.PortalID, OrderDetail.ObjCommonInfo.CultureName);
                    string sendOrderNotice = ssc.GetStoreSettingsByKey(StoreSetting.SendOrderNotification, OrderDetail.ObjCommonInfo.StoreID, OrderDetail.ObjCommonInfo.PortalID, OrderDetail.ObjCommonInfo.CultureName);



                    if (sendOrderNotice.ToLower() == "true")
                    {
                        try
                        {
                            EmailTemplate.SendEmailForOrder(OrderDetail.ObjCommonInfo.PortalID, OrderDetail, addressPath,
                                                            TemplateName, OrderDetail.ObjOrderDetails.TransactionID);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    acc.ClearSessionVariable("OrderCollection");
                    CheckOutHelper cHelper = new CheckOutHelper();
                    cHelper.ClearSessions();
                }
                else
                {
                    // Error!
                    strError = objRetVals[3].Trim(char.Parse("|")) + " (" +
                               objRetVals[2].Trim(char.Parse("|")) + ")";

                    if (objRetVals[2].Trim(char.Parse("|")) == "44")
                    {
                        // CCV transaction decline
                        strError += "Our Card Code Verification (CCV) returned " +
                                    "the following error: ";

                        switch (objRetVals[38].Trim(char.Parse("|")))
                        {
                        case "N":
                            strError += "Card Code does not match.";
                            break;

                        case "P":
                            strError += "Card Code was not processed.";
                            break;

                        case "S":
                            strError += "Card Code should be on card but was not indicated.";
                            break;

                        case "U":
                            strError += "Issuer was not certified for Card Code.";
                            break;
                        }
                    }

                    if (objRetVals[2].Trim(char.Parse("|")) == "45")
                    {
                        if (strError.Length > 1)
                        {
                            strError += "<br />n";
                        }

                        // AVS transaction decline
                        strError += "Our Address Verification System (AVS) " +
                                    "returned the following error: ";

                        switch (objRetVals[5].Trim(char.Parse("|")))
                        {
                        case "A":
                            strError += " the zip code entered does not match " +
                                        "the billing address.";
                            break;

                        case "B":
                            strError += " no information was provided for the AVS check.";
                            break;

                        case "E":
                            strError += " a general error occurred in the AVS system.";
                            break;

                        case "G":
                            strError += " the credit card was issued by a non-US bank.";
                            break;

                        case "N":
                            strError += " neither the entered street address nor zip " +
                                        "code matches the billing address.";
                            break;

                        case "P":
                            strError += " AVS is not applicable for this transaction.";
                            break;

                        case "R":
                            strError += " please retry the transaction; the AVS system " +
                                        "was unavailable or timed out.";
                            break;

                        case "S":
                            strError += " the AVS service is not supported by your " +
                                        "credit card issuer.";
                            break;

                        case "U":
                            strError += " address information is unavailable for the " +
                                        "credit card.";
                            break;

                        case "W":
                            strError += " the 9 digit zip code matches, but the " +
                                        "street address does not.";
                            break;

                        case "Z":
                            strError += " the zip code matches, but the address does not.";
                            break;
                        }
                    }
                    var tinfo = new TransactionLogInfo();
                    var tlog  = new TransactionLog();

                    tinfo.TransactionID      = "";
                    tinfo.AuthCode           = objRetVals[4].Trim(char.Parse("|"));//auth Code
                    tinfo.TotalAmount        = amount;
                    tinfo.ResponseCode       = objRetVals[2].Trim(char.Parse("|"));
                    tinfo.ResponseReasonText = strError;
                    tinfo.OrderID            = OrderDetail.ObjOrderDetails.OrderID;
                    tinfo.StoreID            = OrderDetail.ObjCommonInfo.StoreID;
                    tinfo.PortalID           = OrderDetail.ObjCommonInfo.PortalID;
                    tinfo.AddedBy            = OrderDetail.ObjCommonInfo.AddedBy;
                    tinfo.CustomerID         = OrderDetail.ObjOrderDetails.CustomerID;
                    tinfo.SessionCode        = OrderDetail.ObjOrderDetails.SessionCode;
                    tinfo.PaymentGatewayID   = OrderDetail.ObjOrderDetails.PaymentGatewayTypeID;
                    tinfo.PaymentStatus      = "Failed";
                    tinfo.PayerEmail         = OrderDetail.ObjBillingAddressInfo.EmailAddress;
                    tinfo.CreditCard         = OrderDetail.ObjPaymentInfo.CardNumber;
                    tinfo.CurrencyCode       = gateWayCurrency.Trim();
                    tlog.SaveTransactionLog(tinfo);
                }
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            OrderDetail.ObjOrderDetails.ResponseReasonText = strError;
            return(OrderDetail.ObjOrderDetails.ResponseReasonText);
        }
 public List<ShippingMethodInfo> GetShippingMethodByWeight(int storeID, int portalID, int customerID, string userName, string cultureName, string sessionCode)
 {
     try
     {
         CartManageSQLProvider cmSQLProvider = new CartManageSQLProvider();
         return cmSQLProvider.GetShippingMethodByWeight(storeID, portalID, customerID, userName, cultureName, sessionCode);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public void DeleteCartItem(int cartID, int cartItemID, int customerID, string sessionCode, int storeID, int portalID, string userName)
 {
     try
     {
         CartManageSQLProvider crtManSQLProvider = new CartManageSQLProvider();
         crtManSQLProvider.DeleteCartItem(cartID, cartItemID, customerID, sessionCode, storeID, portalID, userName);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public bool CheckCart(int itemID, int storeID, int portalID, string userName, string cultureName)
        {
            try
            {
                CartManageSQLProvider cartSqlProvider = new CartManageSQLProvider();
                return cartSqlProvider.CheckCart(itemID, storeID, portalID, userName, cultureName);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string Parse(int orderId,string transId, string invoice, string POrderno, int responseCode, int responsereasonCode,
                                  string responsetext, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                OrderDetailsCollection ot = new OrderDetailsCollection();
                OrderDetailsInfo odinfo = new OrderDetailsInfo();
                CartManageSQLProvider cms = new CartManageSQLProvider();
                CommonInfo cf = new CommonInfo();
                cf.StoreID = aspxCommonObj.StoreID;
                cf.PortalID = aspxCommonObj.PortalID;
                cf.AddedBy = aspxCommonObj.UserName;
                // UpdateOrderDetails
              
                odinfo.OrderID = orderId;
                odinfo.TransactionID = odinfo.ResponseCode.ToString(transId);
                odinfo.InvoiceNumber = Convert.ToString(invoice);
                odinfo.PurchaseOrderNumber = Convert.ToString(POrderno);
                odinfo.ResponseCode = Convert.ToInt32(responseCode);
                odinfo.ResponseReasonCode = Convert.ToInt32(responsereasonCode);
                odinfo.ResponseReasonText = Convert.ToString(responsetext);
                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                //GIFT CARD PURCHAGE PAYMENT COMPLETED
                odinfo.OrderStatusID = 3;
                AspxOrderController.UpdateOrderDetails(ot);

                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    var orderdata2 = new OrderDetailsCollection();
                    orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    AspxOrderController.UpdateItemQuantity(orderdata2);
                    IssueGiftCard(orderdata2.LstOrderItemsInfo,orderId, true, aspxCommonObj);
                }
                HttpContext.Current.Session.Remove("OrderID");
                cms.ClearCartAfterPayment(aspxCommonObj);
                return "This transaction has been approved";
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public static int AddItemstoCart(int itemID, decimal itemPrice, int itemQuantity, bool isItemPage, AspxCommonInfo aspxCommonObj)
        {
            try
            {
                var cartobj = new CartManageSQLProvider();
                StoreSettingConfig ssc = new StoreSettingConfig();

                if (cartobj.CheckItemCart(itemID, aspxCommonObj.StoreID, aspxCommonObj.PortalID, "0@"))
                {
                    List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamNoCID(aspxCommonObj);
                    parameter.Add(new KeyValuePair<string, object>("@ItemID", itemID));
                    parameter.Add(new KeyValuePair<string, object>("@Price", itemPrice));
                    parameter.Add(new KeyValuePair<string, object>("@Quantity", itemQuantity));
                    SQLHandler sqlH = new SQLHandler();
                    int i;
                    if (isItemPage)
                        i = sqlH.ExecuteNonQueryAsGivenType<int>("usp_Aspx_CheckCostVariantForItemDetail", parameter, "@IsExist");
                    else
                        i = sqlH.ExecuteNonQueryAsGivenType<int>("usp_Aspx_CheckCostVariantForItem", parameter, "@IsExist");
                    return i;

                }
                else
                {
                    if (bool.Parse(ssc.GetStoreSettingsByKey(StoreSetting.AllowOutStockPurchase, aspxCommonObj.StoreID, aspxCommonObj.PortalID, aspxCommonObj.CultureName)))
                    {
                        List<KeyValuePair<string, object>> parameter = CommonParmBuilder.GetParamNoCID(aspxCommonObj);
                        parameter.Add(new KeyValuePair<string, object>("@ItemID", itemID));
                        parameter.Add(new KeyValuePair<string, object>("@Price", itemPrice));
                        parameter.Add(new KeyValuePair<string, object>("@Quantity", itemQuantity));
                        parameter.Add(new KeyValuePair<string, object>("@isItemPage", isItemPage));
                        SQLHandler sqlH = new SQLHandler();
                        int i;
                        if (isItemPage)
                            i = sqlH.ExecuteNonQueryAsGivenType<int>("usp_Aspx_CheckCostVariantForItemDetail", parameter, "@IsExist");
                        else
                            i = sqlH.ExecuteNonQueryAsGivenType<int>("usp_Aspx_CheckCostVariantForItem", parameter, "@IsExist");
                        return i;
                    }
                    else
                    {
                        return 2;
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public List<CartInfo> GetCartDetails(int storeID, int portalID, int customerID, string userName, string cultureName, string sessionCode)
 {
     try
     {
         CartManageSQLProvider crtManSQLProvider = new CartManageSQLProvider();
         return crtManSQLProvider.GetCartDetails(storeID, portalID, customerID, userName, cultureName, sessionCode);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public static PayPalHandler ParseAfterIPN(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode, string TemplateName, string addressPath)
        {
            String sKey, sValue;
            PayPalHandler ph = new PayPalHandler();
            string transID = string.Empty;

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */
                OrderDetailsCollection ot = new OrderDetailsCollection();
                OrderDetailsInfo odinfo = new OrderDetailsInfo();
                CartManageSQLProvider cms = new CartManageSQLProvider();
                CommonInfo cf = new CommonInfo();
                cf.StoreID = storeID;
                cf.PortalID = portalID;
                cf.AddedBy = userName;
                // UpdateOrderDetails
                AspxOrderDetails objad = new AspxOrderDetails();
                SQLHandler sqlH = new SQLHandler();
                // use split to split array we already have using "=" as delimiter
                WcfSession ws = new WcfSession();
                odinfo.OrderID = ws.GetSessionVariable("OrderID");
                int i;
                for (i = 1; i < StringArray.Length - 1; i++)
                {
                    String[] StringArray1 = StringArray[i].Split('=');

                    sKey = StringArray1[0];
                    sValue = HttpUtility.UrlDecode(StringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                        case "payment_status":
                            odinfo.ResponseReasonText = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            // ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "payer_email":
                            // ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            // ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            odinfo.TransactionID = Convert.ToString(sValue);
                            transID = Convert.ToString(sValue);
                            break;

                    }
                }

                ot.ObjOrderDetails = odinfo;
                ot.ObjCommonInfo = cf;
                //odinfo.OrderStatusID = 8;
                //objad.UpdateOrderDetails(ot);
                if (odinfo.ResponseReasonText.ToLower().Trim() == "completed")
                {
                    if (HttpContext.Current.Session["OrderCollection"] != null)
                    {
                        OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                        orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                        objad.UpdateItemQuantity(orderdata2);
                    }
                }
                ws.ClearSessionVariable("OrderID");
                cms.ClearCartAfterPayment(customerID, sessionCode, storeID, portalID);

                //invoice  transID
                if (HttpContext.Current.Session["OrderCollection"] != null)
                {
                    OrderDetailsCollection orderdata = new OrderDetailsCollection();
                    orderdata = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];
                    EmailTemplate.SendEmailForOrder(portalID, orderdata, addressPath, TemplateName, transID);
                }
                ws.ClearSessionVariable("OrderCollection");

                return ph;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void ClearAllCartItems(int cartID, int customerID, string sessionCode, int storeID, int portalID)
 {
     CartManageSQLProvider crtManSQLProvider = new CartManageSQLProvider();
     crtManSQLProvider.ClearAllCartItems(cartID, customerID, sessionCode, storeID, portalID);
 }
    public static PayPalHandler ParseAfterIPN(string postData, int storeID, int portalID, string userName, int customerID, string sessionCode, string TemplateName, string addressPath)
    {
        String sKey, sValue;
        PayPalHandler ph = new PayPalHandler();
        string transID = string.Empty;
        try
        {
                       String[] StringArray = postData.Split('\n');

                       /*
            * loop is set to start at 1 rather than 0 because first
            string in array will be single word SUCCESS or FAIL
            Only used to verify post data
            */
            OrderDetailsCollection ot = new OrderDetailsCollection();
            OrderDetailsInfo odinfo = new OrderDetailsInfo();
            CartManageSQLProvider cms = new CartManageSQLProvider();
            CommonInfo cf = new CommonInfo();
            cf.StoreID = storeID;
            cf.PortalID = portalID;
            cf.AddedBy = userName;
                       AspxOrderDetails objad = new AspxOrderDetails();
            SQLHandler sqlH = new SQLHandler();
                       odinfo.OrderID = int.Parse(HttpContext.Current.Session["OrderID"].ToString());
            int i;
            for (i = 1; i < StringArray.Length - 1; i++)
            {
                String[] StringArray1 = StringArray[i].Split('=');

                sKey = StringArray1[0];
                sValue = HttpUtility.UrlDecode(StringArray1[1]);

                               switch (sKey)
                {
                    case "payment_status":
                        odinfo.ResponseReasonText = Convert.ToString(sValue);
                        break;

                    case "mc_fee":
                                               break;

                    case "payer_email":
                                               break;

                    case "Tx Token":
                                               break;

                    case "txn_id":
                        odinfo.TransactionID = Convert.ToString(sValue);
                        transID = Convert.ToString(sValue);
                        break;

                }
            }

            ot.ObjOrderDetails = odinfo;
            ot.ObjCommonInfo = cf;
            HttpContext.Current.Session.Remove("OrderID");
            HttpContext.Current.Session.Remove("OrderCollection");

            return ph;
        }
        catch (Exception ex)
        {
            
            throw ex;
        }

    }
 public void UpdateShoppingCart(int cartID, string quantitys, int storeID, int portalID, string cartItemIDs,string userName,string cultureName)
 {
     try
     {
         CartManageSQLProvider crtManSQLProvider = new CartManageSQLProvider();
         crtManSQLProvider.UpdateShoppingCart(cartID, quantitys, storeID, portalID, cartItemIDs, userName, cultureName);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public string SendPaymentInfoAIM(OrderDetailsCollection OrderDetail, string TemplateName, string addressPath)
        {

            var objRequest = new WebClient();
            var objInf = new System.Collections.Specialized.NameValueCollection(30);

            string strError;

            //OrderDetail.ObjOrderDetails.CustomerID = int.Parse(Crypto.GenerateCustomerID());
            OrderDetail.ObjOrderDetails.InvoiceNumber = Crypto.GenerateInvoiceNumber();
            OrderDetail.ObjOrderDetails.PurchaseOrderNumber = Crypto.GeneratePurchaseOrderNumber();

            //merchant generated field
            objInf.Add("x_version", OrderDetail.ObjOrderDetails.Version);
            objInf.Add("x_delim_data", "True");
            objInf.Add("x_login", OrderDetail.ObjOrderDetails.APILogin);
            objInf.Add("x_tran_key", OrderDetail.ObjOrderDetails.TransactionKey);
            objInf.Add("x_relay_response", "False");
            objInf.Add("x_delim_char", ",");
            objInf.Add("x_encap_char", "|");
            objInf.Add("x_invoice_num", OrderDetail.ObjOrderDetails.InvoiceNumber);
            objInf.Add("x_cust_id", OrderDetail.ObjOrderDetails.CustomerID.ToString(CultureInfo.InvariantCulture));
            objInf.Add("x_po_num", OrderDetail.ObjOrderDetails.PurchaseOrderNumber);

            // Billing Address
            objInf.Add("x_first_name", OrderDetail.ObjBillingAddressInfo.FirstName);
            objInf.Add("x_last_name", OrderDetail.ObjBillingAddressInfo.LastName);
            objInf.Add("x_company", OrderDetail.ObjBillingAddressInfo.CompanyName);
            objInf.Add("x_email", OrderDetail.ObjBillingAddressInfo.EmailAddress);
            objInf.Add("x_address", OrderDetail.ObjBillingAddressInfo.Address);
            objInf.Add("x_city", OrderDetail.ObjBillingAddressInfo.City);
            objInf.Add("x_state", OrderDetail.ObjBillingAddressInfo.State);
            objInf.Add("x_zip", OrderDetail.ObjBillingAddressInfo.Zip);
            objInf.Add("x_country", OrderDetail.ObjBillingAddressInfo.Country);
            objInf.Add("x_phone", OrderDetail.ObjBillingAddressInfo.Phone);
            objInf.Add("x_fax", OrderDetail.ObjBillingAddressInfo.Fax);
            objInf.Add("x_email_customer", OrderDetail.ObjOrderDetails.IsEmailCustomer);

            if (OrderDetail.ObjOrderDetails.IsMultipleCheckOut == false)
            {
                //shipping address
                objInf.Add("x_ship_to_first_name", OrderDetail.ObjShippingAddressInfo.FirstName);
                objInf.Add("x_ship_to_last_name", OrderDetail.ObjShippingAddressInfo.LastName);
                objInf.Add("x_ship_to_company", OrderDetail.ObjShippingAddressInfo.CompanyName);
                objInf.Add("x_ship_to_address", OrderDetail.ObjShippingAddressInfo.Address);
                objInf.Add("x_ship_to_city", OrderDetail.ObjShippingAddressInfo.City);
                objInf.Add("x_ship_to_state", OrderDetail.ObjShippingAddressInfo.State);
                objInf.Add("x_ship_to_zip", OrderDetail.ObjShippingAddressInfo.Zip);
                objInf.Add("x_ship_to_country", OrderDetail.ObjShippingAddressInfo.Country);
            }
            // Card Details
            objInf.Add("x_card_num", OrderDetail.ObjPaymentInfo.CardNumber);
            objInf.Add("x_card_type", OrderDetail.ObjPaymentInfo.CardType);
            objInf.Add("x_exp_date", OrderDetail.ObjPaymentInfo.ExpireDate);

            var ssc = new StoreSettingConfig();
            double rate;
            string mainCurrency = ssc.GetStoreSettingsByKey(StoreSetting.MainCurrency, OrderDetail.ObjCommonInfo.StoreID, OrderDetail.ObjCommonInfo.PortalID, OrderDetail.ObjCommonInfo.CultureName);
            const string gateWayCurrency = "USD";
            AspxCommonInfo aspxCommonObj = new AspxCommonInfo();
            aspxCommonObj.CustomerID = OrderDetail.ObjOrderDetails.CustomerID;
            aspxCommonObj.SessionCode = OrderDetail.ObjOrderDetails.SessionCode;
            aspxCommonObj.StoreID = OrderDetail.ObjCommonInfo.StoreID;
            aspxCommonObj.PortalID = OrderDetail.ObjCommonInfo.PortalID;

            if (gateWayCurrency.ToLower().Trim() == mainCurrency.ToLower().Trim())
            {
                rate = 1;
            }
            else
            {
                AspxCoreController acc = new AspxCoreController();
                rate = acc.GetCurrencyRateOnChange(aspxCommonObj, mainCurrency, gateWayCurrency.Trim(), "en-US");
            }
            //double amountTotal = double.Parse(HttpContext.Current.Session["GrandTotalAll"].ToString()) * rate;
            double amountTotal = double.Parse( CheckOutSessions.Get<Double>("GrandTotalAll", 0).ToString()) * rate;
            decimal amount = decimal.Parse(amountTotal.ToString(CultureInfo.InvariantCulture));

            //string amount = Regex.Replace(OrderDetail.ObjOrderDetails.GrandTotal.ToString("0.00"), @"[A-Z]", String.Empty);
            objInf.Add("x_amount", Math.Round(amount, 2).ToString(CultureInfo.InvariantCulture));
            objInf.Add("x_test_request", "False");
            if (OrderDetail.ObjPaymentInfo.PaymentMethodCode == "CC")
            {
                // Authorization code of the card (CCV)
                objInf.Add("x_card_code", OrderDetail.ObjPaymentInfo.CardCode.Trim());
                objInf.Add("x_method", OrderDetail.ObjPaymentInfo.PaymentMethodCode.Trim());
                objInf.Add("x_type", OrderDetail.ObjPaymentInfo.TransactionType.Trim());
                // string amount = Regex.Replace(OrderDetail.ObjOrderDetails.GrandTotal.ToString("0.00"), @"[A-Z]", String.Empty);
                // objInf.Add("x_amount", amount);
                objInf.Add("x_description", OrderDetail.ObjOrderDetails.Remarks.Trim());

            }
            else
            {
                //bank 
                objInf.Add("x_bank_aba_code", OrderDetail.ObjPaymentInfo.RoutingNumber.Trim());
                objInf.Add("x_bank_acct_num", OrderDetail.ObjPaymentInfo.AccountNumber.Trim());
                objInf.Add("x_bank_acct_type", OrderDetail.ObjPaymentInfo.AccountType.Trim());
                objInf.Add("x_bank_name", OrderDetail.ObjPaymentInfo.BankName.Trim());
                objInf.Add("x_bank_acct_name", OrderDetail.ObjPaymentInfo.AccountHolderName.Trim());
                objInf.Add("x_echeck_type", OrderDetail.ObjPaymentInfo.ChequeType.Trim());
                objInf.Add("x_bank_check_number", OrderDetail.ObjPaymentInfo.ChequeNumber.Trim());
            }

            // Currency setting. Check the guide for other supported currencies
            objInf.Add("x_currency_code", OrderDetail.ObjOrderDetails.CurrencyCode.Trim());

            if (OrderDetail.ObjOrderDetails.IsTest.ToLower().Trim() == "true" || OrderDetail.ObjOrderDetails.IsTest.ToLower() == "1")
            {
                objRequest.BaseAddress = "https://test.authorize.net/gateway/transact.dll";
            }
            else
            {
                objRequest.BaseAddress = "https://secure.authorize.net/gateway/transact.dll";
            }

            try
            {
                // POST request

                byte[] objRetBytes = objRequest.UploadValues(objRequest.BaseAddress, "POST", objInf);
                string[] objRetVals = System.Text.Encoding.ASCII.GetString(objRetBytes).Split(",".ToCharArray());

                // Process Return Values
                OrderDetail.ObjOrderDetails.ResponseCode = int.Parse(objRetVals[0].Trim(char.Parse("|")));
                OrderDetail.ObjOrderDetails.ResponseReasonCode = int.Parse(objRetVals[2].Trim(char.Parse("|")));

                if (objRetVals[0].Trim(char.Parse("|")) == "1")
                {
                    // Returned Authorisation Code
                    //response.AuthorizationCode = objRetVals[4].Trim(char.Parse("|"));
                    // Returned Transaction ID
                    OrderDetail.ObjOrderDetails.TransactionID = Convert.ToString(objRetVals[6].Trim(char.Parse("|")));
                    strError = "Transaction completed successfully.";

                    AspxCoreController acc = new AspxCoreController();
                    OrderDetail.ObjOrderDetails.OrderStatusID = 8;
                    OrderDetail.ObjOrderDetails.TransactionID = Convert.ToString(objRetVals[6].Trim(char.Parse("|")));
                    acc.AddOrderDetails(OrderDetail);
                    HttpContext.Current.Session["TransDetailsAIM"] = OrderDetail.ObjOrderDetails.InvoiceNumber + "#" + OrderDetail.ObjOrderDetails.TransactionID + "#" + "AIM Authorize.Net";
                    if (HttpContext.Current.Session["OrderCollection"] != null)
                    {
                      
                        OrderDetailsCollection orderdata2 = new OrderDetailsCollection();
                        if (HttpContext.Current.Session["OrderCollection"] != null)
                        {
                            orderdata2 = (OrderDetailsCollection)HttpContext.Current.Session["OrderCollection"];

                        }

                        AspxOrderController.UpdateItemQuantity(orderdata2);
                        AspxGiftCardController.IssueGiftCard(orderdata2.LstOrderItemsInfo, orderdata2.ObjOrderDetails.OrderID, true, aspxCommonObj);
                        if (orderdata2.GiftCardDetail != null && HttpContext.Current.Session["UsedGiftCard"] != null)
                        {   //updating giftcard used in chekout
                            AspxGiftCardController.UpdateGiftCardUsage(orderdata2.GiftCardDetail, orderdata2.ObjCommonInfo.StoreID,
                                                 orderdata2.ObjCommonInfo.PortalID, orderdata2.ObjOrderDetails.OrderID, orderdata2.ObjCommonInfo.AddedBy,
                                                 orderdata2.ObjCommonInfo.CultureName);
                            HttpContext.Current.Session.Remove("UsedGiftCard");
                        }


                        var tinfo = new TransactionLogInfo();
                        var tlog = new TransactionLog();

                        tinfo.TransactionID = OrderDetail.ObjOrderDetails.TransactionID;
                        tinfo.AuthCode = objRetVals[4].Trim(char.Parse("|"));//auth Code
                        tinfo.TotalAmount = OrderDetail.ObjOrderDetails.GrandTotal;
                        tinfo.ResponseCode = "1";
                        tinfo.ResponseReasonText = strError;
                        tinfo.OrderID = orderdata2.ObjOrderDetails.OrderID;
                        tinfo.StoreID = OrderDetail.ObjCommonInfo.StoreID;
                        tinfo.PortalID = OrderDetail.ObjCommonInfo.PortalID;
                        tinfo.AddedBy = OrderDetail.ObjCommonInfo.AddedBy;
                        tinfo.CustomerID = OrderDetail.ObjOrderDetails.CustomerID;
                        tinfo.SessionCode = OrderDetail.ObjOrderDetails.SessionCode;
                        tinfo.PaymentGatewayID = OrderDetail.ObjOrderDetails.PaymentGatewayTypeID;
                        tinfo.PaymentStatus = "Processed";
                        tinfo.PayerEmail = OrderDetail.ObjBillingAddressInfo.EmailAddress;
                        tinfo.CreditCard = OrderDetail.ObjPaymentInfo.CardNumber;
                        tinfo.CurrencyCode = gateWayCurrency.Trim();
                        tlog.SaveTransactionLog(tinfo);
                    }

                    var cms = new AspxCommerce.Core.CartManageSQLProvider();
                    cms.ClearCartAfterPayment(aspxCommonObj);

                    // StoreSettingConfig ssc = new StoreSettingConfig();
                    string sendEmailFrom = ssc.GetStoreSettingsByKey(StoreSetting.SendEcommerceEmailsFrom, OrderDetail.ObjCommonInfo.StoreID, OrderDetail.ObjCommonInfo.PortalID, OrderDetail.ObjCommonInfo.CultureName);
                    string sendOrderNotice = ssc.GetStoreSettingsByKey(StoreSetting.SendOrderNotification, OrderDetail.ObjCommonInfo.StoreID, OrderDetail.ObjCommonInfo.PortalID, OrderDetail.ObjCommonInfo.CultureName);

                 

                    if (sendOrderNotice.ToLower() == "true")
                    {
                        try
                        {
                            EmailTemplate.SendEmailForOrder(OrderDetail.ObjCommonInfo.PortalID, OrderDetail, addressPath,
                                                            TemplateName, OrderDetail.ObjOrderDetails.TransactionID);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    acc.ClearSessionVariable("OrderCollection");
                    CheckOutHelper cHelper = new CheckOutHelper();
                    cHelper.ClearSessions();
                }
                else
                {
                    // Error!
                    strError = objRetVals[3].Trim(char.Parse("|")) + " (" +
                               objRetVals[2].Trim(char.Parse("|")) + ")";

                    if (objRetVals[2].Trim(char.Parse("|")) == "44")
                    {
                        // CCV transaction decline
                        strError += "Our Card Code Verification (CCV) returned " +
                                    "the following error: ";

                        switch (objRetVals[38].Trim(char.Parse("|")))
                        {
                            case "N":
                                strError += "Card Code does not match.";
                                break;
                            case "P":
                                strError += "Card Code was not processed.";
                                break;
                            case "S":
                                strError += "Card Code should be on card but was not indicated.";
                                break;
                            case "U":
                                strError += "Issuer was not certified for Card Code.";
                                break;
                        }
                    }

                    if (objRetVals[2].Trim(char.Parse("|")) == "45")
                    {
                        if (strError.Length > 1)
                            strError += "<br />n";

                        // AVS transaction decline
                        strError += "Our Address Verification System (AVS) " +
                                    "returned the following error: ";

                        switch (objRetVals[5].Trim(char.Parse("|")))
                        {
                            case "A":
                                strError += " the zip code entered does not match " +
                                            "the billing address.";
                                break;
                            case "B":
                                strError += " no information was provided for the AVS check.";
                                break;
                            case "E":
                                strError += " a general error occurred in the AVS system.";
                                break;
                            case "G":
                                strError += " the credit card was issued by a non-US bank.";
                                break;
                            case "N":
                                strError += " neither the entered street address nor zip " +
                                            "code matches the billing address.";
                                break;
                            case "P":
                                strError += " AVS is not applicable for this transaction.";
                                break;
                            case "R":
                                strError += " please retry the transaction; the AVS system " +
                                            "was unavailable or timed out.";
                                break;
                            case "S":
                                strError += " the AVS service is not supported by your " +
                                            "credit card issuer.";
                                break;
                            case "U":
                                strError += " address information is unavailable for the " +
                                            "credit card.";
                                break;
                            case "W":
                                strError += " the 9 digit zip code matches, but the " +
                                            "street address does not.";
                                break;
                            case "Z":
                                strError += " the zip code matches, but the address does not.";
                                break;
                        }
                    }
                    var tinfo = new TransactionLogInfo();
                    var tlog = new TransactionLog();

                    tinfo.TransactionID = "";
                    tinfo.AuthCode = objRetVals[4].Trim(char.Parse("|"));//auth Code
                    tinfo.TotalAmount = amount;
                    tinfo.ResponseCode = objRetVals[2].Trim(char.Parse("|"));
                    tinfo.ResponseReasonText = strError;
                    tinfo.OrderID = OrderDetail.ObjOrderDetails.OrderID;
                    tinfo.StoreID = OrderDetail.ObjCommonInfo.StoreID;
                    tinfo.PortalID = OrderDetail.ObjCommonInfo.PortalID;
                    tinfo.AddedBy = OrderDetail.ObjCommonInfo.AddedBy;
                    tinfo.CustomerID = OrderDetail.ObjOrderDetails.CustomerID;
                    tinfo.SessionCode = OrderDetail.ObjOrderDetails.SessionCode;
                    tinfo.PaymentGatewayID = OrderDetail.ObjOrderDetails.PaymentGatewayTypeID;
                    tinfo.PaymentStatus = "Failed";
                    tinfo.PayerEmail = OrderDetail.ObjBillingAddressInfo.EmailAddress;
                    tinfo.CreditCard = OrderDetail.ObjPaymentInfo.CardNumber;
                    tinfo.CurrencyCode = gateWayCurrency.Trim();
                    tlog.SaveTransactionLog(tinfo);
                }
            }
            catch (Exception ex)
            {
                strError = ex.Message;
            }
            OrderDetail.ObjOrderDetails.ResponseReasonText = strError;
            return OrderDetail.ObjOrderDetails.ResponseReasonText;
        }