internal static void InitStackTraceOn()
 {
     if (!mTraceInitialized)
     {
         try
         {
             String StackTraceOn;
             StackTraceOn = PayflowUtility.AppSettings(PayflowConstants.TRACE_TAG);
             if (0 == String.Compare(PayflowConstants.TRACE_ON, StackTraceOn, true))
             {
                 PayflowConstants.TRACE = PayflowConstants.TRACE_ON;
             }
         }
         catch
         {
             PayflowConstants.TRACE = PayflowConstants.TRACE_DEFAULT;
         }
     }
     mTraceInitialized = true;
 }
Example #2
0
        /// <summary>
        /// Validates the parameter list.
        /// </summary>
        /// <param name="ParamList">Parameter List</param>
        /// <param name="IsXmlPayReq">true if Request is XmlPay, false otherwise.</param>
        /// <param name="CurrentContext">Context object by reference.</param>
        public static void Validate(String ParamList, bool IsXmlPayReq, ref Context CurrentContext)
        {
            Logger.Instance.Log("PayPal.Payments.Common.Utility.ParameterListValidator.Validate(String,bool,String,String,ref Context): Entered", PayflowConstants.SEVERITY_DEBUG);
            try
            {
                if (IsXmlPayReq)
                {
                    XmlDocument XmlPayReq = new XmlDocument();
                    XmlPayReq.LoadXml(ParamList);
                }
                else
                {
                    if (ParamList != null && ParamList.Length > 0)
                    {
                        ParseNVPList(ParamList, ref CurrentContext, false);
                    }
                }
            }
            catch (Exception Ex)
            {
                ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_INVALID_NVP, Ex, PayflowConstants.SEVERITY_FATAL, IsXmlPayReq, null);
                if (!CurrentContext.IsCommunicationErrorContained(Err))
                {
                    CurrentContext.AddError(Err);
                }
            }
            //catch
            //{
            //    ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_INVALID_NVP, null, PayflowConstants.SEVERITY_FATAL, IsXmlPayReq, null);
            //    if (!CurrentContext.IsCommunicationErrorContained(Err))
            //    {
            //        CurrentContext.AddError(Err);
            //    }

            //}
            finally
            {
                Logger.Instance.Log("PayPal.Payments.Common.Utility.ParameterListValidator.Validate(String,bool,String,String,ref Context): Exiting", PayflowConstants.SEVERITY_DEBUG);
            }
        }
        /// <summary>
        /// Masks the NVP request
        /// </summary>
        /// <param name="ParmList">Param List to be masked</param>
        /// <returns>Masked Param List</returns>
        internal static String MaskNVPRequest(String ParmList)
        {
            String LogParmList = ParmList;

            //Mask ACCT if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_ACCT, true);
            //Mask EXPDATE if present
            //LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_EXPDATE, true);
            //Mask SWIPE if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_SWIPE, true);
            //Mask MICR if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_MICR, true);
            //Mask CVV2 if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_CVV2, true);
            //Mask PWD
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_PWD, true);
            //Mask DL if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_DL, true);
            //Mask SS if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_SS, true);
            //Mask DOB if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_DOB, true);
            //Mask MAGTEKPWD if present
            LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.MAGTEK_PARAM_MAGTEKPWD, true);
            //Mask VIT_OSNAME if present
            //LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_VIT_OSNAME, true);
            //Mask VIT_OSARCH if present
            //LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_VIT_OSARCH, true);
            //Mask VIT_OSVERSION if present
            //LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_VIT_OSVERSION, true);
            //Mask VIT_SDKRUNTIMEVERSION if present
            //LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_VIT_SDKRUNTIMEVERSION, true);
            //Mask VIT_PROXY if present
            //LogParmList = PayflowUtility.LocateValueForName(LogParmList, PayflowConstants.PARAM_VIT_PROXY, true);
            return(LogParmList);
        }
        /// <summary>
        /// Masks XMLPay Request
        /// </summary>
        /// <param name="ParmList">XMLPay request to be masked</param>
        /// <returns>Masked XMLPay Request</returns>
        internal static String MaskXMLPayRequest(String ParmList)
        {
            String RetVal;

            try
            {
                XmlDocument XmlPayRequest = new XmlDocument();
                XmlPayRequest.LoadXml(ParmList);
                //Mask ACCT if present : Corresponding XmlPay element --> AcctNum or CardNum
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_ACCTNUM);
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_CARDNUM);
                //Mask EXPDATE if present : Corresponding XmlPay element --> ExpDate
                //PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_EXPDATE);
                //Mask SWIPE if present : Corresponding XmlPay element --> MagData
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_MAGDATA);
                //Mask MICR if present : Corresponding XmlPay element --> MICR or MagData
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_MICR);
                //Mask CVV2 if present : Corresponding XmlPay element --> CVNum
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_CVNUM);
                //Mask PWD if present : Corresponding XmlPay element --> Password
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_PASSWORD);
                //Mask DL if present : Corresponding XmlPay element --> DL
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_DL);
                //Mask SS if present : Corresponding XmlPay element --> CVNum
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_SS);
                //Mask DOB if present : Corresponding XmlPay element --> DOB
                PayflowUtility.MaskXmlNodeValue(ref XmlPayRequest, PayflowConstants.XML_PARAM_DOB);

                RetVal = XmlPayRequest.InnerXml;
            }
            catch
            {
                RetVal = ParmList;
            }
            return(RetVal);
        }
