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 void GetUserShippingAddress(int shippingAddressId)
    {
        try
        {
            var parameter = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("@ShippingAddressId", shippingAddressId) };
            var sqlH = new SQLHandler();
            _userShippingAddresInfo = sqlH.ExecuteAsObject<UserAddressInfo>("usp_Aspx_mb_GetShippingAddressByAddressId",
                                                                           parameter);

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
        public static void SendEmailForOrderMobile(OrderInfo orderInfo, UserAddressInfo billingAddress,
                                                   UserAddressInfo shippingAddress, string addressPath,
                                                   string templateName, string transID)
        {
            StoreSettingConfig ssc = new StoreSettingConfig();
            SageFrameConfig pagebase = new SageFrameConfig();
            string sendOrderNotice = ssc.GetStoreSettingsByKey(StoreSetting.SendOrderNotification, orderInfo.StoreId,
                                                               orderInfo.PortalId, orderInfo.CultureName);
            string logosrc = ssc.GetStoreSettingsByKey(StoreSetting.StoreLogoURL, orderInfo.StoreId, orderInfo.PortalId,
                                                       orderInfo.CultureName);
            string inquiry = ssc.GetStoreSettingsByKey(StoreSetting.SendEcommerceEmailsFrom, orderInfo.StoreId,
                                                       orderInfo.PortalId, orderInfo.CultureName);
            string storeName = ssc.GetStoreSettingsByKey(StoreSetting.StoreName, orderInfo.StoreId, orderInfo.PortalId,
                                                         orderInfo.CultureName);

            if (bool.Parse(sendOrderNotice))
            {
                List<MessageManagementInfo> template =
                    MessageManagementController.GetMessageTemplateByMessageTemplateTypeID(
                        SystemSetting.ORDER_PLACED, orderInfo.PortalId);
                foreach (MessageManagementInfo messageToken in template)
                {

                    string messageTemplate = messageToken.Body;
                    if (template != null)
                    {
                        string[] tokens = GetAllToken(messageTemplate);
                        foreach (string token in tokens)
                        {
                            switch (token)
                            {
                                case "%OrderRemarks%":
                                    messageTemplate = messageTemplate.Replace(token, orderInfo.Remarks);
                                    break;
                                case "%InvoiceNo%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              orderInfo.InvoiceNumber);
                                    break;
                                case "%OrderID%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              orderInfo.OrderId.ToString());
                                    break;
                                case "%BillingAddress%":
                                    string billing = billingAddress.FirstName + " " +
                                                     billingAddress.LastName +
                                                     "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";

                                    if (billingAddress.CompanyName != null)
                                    {
                                        billing += billingAddress.CompanyName +
                                                   "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";
                                    }

                                    billing += billingAddress.City + ", " +
                                               billingAddress.Address +
                                               "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">" +
                                               billingAddress.Country +
                                               "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">" +
                                               billingAddress.EmailAddress +
                                               "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">" +
                                               billingAddress.Phone;
                                    messageTemplate = messageTemplate.Replace(token, billing);
                                    break;
                                case "%ShippingAddress%":
                                    string shipping = "";
                                    if (!orderInfo.IsDownloadable || shippingAddress != null)
                                    {
                                        if (orderInfo.IsMultipleCheckOut == false)
                                        {
                                            shipping = shippingAddress.FirstName + " " +
                                                       shippingAddress.LastName +
                                                       "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";
                                            if (shippingAddress.CompanyName != null)
                                            {
                                                shipping += shippingAddress.CompanyName +
                                                            "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";
                                            }

                                            shipping += shippingAddress.City + ", " +
                                                        shippingAddress.Address +
                                                        "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">" +
                                                        shippingAddress.Country +
                                                        "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">" +
                                                        shippingAddress.EmailAddress +
                                                        "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">" +
                                                        shippingAddress.Phone +
                                                        "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";

                                        }
                                        else
                                        {
                                            shipping = "Multiple addresses<br />Plese log in to view." +
                                                       "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";
                                        }

                                    }
                                    else
                                    {
                                        shipping = "Your Ordered Item is Downloadable Item." +
                                                   "</td></tr><tr><td height=\"32\" style=\"border-bottom:thin dashed #d1d1d1; padding:10px 0 5px 10px; font:normal 12px Arial, Helvetica, sans-serif\">";
                                    }

                                    messageTemplate = messageTemplate.Replace(token, shipping);
                                    break;
                                case "%UserFirstName%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              billingAddress.FirstName);
                                    break;
                                case "%UserLastName%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              billingAddress.LastName);
                                    break;
                                case "%TransactionID%":
                                    messageTemplate = messageTemplate.Replace(token, transID);
                                    break;
                                case "%PaymentMethodName%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              orderInfo.PaymentMethodName);
                                    break;
                                case "%DateTimeDay%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              DateTime.Now.ToString("dddd, dd MMMM yyyy"));
                                    break;
                                case "%DateYear%":
                                    messageTemplate = messageTemplate.Replace(token, DateTime.Now.Year.ToString());
                                    break;
                                case "%CustomerID%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              orderInfo.CustomerId.ToString());
                                    break;
                                case "%PhoneNo%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              billingAddress.Phone);
                                    break;
                                case "%AccountLogin%":
                                    string account = "";
                                    if (orderInfo.AddedBy.ToLower() == "anonymoususer" &&
                                        orderInfo.CustomerId == 0)
                                    {
                                        // future login process for annoymoususr 
                                        account +=
                                            "Please Register and log in to your ";

                                        account += "<a  style=\"color: rgb(39, 142, 230);\"  href=" + addressPath +
                                                   "User-Registration.aspx" + ">account</a>";
                                    }
                                    else
                                    {
                                        account +=
                                            "  Please log in to your ";

                                        account += " <a style=\"color: rgb(39, 142, 230);\"  href=" + addressPath +
                                                   "Login.aspx" + ">account</a>";
                                    }
                                    messageTemplate = messageTemplate.Replace(token, account);
                                    break;
                                case "%LogoSource%":
                                    // string src = " http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + "/Templates/" + templateName + "/images/aspxcommerce.png";
                                    string src = " http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] +
                                                 "/" + logosrc;
                                    messageTemplate = messageTemplate.Replace(token, src);
                                    break;
                                case "%DateTime%":
                                    messageTemplate = messageTemplate.Replace(token,
                                                                              DateTime.Now.ToString("dd MMMM yyyy "));

                                    break;
                                case "%InquiryEmail%":
                                    string x =
                                        "<a  target=\"_blank\" style=\"text-decoration: none;color: #226ab7;font-style: italic;\" href=\"mailto:" +
                                        inquiry + "\" >" + inquiry + "</a>";
                                    messageTemplate = messageTemplate.Replace(token, x);
                                    break;
                                case "%StoreName%":
                                    messageTemplate = messageTemplate.Replace(token, storeName);
                                    break;
                            }
                        }
                        // return messageTemplate;
                        string emailStoreAdmin = ssc.GetStoreSettingsByKey(StoreSetting.SendEcommerceEmailsFrom,
                                                                           orderInfo.StoreId, orderInfo.PortalId
                                                                           , orderInfo.CultureName);
                        string emailSuperAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SuperUserEmail);
                        string emailSiteAdmin = pagebase.GetSettingsByKey(SageFrameSettingKeys.SiteAdminEmailAddress);
                        MailHelper.SendMailNoAttachment(emailStoreAdmin, billingAddress.EmailAddress,
                                                        messageToken.Subject
                                                        , messageTemplate, emailSiteAdmin, emailSuperAdmin);

                    }
                }
            }
        }