Ejemplo n.º 1
0
        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;
            }
        }