Example #5
0
        /// <summary>
        /// Validates Name Value Pair Request.
        /// </summary>
        /// <param name="ParamList">Name Value Param List.</param>
        /// <param name="CurrentContext">Context object by reference.</param>
        /// <param name="PopulateResponseHashTable">True will populate the return hashtable, false will just parse the request and check for validity</param>
        /// <returns>Name value hash table</returns>
        public static Hashtable ParseNVPList(String ParamList, ref Context CurrentContext, bool PopulateResponseHashTable)
        {
            Logger.Instance.Log("PayPal.Payments.Common.Utility.ParameterListValidator.ParseNVPList(String,String,String,ref context,bool): Entered", PayflowConstants.SEVERITY_DEBUG);
            long        ParamListLen = ParamList.Length;
            int         index        = 0;
            bool        OpenBracket  = false;
            bool        CloseBracket = false;
            String      AddlMessage;
            ErrorObject Err;
            Hashtable   ParamListHashTable = new Hashtable();

            if (ParamList == null || ParamList.Length <= 0)
            {
                Err = PayflowUtility.PopulateCommError(PayflowConstants.E_EMPTY_PARAM_LIST, null, PayflowConstants.SEVERITY_FATAL, false, null);
                CurrentContext.AddError(Err);
            }

            while (index < ParamListLen && CurrentContext.HighestErrorLvl < PayflowConstants.SEVERITY_FATAL)
            {
                long   NameBuffSize   = 1000;
                long   ValBuffSize    = 1000;
                long   LenBuffSize    = 1000;
                char[] NameBuffer     = new char[NameBuffSize];
                char[] LenValueBuffer = new char[LenBuffSize];
                char[] ValueBuffer    = new char[ValBuffSize];
                char[] TempArray      = null;
                int    LenIndex       = 0;
                int    NameIndex      = 0;

                while (index < ParamListLen && ParamList[index] != '\0' && ParamList[index] != '=')
                {
                    if (ParamList[index] == '[')
                    {
                        if (OpenBracket)
                        {
                            AddlMessage = "Found unmatched '[' followed by another '[' at index  " + (index + 1).ToString();
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                            break;
                        }
                        OpenBracket = true;
                        index++;
                        continue;
                    }
                    if (ParamList[index] == ']')
                    {
                        if (!OpenBracket)
                        {
                            AddlMessage = "Unmatched ']' at index " + (index + 1).ToString();
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                            break;
                        }
                        else if ((index + 1) < ParamListLen && ParamList[index + 1] != '=')
                        {
                            AddlMessage = "']' is not followed by '=' in param list at index " + (index + 1).ToString();
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                            break;
                        }
                        else if ((index + 1) < ParamListLen && ParamList[index - 1] == '[')
                        {
                            AddlMessage = "Length of value not found in '[]' at index " + (index + 1).ToString();
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                            break;
                        }
                        else
                        {
                            if (CloseBracket)
                            {
                                AddlMessage = "Found unmatched ']' followed by another ']' at index  " + (index + 1).ToString();
                                Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                                if (!CurrentContext.IsCommunicationErrorContained(Err))
                                {
                                    CurrentContext.AddError(Err);
                                }
                                break;
                            }
                            index++;
                            CloseBracket = true;
                            continue;
                        }
                    }

                    if (OpenBracket && !CloseBracket)
                    {
                        //increase the size of LenValueBuffer if required
                        if (LenIndex >= LenBuffSize)
                        {
                            LenBuffSize += 2000;
                            TempArray    = new char[LenBuffSize];
                            System.Array.Copy(LenValueBuffer, TempArray, LenValueBuffer.LongLength);
                            LenValueBuffer = TempArray;
                        }
                        LenValueBuffer[LenIndex] = ParamList[index];
                        LenIndex++;
                        index++;
                        continue;
                    }
                    else
                    {
                        //increase the size of NameBuffer if required
                        if (NameIndex >= NameBuffSize)
                        {
                            NameBuffSize += 2000;
                            TempArray     = new char[NameBuffSize];
                            System.Array.Copy(NameBuffer, TempArray, NameBuffer.LongLength);
                            NameBuffer = TempArray;
                        }
                        NameBuffer[NameIndex] = ParamList[index];
                        if (NameBuffer[NameIndex] == '&')
                        {
                            AddlMessage = new string(NameBuffer);
                            AddlMessage = AddlMessage.Trim('\0');
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                        }
                        index++;
                        NameIndex++;
                        continue;
                    }
                }
                //skip '='
                if (index < ParamListLen && ParamList[index] != '\0')
                {
                    index++;
                }

                if (OpenBracket && !CloseBracket)
                {
                    AddlMessage = "Unmatched '[' at index " + (index + 1).ToString();
                    Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                    if (!CurrentContext.IsCommunicationErrorContained(Err))
                    {
                        CurrentContext.AddError(Err);
                    }
                    break;
                }

                /*if(OpenBracket && CloseBracket && LenValueBuffer != null && LenValueBuffer.Length > 0 && LenValueBuffer[0] == '0')
                 * {
                 *      String Len = new string(LenValueBuffer).Trim('\0');
                 *      AddlMessage = "Invalid param length = " + Len;
                 *      Err =  PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN,null,PayflowConstants.SEVERITY_FATAL,false,AddlMessage);
                 *      if(!CurrentContext.IsCommunicationErrorContained(Err))
                 *      {
                 *              CurrentContext.AddError(Err);
                 *      }
                 *      break;
                 *
                 * }*/

                if (OpenBracket && CloseBracket && LenValueBuffer != null && LenValueBuffer.Length > 0 && LenValueBuffer[0] == '-')
                {
                    String Len = new string(LenValueBuffer).Trim('\0');
                    AddlMessage = "Invalid param length = " + Len;
                    Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                    if (!CurrentContext.IsCommunicationErrorContained(Err))
                    {
                        CurrentContext.AddError(Err);
                    }
                    break;
                }

                int ValIndex = 0;
                while (index < ParamListLen && ParamList[index] != '\0' && CurrentContext.HighestErrorLvl < PayflowConstants.SEVERITY_FATAL)
                {
                    if (LenValueBuffer != null && LenValueBuffer.Length > 0 && LenValueBuffer[0] != '\0')
                    {
                        String LenString = new String(LenValueBuffer);
                        LenString = LenString.Trim();
                        int Len;
                        try
                        {
                            Len = Int32.Parse(LenString);
                        }
                        catch (Exception Ex)
                        {
                            String Name = new string(NameBuffer).Trim('\0');
                            AddlMessage = "Value in [] is not numeric data, data in '[]' =  " + LenString.Trim('\0') + "for Name = " + Name;
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, Ex, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                            break;
                        }
                        //catch
                        //{
                        //    String Name = new string(NameBuffer).Trim('\0');
                        //    AddlMessage = "Value in [] is not numeric data, data in '[]' =  " + LenString.Trim('\0') + "for Name = " + Name;
                        //    Err = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                        //    if (!CurrentContext.IsCommunicationErrorContained(Err))
                        //    {
                        //        CurrentContext.AddError(Err);
                        //    }
                        //    break;
                        //}

                        int AmpIndex = index + Len;
                        if (AmpIndex < ParamListLen && ParamList[AmpIndex] != '&')
                        {
                            String Name = new string(NameBuffer).Trim('\0');
                            AddlMessage = "Param length in '[]' does not match actual value length.Param Name = " + Name;
                            Err         = PayflowUtility.PopulateCommError(PayflowConstants.E_PARM_NAME_LEN, null, PayflowConstants.SEVERITY_FATAL, false, AddlMessage);
                            if (!CurrentContext.IsCommunicationErrorContained(Err))
                            {
                                CurrentContext.AddError(Err);
                            }
                            index += Len + 1;
                            break;
                        }
                        else
                        {
                            //increase the size of ValueBuffer if required
                            if (Len >= ValBuffSize)
                            {
                                ValBuffSize += Len + 2000;
                                ValueBuffer  = new char[ValBuffSize];
                            }
                            int ValueIndex;
                            for (ValueIndex = 0; ValueIndex < Len && index + ValueIndex < ParamListLen; ValueIndex++)
                            {
                                ValueBuffer[ValueIndex] = ParamList[index + ValueIndex];
                            }
                            index += Len + 1;
                            break;
                        }
                    }
                    else
                    {
                        //increase the size of NameBuffer if required
                        if (ValIndex >= ValBuffSize)
                        {
                            ValBuffSize += 2000;
                            TempArray    = new char[ValBuffSize];
                            System.Array.Copy(ValueBuffer, TempArray, ValueBuffer.LongLength);
                            ValueBuffer = TempArray;
                        }
                        if (ParamList[index] == '&')
                        {
                            if ((index + 1) < ParamListLen && ParamList[index + 1] == '&')
                            {
                                ValueBuffer[ValIndex] = ParamList[index];
                            }
                            else if (ParamList[index - 1] == '&')
                            {
                                ValueBuffer[ValIndex] = ParamList[index];
                            }
                            else
                            {
                                index++;
                                ValIndex++;
                                break;
                            }
                        }
                        else
                        {
                            ValueBuffer[ValIndex] = ParamList[index];
                        }
                    }
                    index++;
                    ValIndex++;
                }

                //put data in hash table as name - value
                if (PopulateResponseHashTable)
                {
                    String Name  = new String(NameBuffer).Trim('\0');
                    String Value = new String(ValueBuffer).Trim('\0');
                    if (ParamListHashTable.Contains(Name))
                    {
                        Name = Name + PayflowConstants.TAG_DUPLICATE + PayflowUtility.RequestId;
                    }

                    ParamListHashTable.Add(Name, Value);
                }

                OpenBracket    = false;
                CloseBracket   = false;
                NameBuffer     = null;
                LenValueBuffer = null;
                ValueBuffer    = null;
                TempArray      = null;
            }
            Logger.Instance.Log("PayPal.Payments.Common.Utility.ParameterListValidator.ParseNVPList(String,String,String,ref context,bool): Exiting", PayflowConstants.SEVERITY_DEBUG);
            return(ParamListHashTable);
        }
        internal static ArrayList AlignContext(Context Context, bool IsXmlPayRequest)
        {
            ArrayList Errors     = Context.GetErrors();
            ArrayList RetVal     = new ArrayList();
            int       ErrorCount = Errors.Count;
            int       Index;

            for (Index = 0; Index < ErrorCount; Index++)
            {
                ErrorObject Error       = (ErrorObject)Errors[Index];
                String      MessageCode = Error.MessageCode;
                if (Error != null)
                {
                    if (MessageCode != null && MessageCode.Length > 0)
                    {
                        bool Msg1012 = false;
                        bool Msg1013 = false;
                        bool Msg1015 = false;
                        bool Msg1016 = false;

                        if ("MSG_1012".Equals(MessageCode))
                        {
                            Msg1012 = true;
                        }
                        else if ("MSG_1013".Equals(MessageCode))
                        {
                            Msg1013 = true;
                        }
                        else if ("MSG_1015".Equals(MessageCode))
                        {
                            Msg1015 = true;
                        }
                        else if ("MSG_1016".Equals(MessageCode))
                        {
                            Msg1016 = true;
                        }

                        if (IsXmlPayRequest)
                        {
                            if (Msg1013 || Msg1016)
                            {
                                RetVal.Add(Error);
                            }
                            else
                            {
                                ErrorObject NewError = null;
                                try
                                {
                                    if (Msg1012)
                                    {
                                        ArrayList MsgParams    = Error.MessageParams;
                                        String[]  NewMsgParams = new String[] { (String)MsgParams[0],
                                                                                (String)MsgParams[1] };
                                        NewError = new ErrorObject(Error.SeverityLevel, "MSG_1013", NewMsgParams, Error.ErrorStackTrace);
                                    }
                                    else if (Msg1015)
                                    {
                                        ArrayList MsgParams    = Error.MessageParams;
                                        String[]  NewMsgParams = new String[] { (String)MsgParams[0],
                                                                                (String)MsgParams[1] };
                                        NewError = new ErrorObject(Error.SeverityLevel, "MSG_1016", NewMsgParams, Error.ErrorStackTrace);
                                    }
                                    else
                                    {
                                        String ErrMessage = Error.ToString();
                                        NewError = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, null, Error.SeverityLevel, true, ErrMessage);
                                    }
                                }
                                catch
                                {
                                    NewError = null;
                                }

                                if (NewError != null)
                                {
                                    RetVal.Add(NewError);
                                }
                            }
                        }
                        else
                        {
                            if (Msg1012 || Msg1015)
                            {
                                RetVal.Add(Error);
                            }
                            else
                            {
                                ErrorObject NewError = null;
                                try
                                {
                                    if (Msg1013)
                                    {
                                        ArrayList MsgParams    = Error.MessageParams;
                                        String[]  NewMsgParams = new String[] { (String)MsgParams[2],
                                                                                (String)MsgParams[3] };
                                        NewError = new ErrorObject(Error.SeverityLevel, "MSG_1012", NewMsgParams, Error.ErrorStackTrace);
                                    }
                                    else if (Msg1016)
                                    {
                                        ArrayList MsgParams    = Error.MessageParams;
                                        String[]  NewMsgParams = new String[] { (String)MsgParams[1],
                                                                                (String)MsgParams[2] };
                                        NewError = new ErrorObject(Error.SeverityLevel, "MSG_1015", NewMsgParams, Error.ErrorStackTrace);
                                    }
                                    else
                                    {
                                        String ErrMessage = Error.ToString();
                                        NewError = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, null, Error.SeverityLevel, false, ErrMessage);
                                    }
                                }
                                catch
                                {
                                    NewError = null;
                                }

                                if (NewError != null)
                                {
                                    RetVal.Add(NewError);
                                }
                            }
                        }
                    }
                    else
                    {
                        ErrorObject NewError = null;
                        try
                        {
                            String ErrMessage = Error.ToString();
                            if (ErrMessage != null && ErrMessage.Length > 0)
                            {
                                String Result      = PayflowConstants.EMPTY_STRING;
                                String RespMsg     = PayflowConstants.EMPTY_STRING;
                                bool   ErrIsXmlPay = (ErrMessage.IndexOf(PayflowConstants.XML_RESP_ID) >= 0);
                                //Check whether the error string is in nvp format
                                // or xml pay format.
                                if (ErrIsXmlPay)
                                {
                                    //Try to get values in nodes Result, RespMsg
                                    Result  = PayflowUtility.GetXmlPayNodeValue(ErrMessage, PayflowConstants.XML_PARAM_RESULT);
                                    RespMsg = PayflowUtility.GetXmlPayNodeValue(ErrMessage, PayflowConstants.XML_PARAM_MESSAGE);
                                }
                                else
                                {
                                    //Try to get RESULT , RESPMSG from the error if
                                    // available.
                                    Result  = PayflowUtility.LocateValueForName(ErrMessage, PayflowConstants.PARAM_RESULT, false);
                                    RespMsg = PayflowUtility.LocateValueForName(ErrMessage, PayflowConstants.PARAM_RESPMSG, false);
                                }

                                if (Result != null && Result.Length > 0 && RespMsg != null && RespMsg.Length > 0)
                                {
                                    StringBuilder NewErrMessage = new StringBuilder("");
                                    if (IsXmlPayRequest && !ErrIsXmlPay)
                                    {
                                        NewErrMessage = new StringBuilder("<XMLPayResponse xmlns='http://www.paypal.com/XMLPay'");

                                        NewErrMessage.Append("><ResponseData><TransactionResults><TransactionResult><Result>");
                                        NewErrMessage.Append(Result);
                                        NewErrMessage.Append("</Result><Message>");
                                        NewErrMessage.Append(RespMsg);
                                        NewErrMessage.Append("</Message></TransactionResult></TransactionResults></ResponseData></XMLPayResponse>");
                                        NewError = new ErrorObject(Error.SeverityLevel, "", NewErrMessage.ToString());
                                    }
                                    else if (!IsXmlPayRequest && ErrIsXmlPay)
                                    {
                                        NewErrMessage = new StringBuilder(PayflowConstants.PARAM_RESULT);
                                        NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP);
                                        NewErrMessage.Append(Result);
                                        NewErrMessage.Append(PayflowConstants.DELIMITER_NVP);
                                        NewErrMessage.Append(PayflowConstants.PARAM_RESPMSG);
                                        NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP);
                                        NewErrMessage.Append(RespMsg);

                                        NewError = new ErrorObject(Error.SeverityLevel, "", NewErrMessage.ToString());
                                    }
                                    else
                                    {
                                        NewError = new ErrorObject(Error.SeverityLevel, "", ErrMessage);
                                    }
                                }
                                else
                                {
                                    StringBuilder NewErrMessage = new StringBuilder("");
                                    if (IsXmlPayRequest)
                                    {
                                        NewErrMessage = new StringBuilder("<XMLPayResponse xmlns='http://www.paypal.com/XMLPay'");

                                        NewErrMessage.Append("><ResponseData><TransactionResults><TransactionResult><Result>");
                                        NewErrMessage.Append((String)PayflowConstants.CommErrorCodes[PayflowConstants.E_UNKNOWN_STATE]);
                                        NewErrMessage.Append("</Result><Message>");
                                        NewErrMessage.Append((String)PayflowConstants.CommErrorMessages[PayflowConstants.E_UNKNOWN_STATE] + " " + ErrMessage);
                                        NewErrMessage.Append("</Message></TransactionResult></TransactionResults></ResponseData></XMLPayResponse>");
                                    }
                                    else
                                    {
                                        NewErrMessage = new StringBuilder(PayflowConstants.PARAM_RESULT);
                                        NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP);
                                        NewErrMessage.Append((String)PayflowConstants.CommErrorCodes[PayflowConstants.E_UNKNOWN_STATE]);
                                        NewErrMessage.Append(PayflowConstants.DELIMITER_NVP);
                                        NewErrMessage.Append(PayflowConstants.PARAM_RESPMSG);
                                        NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP);
                                        NewErrMessage.Append((String)PayflowConstants.CommErrorMessages[PayflowConstants.E_UNKNOWN_STATE] + " " + ErrMessage);
                                    }

                                    NewError = new ErrorObject(Error.SeverityLevel, "", NewErrMessage.ToString());
                                }
                            }
                        }
                        catch
                        {
                            NewError = null;
                        }

                        if (NewError != null)
                        {
                            RetVal.Add(NewError);
                        }
                    }
                }
            }

            return(RetVal);
        }