/// <summary> /// Constructor /// </summary> /// <param name="connection">PaymentConnection Object</param> /// <param name="paramList">Parameter List</param> /// <param name="psmContext">Context Object by ref</param> /// <remarks>This is an abstract class, creating an object of PaymentState directly is not possible.</remarks> public PaymentState(PaymentConnection connection, string paramList, ref Context psmContext) : this() { Logger.Instance.Log( "PayPal.Payments.Communication.PaymentState.PaymentState(PaymentConnection,String,Context): Entered.", PayflowConstants.SeverityDebug); CommContext = psmContext; Connection = connection; InitializeContentType(paramList); if (CommContext.HighestErrorLvl < PayflowConstants.SeverityFatal) { Connection.ContentType = _mContentType; if (paramList == null || paramList.Length == 0) { var err = PayflowUtility.PopulateCommError(PayflowConstants.EEmptyParamList, null, PayflowConstants.SeverityFatal, IsXmlPayRequest, null); CommContext.AddError(err); } TransactionRequest = paramList; ValidateRequestId(); } Logger.Instance.Log( "PayPal.Payments.Communication.PaymentState.PaymentState(PaymentConnection,String,Context): Exiting.", PayflowConstants.SeverityDebug); }
/// <summary> /// Constructor /// </summary> /// <param name="Connection">PaymentConnection Object</param> /// <param name="ParamList">Parameter List</param> /// <param name="PsmContext">Context Object by ref</param> /// <remarks>This is an abstract class, creating an object of PaymentState directly is not possible.</remarks> public PaymentState(PaymentConnection Connection, String ParamList, ref Context PsmContext) : this() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentState.PaymentState(PaymentConnection,String,Context): Entered.", PayflowConstants.SEVERITY_DEBUG); mContext = PsmContext; mConnection = Connection; InitializeContentType(ParamList); if (mContext.HighestErrorLvl < PayflowConstants.SEVERITY_FATAL) { mConnection.ContentType = mContentType; if (ParamList == null || ParamList.Length == 0) { ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_EMPTY_PARAM_LIST, null, PayflowConstants.SEVERITY_FATAL, IsXmlPayRequest, null); mContext.AddError(Err); } this.mTransactionRequest = ParamList; ValidateRequestId(); } Logger.Instance.Log("PayPal.Payments.Communication.PaymentState.PaymentState(PaymentConnection,String,Context): Exiting.", PayflowConstants.SEVERITY_DEBUG); }
/// <summary> /// Initialized Transaction. /// </summary> /// <param name="ParamList">Parameter List</param> /// <param name="RequestId">Request Id</param> public void InitTrans(String ParamList, String RequestId) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.InitTrans(String): Entered.", PayflowConstants.SEVERITY_DEBUG); try { this.mConnection.RequestId = RequestId; this.mPaymentState = new SendInitState(this.mConnection, ParamList, ref psmContext); } catch (Exception Ex) { ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_CONTXT_INIT_FAILED, Ex, PayflowConstants.SEVERITY_ERROR, mPaymentState.IsXmlPayRequest, null); if (!PsmContext.IsCommunicationErrorContained(Err)) { PsmContext.AddError(Err); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.InitTrans(String): Exiting.", PayflowConstants.SEVERITY_DEBUG); } }
/// <summary> /// Initializes Connection Host Attributes. /// </summary> /// <param name="hostAddress">String Value of Host Address.</param> /// <param name="hostPort">Host port as positive integer.</param> /// <param name="timeOut">Connection Timeout in Seconds.</param> private void InitializeHost(string hostAddress, int hostPort, int timeOut) { Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): Entered.", PayflowConstants.SeverityDebug); if (hostAddress != null && hostAddress.Length > 0) { _mHostAddress = hostAddress; Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): HostAddress = " + _mHostAddress, PayflowConstants.SeverityInfo); } else { var nullHostError = PayflowUtility.PopulateCommError(PayflowConstants.ENullHostString, null, PayflowConstants.SeverityFatal, IsXmlPayRequest, null); if (!ConnContext.IsCommunicationErrorContained(nullHostError)) { ConnContext.AddError(nullHostError); } } _mHostPort = hostPort; Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): HostPort = " + _mHostPort, PayflowConstants.SeverityInfo); TimeOut = timeOut; Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): Exiting.", PayflowConstants.SeverityDebug); }
/// <summary> /// Initializes transaction context. /// </summary> /// <param name="HostAddress">Payflow Host Address.</param> /// <param name="HostPort">Payflow Host Port.</param> /// <param name="TimeOut">Transaction timeout.</param> /// <param name="ProxyAddress">Proxy Address.</param> /// <param name="ProxyPort">Proxy Port.</param> /// <param name="ProxyLogon">Proxy Logon Id.</param> /// <param name="ProxyPassword">Proxy Password.</param> /// <param name="ClientInfo">Client Info</param> public void InitializeContext(String HostAddress, int HostPort, int TimeOut, String ProxyAddress, int ProxyPort, String ProxyLogon, String ProxyPassword, ClientInfo ClientInfo) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.InitializeContext(String, int, int, String, int, String, String): Entered.", PayflowConstants.SEVERITY_DEBUG); try { this.mConnection.InitializeConnection(HostAddress, HostPort, TimeOut, ProxyAddress, ProxyPort, ProxyLogon, ProxyPassword); if (ClientInfo != null) { mClientInfo = ClientInfo; } else { mClientInfo = new ClientInfo(); } this.SetVersionTracking(); this.mConnection.ClientInfo = mClientInfo; } catch (Exception Ex) { ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_EMPTY_PARAM_LIST, Ex, PayflowConstants.SEVERITY_ERROR, mPaymentState.IsXmlPayRequest, null); if (!PsmContext.IsCommunicationErrorContained(Err)) { PsmContext.AddError(Err); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.InitializeContext(String,int,int,String, nt,String,String): Exiting.", PayflowConstants.SEVERITY_DEBUG); } }
/// <summary> /// Initializes Connection Host Attributes. /// </summary> /// <param name="HostAddress">String Value of Host Address.</param> /// <param name="HostPort">Host port as positive integer.</param> /// <param name="TimeOut">Connection Timeout in Seconds.</param> private void InitializeHost(String HostAddress, int HostPort, int TimeOut) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): Entered.", PayflowConstants.SEVERITY_DEBUG); if (HostAddress != null && HostAddress.Length > 0) { mHostAddress = HostAddress; Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): HostAddress = " + mHostAddress, PayflowConstants.SEVERITY_INFO); } else { ErrorObject NullHostError = PayflowUtility.PopulateCommError(PayflowConstants.E_NULL_HOST_STRING, null, PayflowConstants.SEVERITY_FATAL, IsXmlPayRequest, null); if (!ConnContext.IsCommunicationErrorContained(NullHostError)) { ConnContext.AddError(NullHostError); } } mHostPort = HostPort; Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): HostPort = " + mHostPort.ToString(), PayflowConstants.SEVERITY_INFO); mConnectionTimeOut = TimeOut; Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitializeHost(String,int,int): Exiting.", PayflowConstants.SEVERITY_DEBUG); }
/// <summary> /// Sets the appropriate server file path for the connection /// and initializes the connection uri. /// </summary> public override void Execute() { bool IsConnected = false; Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Entered.", PayflowConstants.SEVERITY_DEBUG); if (!InProgress) { return; } try { Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Initializing Connection.", PayflowConstants.SEVERITY_INFO); //Begin Payflow Timeout Check Point 2 long TimeRemainingMsec; bool TimedOut = PayflowUtility.IsTimedOut(mConnection.TimeOut, mConnection.StartTime, out TimeRemainingMsec); if (TimedOut) { String AddlMessage = "Input timeout value in millisec : " + Connection.TimeOut.ToString(); ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_TIMEOUT_WAIT_RESP, null, PayflowConstants.SEVERITY_FATAL, IsXmlPayRequest, AddlMessage); if (!CommContext.IsCommunicationErrorContained(Err)) { CommContext.AddError(Err); } } else { mConnection.TimeOut = TimeRemainingMsec; } //End Payflow Timeout Check Point 2 IsConnected = mConnection.ConnectToServer(); } catch (Exception Ex) { Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Error occurred While Initializing Connection.", PayflowConstants.SEVERITY_ERROR); Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Exception " + Ex.ToString(), PayflowConstants.SEVERITY_ERROR); IsConnected = false; } //catch //{ // IsConnected = false; //} finally { if (IsConnected) { Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Connection Initialization = Success", PayflowConstants.SEVERITY_INFO); SetStateSuccess(); } else { Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Initialized Connection = Failure", PayflowConstants.SEVERITY_INFO); SetStateFail(); } } Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Exiting.", PayflowConstants.SEVERITY_DEBUG); }
/// <summary> /// Receives the transaction response from /// the server. /// </summary> /// <returns>String Value of Response.</returns> public async Task <string> ReceiveResponseAsync() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Entered.", PayflowConstants.SeverityDebug); var response = PayflowConstants.EmptyString; try { var serverResponse = await _mServerConnection.GetResponseAsync(); var responseStream = serverResponse.GetResponseStream(); RequestId = serverResponse.Headers.Get(PayflowConstants.PayflowheaderRequestId); Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Obtained RequestId = " + RequestId, PayflowConstants.SeverityInfo); // v4.3.1 - changed stream handling due to issue with code below not returning a complete // stream.//read the stream in bytes //long RespLen = ServerResponse.ContentLength ; //Byte[] RespByteBuffer = new byte[RespLen]; //ResponseStream.Read (RespByteBuffer,0,Convert.ToInt32 (RespLen)); //UTF8Encoding UtfEncoding = new UTF8Encoding (); //Response = UtfEncoding.GetString(RespByteBuffer); response = await new StreamReader(serverResponse.GetResponseStream()).ReadToEndAsync(); Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Obtained Response.", PayflowConstants.SeverityInfo); responseStream.Close(); _mServerConnection = null; } catch (Exception ex) { var addlMessage = "Input Server Uri = " + _mServerUri.AbsoluteUri; if (IsProxy) { addlMessage += " Input Proxy info = " + _mProxyInfo.Address; } var initError = PayflowUtility.PopulateCommError(PayflowConstants.ETimeoutWaitResp, ex, PayflowConstants.SeverityError, IsXmlPayRequest, addlMessage); if (!ConnContext.IsCommunicationErrorContained(initError)) { ConnContext.AddError(initError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Exiting.", PayflowConstants.SeverityDebug); } return(response); }
/// <summary> /// Receives the transaction response from /// the server. /// </summary> /// <returns>String Value of Response.</returns> public String ReceiveResponse() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Entered.", PayflowConstants.SEVERITY_DEBUG); String Response = PayflowConstants.EMPTY_STRING; try { HttpWebResponse ServerResponse = (HttpWebResponse)mServerConnection.GetResponse(); Stream ResponseStream = ServerResponse.GetResponseStream(); mRequestId = ServerResponse.Headers.Get(PayflowConstants.PAYFLOWHEADER_REQUEST_ID); Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Obtained RequestId = " + mRequestId, PayflowConstants.SEVERITY_INFO); // v4.3.1 - changed stream handling due to issue with code below not returning a complete // stream.//read the stream in bytes //long RespLen = ServerResponse.ContentLength ; //Byte[] RespByteBuffer = new byte[RespLen]; //ResponseStream.Read (RespByteBuffer,0,Convert.ToInt32 (RespLen)); //UTF8Encoding UtfEncoding = new UTF8Encoding (); //Response = UtfEncoding.GetString(RespByteBuffer); Response = new StreamReader(ServerResponse.GetResponseStream()).ReadToEnd(); Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Obtained Response.", PayflowConstants.SEVERITY_INFO); ResponseStream.Close(); mServerConnection = null; } catch (Exception Ex) { String AddlMessage = "Input Server Uri = " + mServerUri.AbsoluteUri; if (IsProxy) { AddlMessage += " Input Proxy info = " + mProxyInfo.Address.ToString(); } ErrorObject InitError = PayflowUtility.PopulateCommError(PayflowConstants.E_TIMEOUT_WAIT_RESP, Ex, PayflowConstants.SEVERITY_ERROR, IsXmlPayRequest, AddlMessage); if (!ConnContext.IsCommunicationErrorContained(InitError)) { ConnContext.AddError(InitError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ReceiveResponse(): Exiting.", PayflowConstants.SEVERITY_DEBUG); } return(Response); }
/// <summary> /// Executes the transaction. /// </summary> public void Execute() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.Execute(): Entered.", PayflowConstants.SEVERITY_DEBUG); try { if (PsmContext.HighestErrorLvl == PayflowConstants.SEVERITY_FATAL) { String TrxResponse = mPaymentState.TransactionResponse; String Message; if (TrxResponse != null && TrxResponse.Length > 0) { Message = TrxResponse; } else { ArrayList ErrorList = psmContext.GetErrors(PayflowConstants.SEVERITY_FATAL); ErrorObject FirstFatalError = (ErrorObject)ErrorList[0]; Message = FirstFatalError.ToString(); } mPaymentState.SetTransactionFail = Message; } else { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.Execute(): Current State = " + mPaymentState, PayflowConstants.SEVERITY_DEBUG); mPaymentState.Execute(); } } catch (Exception Ex) { ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, Ex, PayflowConstants.SEVERITY_ERROR, mPaymentState.IsXmlPayRequest, null); if (!PsmContext.IsCommunicationErrorContained(Err)) { PsmContext.AddError(Err); } } finally { // perform state transition mPaymentState = GetNextState(mPaymentState); mClientInfo = mConnection.ClientInfo; Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.Execute(): Exiting. Current State = " + mPaymentState.GetType().ToString(), PayflowConstants.SEVERITY_DEBUG); } }
/// <summary> /// Initialized the Server Uri object from /// available connection attributes. /// </summary> private void InitServerUri() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitServerUri(String): Entered.", PayflowConstants.SeverityDebug); var serverUriBuilder = new UriBuilder(); try { serverUriBuilder.Host = _mHostAddress; serverUriBuilder.Scheme = "https"; serverUriBuilder.Port = _mHostPort; _mServerUri = serverUriBuilder.Uri; } catch (Exception ex) { var addlMessage = "Input Server Uri = " + serverUriBuilder.Scheme + "://" + serverUriBuilder.Host + ":" + serverUriBuilder.Port; if (ex is UriFormatException && IsProxy) { addlMessage += " Input Proxy info = http://" + _mProxyAddress; _mProxyStatus = false; } else if (IsProxy) { addlMessage += " Input Proxy info = " + _mProxyInfo.Address; } var initError = PayflowUtility.PopulateCommError(PayflowConstants.ESokConnFailed, ex, PayflowConstants.SeverityError, IsXmlPayRequest, addlMessage); if (!ConnContext.IsCommunicationErrorContained(initError)) { ConnContext.AddError(initError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitServerUri(String): Exiting.", PayflowConstants.SeverityDebug); } }
/// <summary> /// Validates Request Id. /// </summary> /// <returns>True if valid, false otherwise.</returns> private bool ValidateRequestId() { var retValue = false; if (!HaveRequestId) { var err = PayflowUtility.PopulateCommError(PayflowConstants.EMissingRequestId, null, PayflowConstants.SeverityFatal, IsXmlPayRequest, null); if (!CommContext.IsCommunicationErrorContained(err)) { CommContext.AddError(err); } } else { retValue = true; } return(retValue); }
/// <summary> /// Validates Request Id. /// </summary> /// <returns>True if valid, false otherwise.</returns> private bool ValidateRequestId() { bool RetValue = false; if (!HaveRequestId) { ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_MISSING_REQUEST_ID, null, PayflowConstants.SEVERITY_FATAL, IsXmlPayRequest, null); if (!mContext.IsCommunicationErrorContained(Err)) { CommContext.AddError(Err); } } else { RetValue = true; } return(RetValue); }
/// <summary> /// Initialized the Server Uri object from /// available connection attributes. /// </summary> private void InitServerUri() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitServerUri(String): Entered.", PayflowConstants.SEVERITY_DEBUG); UriBuilder ServerUriBuilder = new UriBuilder(); try { ServerUriBuilder.Host = mHostAddress; ServerUriBuilder.Scheme = "https"; ServerUriBuilder.Port = mHostPort; mServerUri = ServerUriBuilder.Uri; } catch (Exception Ex) { String AddlMessage = "Input Server Uri = " + ServerUriBuilder.Scheme + "://" + ServerUriBuilder.Host + ":" + ServerUriBuilder.Port; if (Ex is System.UriFormatException && IsProxy) { AddlMessage += " Input Proxy info = http://" + mProxyAddress; mProxyStatus = false; } else if (IsProxy) { AddlMessage += " Input Proxy info = " + mProxyInfo.Address.ToString(); } ErrorObject InitError = PayflowUtility.PopulateCommError(PayflowConstants.E_SOK_CONN_FAILED, Ex, PayflowConstants.SEVERITY_ERROR, IsXmlPayRequest, AddlMessage); if (!ConnContext.IsCommunicationErrorContained(InitError)) { ConnContext.AddError(InitError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.InitServerUri(String): Exiting.", PayflowConstants.SEVERITY_DEBUG); } }
/// <summary> /// Sets the appropriate server file path for the connection /// and initializes the connection uri. /// </summary> public override Task ExecuteAsync() { var isConnected = false; Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Entered.", PayflowConstants.SeverityDebug); if (!InProgress) { return(Task.CompletedTask); } try { Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Initializing Connection.", PayflowConstants.SeverityInfo); //Begin Payflow Timeout Check Point 2 long timeRemainingMsec; var timedOut = PayflowUtility.IsTimedOut(Connection.TimeOut, Connection.StartTime, out timeRemainingMsec); if (timedOut) { var addlMessage = "Input timeout value in millisec : " + Connection.TimeOut; var err = PayflowUtility.PopulateCommError(PayflowConstants.ETimeoutWaitResp, null, PayflowConstants.SeverityFatal, IsXmlPayRequest, addlMessage); if (!CommContext.IsCommunicationErrorContained(err)) { CommContext.AddError(err); } } else { Connection.TimeOut = timeRemainingMsec; } //End Payflow Timeout Check Point 2 isConnected = Connection.ConnectToServer(); } catch (Exception ex) { Logger.Instance.Log( "PayPal.Payments.Communication.InitState.Execute(): Error occurred While Initializing Connection.", PayflowConstants.SeverityError); Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Exception " + ex, PayflowConstants.SeverityError); isConnected = false; } //catch //{ // IsConnected = false; //} finally { if (isConnected) { Logger.Instance.Log( "PayPal.Payments.Communication.InitState.Execute(): Connection Initialization = Success", PayflowConstants.SeverityInfo); SetStateSuccess(); } else { Logger.Instance.Log( "PayPal.Payments.Communication.InitState.Execute(): Initialized Connection = Failure", PayflowConstants.SeverityInfo); SetStateFail(); } } Logger.Instance.Log("PayPal.Payments.Communication.InitState.Execute(): Exiting.", PayflowConstants.SeverityDebug); return(Task.CompletedTask); }
/// <summary> /// Initializes all the connection attributes and creates the connection. /// </summary> private void CreateConnection() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.CreateConnection(): Entered.", PayflowConstants.SEVERITY_DEBUG); try { //Create Connection Object. // 03/06/2017 Added TLS 1.2 support for .NET 4.5 support. Only TLS 1.2 is supported going forward. System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // | SecurityProtocolType.Tls11; mServerConnection = (HttpWebRequest)WebRequest.Create(mServerUri); // Create a new request to the above mentioned URL. // WebRequest mServerConnection = WebRequest.Create(mServerUri); //Set Connection Properties mServerConnection.Method = "POST"; mServerConnection.KeepAlive = false; mServerConnection.UserAgent = PayflowConstants.USER_AGENT; mServerConnection.ContentType = mContentType; mServerConnection.Timeout = (int)mConnectionTimeOut; // Add request id in the header. mServerConnection.Headers.Add(PayflowConstants.PAYFLOWHEADER_REQUEST_ID, mRequestId); long TimeOut = mConnectionTimeOut / 1000; mServerConnection.Headers.Add(PayflowConstants.PAYFLOWHEADER_TIMEOUT, TimeOut.ToString()); if (IsProxy) { if (mProxyInfo == null) { InitProxyInfo(); } //mServerConnection.Proxy = mProxyInfo; } else { // added 09/02/2009, v4.33 // reference: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.proxy.aspx // sets the the global proxy to an empty proxy. // mServerConnection.Proxy = GlobalProxySelection.GetEmptyWebProxy(); // GlobalProxySelection is deprecated, replaced with WebRequest.DefaultWebProxy v4.50 0-3/15/2016 WebRequest.DefaultWebProxy = null; mServerConnection.Proxy = WebRequest.DefaultWebProxy; } //Add VIT Headers if (mClientInfo != null) { //Get the Hash map. Hashtable ClientInfoHash = mClientInfo.ClientInfoHash; if (ClientInfoHash != null && ClientInfoHash.Count > 0) { //Iterate through the hash map to add the //appropriate headers. foreach (DictionaryEntry HeaderKeyValue in ClientInfoHash) { Object ValueObj = HeaderKeyValue.Value; if (ValueObj != null) { ClientInfoHeader CurrHeader = (ClientInfoHeader)ValueObj; String HdrName = CurrHeader.HeaderName; Object HdrValueObj = CurrHeader.HeaderValue; String HdrValueStr = null; //Check if Header name is non-null, non-empty string. bool ValidHeaderName = (HdrName != null && HdrName.Length > 0); bool ValidHeaderValue = (HdrValueObj != null); //Check if Header value object is non-null, object. if (ValidHeaderValue) { HdrValueStr = CurrHeader.HeaderValue.ToString(); //Check if the header value is non-null, non-empty. ValidHeaderValue = (HdrValueStr != null && HdrValueStr.Length > 0); } //If all conditions are satisfied, then add header to request. if (ValidHeaderName && ValidHeaderValue) { try { mServerConnection.Headers.Add(HdrName, HdrValueStr); } catch (Exception Ex) { string AddlMessage = "Invalid Client(Wrapper) Header: " + HdrName; ErrorObject HeaderError = PayflowUtility.PopulateCommError(PayflowConstants.MESSAGE_WRAPPERHEADER_ERROR, Ex, PayflowConstants.SEVERITY_WARN, IsXmlPayRequest, AddlMessage); if (!ConnContext.IsCommunicationErrorContained(HeaderError)) { ConnContext.AddError(HeaderError); } } } } } } } //Added VIT Headers to the http request. } catch (Exception Ex) { String AddlMessage = "Input Server Uri = " + mServerUri.AbsoluteUri; if (Ex is System.UriFormatException && IsProxy) { AddlMessage += " Input Proxy info = http://" + mProxyAddress; mProxyStatus = false; } else if (IsProxy) { AddlMessage += " Input Proxy info = " + mProxyInfo.Address.ToString(); } ErrorObject InitError = PayflowUtility.PopulateCommError(PayflowConstants.E_SOK_CONN_FAILED, Ex, PayflowConstants.SEVERITY_ERROR, IsXmlPayRequest, AddlMessage); if (!ConnContext.IsCommunicationErrorContained(InitError)) { ConnContext.AddError(InitError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.CreateConnection(): Exiting.", PayflowConstants.SEVERITY_DEBUG); } }
/// <summary> /// Sends the request to the server. /// </summary> /// <param name="request">String Value of request.</param> /// <returns>True if success, False otherwise.</returns> public async Task <bool> SendToServer(string request) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.SendToServer(String): Entered.", PayflowConstants.SeverityDebug); var retVal = false; // Uncomment this line to test this SDK in QA. This will override the certificate check where the // host URL does not match the server certificate causing the exception: // // "The underlying connection was closed: Could not establish trust relationship with remote server." // // See notes in LocalPolicy.cs in the Utility directory. // //System.Net.ServicePointManager.CertificatePolicy = new LocalPolicy(ref mContext,IsXmlPayRequest); try { var encoding = new ASCIIEncoding(); if (request != null) { var paramListBytes = encoding.GetBytes(request); _mServerConnection.ContentLength = paramListBytes.Length; var reqStram = _mServerConnection.GetRequestStream(); await reqStram.WriteAsync(paramListBytes, 0, paramListBytes.Length); reqStram.Close(); retVal = true; var headerKeys = _mServerConnection.Headers.AllKeys; if (headerKeys != null) { var keysLen = headerKeys.GetLength(0); int index; Logger.Instance.Log("++++++++++++++++++++++", PayflowConstants.SeverityDebug); for (index = 0; index < keysLen; index++) { //if (!(HeaderKeys[index].Equals(PayflowConstants.PAYFLOWHEADER_CLIENT_VERSION))) // || HeaderKeys[index].Equals(PayflowConstants.PAYFLOWHEADER_CLIENT_TYPE))) //{ Logger.Instance.Log( "HTTP Header: " + headerKeys[index] + ": " + _mServerConnection.Headers.Get(headerKeys[index]), PayflowConstants.SeverityDebug); } //} Logger.Instance.Log("++++++++++++++++++++++", PayflowConstants.SeverityDebug); } } else { var initError = PayflowUtility.PopulateCommError(PayflowConstants.EEmptyParamList, null, PayflowConstants.SeverityError, IsXmlPayRequest, null); if (!ConnContext.IsCommunicationErrorContained(initError)) { ConnContext.AddError(initError); } } } catch (Exception ex) { var addlMessage = "Input Server Uri = " + _mServerUri.AbsoluteUri; if (IsProxy) { addlMessage += " Input Proxy info = " + _mProxyInfo.Address; } var initError = PayflowUtility.PopulateCommError(PayflowConstants.ESokConnFailed, ex, PayflowConstants.SeverityError, IsXmlPayRequest, addlMessage); if (!ConnContext.IsCommunicationErrorContained(initError)) { ConnContext.AddError(initError); } Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.SendToServer(String): InitError: ", PayflowConstants.SeverityDebug); } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.SendToServer(String): Exiting.", PayflowConstants.SeverityDebug); } return(retVal); }
/// <summary> /// Initializes the Server Connection. /// </summary> /// <returns>True if success, False otherwise.</returns> public bool ConnectToServer() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Entered.", PayflowConstants.SeverityDebug); var retVal = false; try { //Initialize Server Uri. Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Initializing Server Uri.", PayflowConstants.SeverityInfo); InitServerUri(); Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Initialized Server Uri = " + _mServerUri.AbsoluteUri, PayflowConstants.SeverityInfo); //Create Connection object & Set Connection Attributes Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Initializing Connection Attributes.", PayflowConstants.SeverityInfo); CreateConnection(); if (_mServerConnection != null) { if (_mProxyStatus) { retVal = true; Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Connection Created.", PayflowConstants.SeverityInfo); } else { retVal = false; Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Connection Creation Failure: Incorrect Proxy Details.", PayflowConstants.SeverityInfo); } } else { retVal = false; Logger.Instance.Log( "PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Connection Creation Failure.", PayflowConstants.SeverityInfo); } } catch (Exception ex) { var addlMessage = "Input Server Uri = " + _mServerUri.AbsoluteUri; if (IsProxy) { addlMessage += " Input Proxy info = " + _mProxyInfo.Address; } var initError = PayflowUtility.PopulateCommError(PayflowConstants.ESokConnFailed, ex, PayflowConstants.SeverityError, IsXmlPayRequest, addlMessage); if (!ConnContext.IsCommunicationErrorContained(initError)) { ConnContext.AddError(initError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Exiting.", PayflowConstants.SeverityDebug); } return(retVal); }
/// <summary> /// Initializes all the connection attributes and creates the connection. /// </summary> private void CreateConnection() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.CreateConnection(): Entered.", PayflowConstants.SeverityDebug); try { //Create Connection Object. _mServerConnection = (HttpWebRequest)WebRequest.Create(_mServerUri); // Create a new request to the above mentioned URL. // WebRequest mServerConnection = WebRequest.Create(mServerUri); //Set Connection Properties _mServerConnection.Method = "POST"; _mServerConnection.KeepAlive = false; _mServerConnection.UserAgent = PayflowConstants.UserAgent; _mServerConnection.ContentType = ContentType; _mServerConnection.Timeout = (int)TimeOut; // Add request id in the header. _mServerConnection.Headers.Add(PayflowConstants.PayflowheaderRequestId, RequestId); var timeOut = TimeOut / 1000; _mServerConnection.Headers.Add(PayflowConstants.PayflowheaderTimeout, timeOut.ToString()); if (IsProxy) { if (_mProxyInfo == null) { InitProxyInfo(); } //mServerConnection.Proxy = mProxyInfo; } else { _mServerConnection.Proxy = WebRequest.DefaultWebProxy; } //Add VIT Headers if (ClientInfo != null) { //Get the Hash map. var clientInfoHash = ClientInfo.ClientInfoHash; if (clientInfoHash != null && clientInfoHash.Count > 0) { foreach (DictionaryEntry headerKeyValue in clientInfoHash) { var valueObj = headerKeyValue.Value; if (valueObj != null) { var currHeader = (ClientInfoHeader)valueObj; var hdrName = currHeader.HeaderName; var hdrValueObj = currHeader.HeaderValue; string hdrValueStr = null; //Check if Header name is non-null, non-empty string. var validHeaderName = hdrName != null && hdrName.Length > 0; var validHeaderValue = hdrValueObj != null; //Check if Header value object is non-null, object. if (validHeaderValue) { hdrValueStr = currHeader.HeaderValue.ToString(); //Check if the header value is non-null, non-empty. validHeaderValue = hdrValueStr != null && hdrValueStr.Length > 0; } //If all conditions are satisfied, then add header to request. if (validHeaderName && validHeaderValue) { try { _mServerConnection.Headers.Add(hdrName, hdrValueStr); } catch (Exception ex) { var addlMessage = "Invalid Client(Wrapper) Header: " + hdrName; var headerError = PayflowUtility.PopulateCommError( PayflowConstants.MessageWrapperheaderError, ex, PayflowConstants.SeverityWarn, IsXmlPayRequest, addlMessage); if (!ConnContext.IsCommunicationErrorContained(headerError)) { ConnContext.AddError(headerError); } } } } } } } //Added VIT Headers to the http request. } catch (Exception ex) { var addlMessage = "Input Server Uri = " + _mServerUri.AbsoluteUri; if (ex is UriFormatException && IsProxy) { addlMessage += " Input Proxy info = http://" + _mProxyAddress; _mProxyStatus = false; } else if (IsProxy) { addlMessage += " Input Proxy info = " + _mProxyInfo.Address; } var initError = PayflowUtility.PopulateCommError(PayflowConstants.ESokConnFailed, ex, PayflowConstants.SeverityError, IsXmlPayRequest, addlMessage); if (!ConnContext.IsCommunicationErrorContained(initError)) { ConnContext.AddError(initError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.CreateConnection(): Exiting.", PayflowConstants.SeverityDebug); } }
/// <summary> /// Sets the response params /// </summary> /// <param name="Response">Response string</param> internal void SetParams(String Response) { try { mResponseString = Response; if (Response != null) { int ResultIndex = Response.IndexOf(PayflowConstants.PARAM_RESULT); if (ResultIndex >= 0) { if (ResultIndex > 0) { Response = Response.Substring(ResultIndex); } ParseResponse(Response); SetResultParams(ref mResponseHashTable); SetFraudResultParams(ref mResponseHashTable); SetBuyerAuthResultParams(ref mResponseHashTable); String TrxType = PayflowUtility.LocateValueForName(RequestString, PayflowConstants.PARAM_TRXTYPE, false); if (String.Equals(TrxType, PayflowConstants.TRXTYPE_RECURRING)) { SetRecurringResultParams(ref mResponseHashTable); } else { SetExpressCheckoutDOResultParams(ref mResponseHashTable); SetExpressCheckoutGETResultParams(ref mResponseHashTable); SetExpressCheckoutSETResultParams(ref mResponseHashTable); SetExpressCheckoutUPDATEResultParams(ref mResponseHashTable); } mResponseHashTable.Remove(PayflowConstants.INTL_PARAM_FULLRESPONSE); SetExtDataList(); mResponseHashTable = null; } else { //Append the RESULT and RESPMSG for error code //E_UNKNOWN_STATE and create a message. //Call SetParams again on it. String ResponseValue = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_UNKNOWN_STATE] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_UNKNOWN_STATE] + ", " + mResponseString; this.SetParams(ResponseValue); } } else { String AddlMessage = "Empty response"; ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_EMPTY_PARAM_LIST, null, PayflowConstants.SEVERITY_WARN, false, AddlMessage); mContext.AddError(Err); Err = mContext.GetError(mContext.getErrorCount() - 1); String ResponseValue = Err.ToString(); this.SetParams(ResponseValue); } } catch (BaseException BaseEx) { //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_ERROR,false, null); ErrorObject Error = BaseEx.GetFirstErrorInExceptionContext(); mContext.AddError(Error); String ResponseValue = Error.ToString(); this.SetParams(ResponseValue); } catch (Exception Ex) { DataObjectException DEx = new DataObjectException(Ex); ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, DEx, PayflowConstants.SEVERITY_ERROR, false, null); mContext.AddError(Error); String ResponseValue = Error.ToString(); this.SetParams(ResponseValue); } //catch //{ // ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,null,PayflowConstants.SEVERITY_ERROR,false,null); // mContext.AddError(Error); // String ResponseValue = Error.ToString(); // this.SetParams(ResponseValue); //} }
/// <summary> /// Sends the request to the server. /// </summary> /// <param name="Request">String Value of request.</param> /// <returns>True if success, False otherwise.</returns> public bool SendToServer(String Request) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.SendToServer(String): Entered.", PayflowConstants.SEVERITY_DEBUG); bool RetVal = false; // Uncomment this line to test this SDK in QA. This will override the certificate check where the // host URL does not match the server certificate causing the exception: // // "The underlying connection was closed: Could not establish trust relationship with remote server." // // See notes in LocalPolicy.cs in the Utility directory. // //System.Net.ServicePointManager.CertificatePolicy = new LocalPolicy(ref mContext,IsXmlPayRequest); try { ASCIIEncoding Encoding = new ASCIIEncoding(); if (Request != null) { Byte[] ParamListBytes = Encoding.GetBytes(Request); mServerConnection.ContentLength = ParamListBytes.Length; Stream ReqStram = mServerConnection.GetRequestStream(); ReqStram.Write(ParamListBytes, 0, ParamListBytes.Length); ReqStram.Close(); RetVal = true; String[] HeaderKeys = mServerConnection.Headers.AllKeys; if (HeaderKeys != null) { int KeysLen = HeaderKeys.GetLength(0); int index; Logger.Instance.Log("++++++++++++++++++++++", PayflowConstants.SEVERITY_DEBUG); for (index = 0; index < KeysLen; index++) { //if (!(HeaderKeys[index].Equals(PayflowConstants.PAYFLOWHEADER_CLIENT_VERSION))) // || HeaderKeys[index].Equals(PayflowConstants.PAYFLOWHEADER_CLIENT_TYPE))) //{ Logger.Instance.Log("HTTP Header: " + HeaderKeys[index] + ": " + mServerConnection.Headers.Get(HeaderKeys[index]), PayflowConstants.SEVERITY_DEBUG); //} } Logger.Instance.Log("++++++++++++++++++++++", PayflowConstants.SEVERITY_DEBUG); } } else { ErrorObject InitError = PayflowUtility.PopulateCommError(PayflowConstants.E_EMPTY_PARAM_LIST, null, PayflowConstants.SEVERITY_ERROR, IsXmlPayRequest, null); if (!ConnContext.IsCommunicationErrorContained(InitError)) { ConnContext.AddError(InitError); } } } catch (Exception Ex) { String AddlMessage = "Input Server Uri = " + mServerUri.AbsoluteUri; if (IsProxy) { AddlMessage += " Input Proxy info = " + mProxyInfo.Address.ToString(); } ErrorObject InitError = PayflowUtility.PopulateCommError(PayflowConstants.E_SOK_CONN_FAILED, Ex, PayflowConstants.SEVERITY_ERROR, IsXmlPayRequest, AddlMessage); if (!ConnContext.IsCommunicationErrorContained(InitError)) { ConnContext.AddError(InitError); } Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.SendToServer(String): InitError: ", PayflowConstants.SEVERITY_DEBUG); } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.SendToServer(String): Exiting.", PayflowConstants.SEVERITY_DEBUG); } return(RetVal); }
/// <summary> /// Overrides ToString /// </summary> /// <returns>String value of currency</returns> /// <remarks>Formats string value of currency in format "$.CC"</remarks> /// <example> /// <code lang="C#" escaped="false"> /// ............. /// //Inv is the Invoice object /// ............. /// /// //Set the invoice amount. /// Inv.Amt = new Currency(new Decimal(25.12),"USD"); /// String CurrValue = Inv.ToString(); /// ............. /// </code> /// <code lang="Visual Basic" escaped="false"> /// ............. /// 'Inv is the Invoice object /// ............. /// /// 'Set the invoice amount. /// Inv.Amt = New Currency(New Decimal(25.12),"USD") /// CurrValue As String = Inv.ToString /// ............. /// </code> /// </example> public override string ToString() { try { //Overridden ToString. Returns held Currency Value. String RetVal = PayflowConstants.EMPTY_STRING; // We need to double check here whether currency value // is non-zero positive before converting it. if (mNoOfDecimalDigits < 0) { mNoOfDecimalDigits = 2; } if (mRound && mTruncate) { ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_CURRENCY_PROCESS_ERROR, null, PayflowConstants.SEVERITY_FATAL, false, null); throw new DataObjectException(Err); } else if (mRound) { mCurrencyValue = decimal.Round(mCurrencyValue, mNoOfDecimalDigits); RetVal = RoundCurrencyValue(mCurrencyValue.ToString(), mNoOfDecimalDigits); //RetVal = mCurrencyValue.ToString("c", LocalFormat); } else if (mTruncate) { //RetVal = TruncateCurrencyValue(mCurrencyValue.ToString("c", LocalFormat),mNoOfDecimalDigits); RetVal = TruncateCurrencyValue(mCurrencyValue.ToString(), mNoOfDecimalDigits); } else { //RetVal = mCurrencyValue.ToString("c", LocalFormat); RetVal = mCurrencyValue.ToString(); } int IndexOfDecimal = RetVal.IndexOf(".", 1); if (IndexOfDecimal < 0 && mNoOfDecimalDigits != 0) { RetVal += ".00"; } string TempStr = RetVal.Substring(IndexOfDecimal + 1, RetVal.Length - IndexOfDecimal - 1); int Len = TempStr.Length; if (Len < 2) { for (int i = Len; i < 2; i++) { RetVal = RetVal + "0"; } } return(RetVal); } catch (BaseException) { throw; } catch (Exception Ex) { DataObjectException DEx = new DataObjectException(Ex); throw DEx; } //catch //{ // throw new Exception(); //} }
/// <summary> /// This method submits the transaction /// to the PayPal Payment Gateway. /// The response is obtained from the gateway /// and response object is populated with the /// response values along with the sdk specific /// errors in context, if any. /// </summary> /// <returns>Returns response object for Strong assembly transactions</returns> /// <example> /// <code lang="C#" escaped="false"> /// ............ /// //Trans is the transaction object. /// ............ /// /// //Submit the transaction. /// Trans.SubmitTransaction(); /// /// // Get the Response. /// Response Resp = Trans.Response; /// if (Resp != null) /// { /// // Get the Transaction Response parameters. /// TransactionResponse TrxnResponse = Resp.TransactionResponse; /// if (TrxnResponse != null) /// { /// Console.WriteLine("RESULT = " + TrxnResponse.Result); /// Console.WriteLine("PNREF = " + TrxnResponse.Pnref); /// Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg); /// Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode); /// Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr); /// Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip); /// Console.WriteLine("IAVS = " + TrxnResponse.IAVS); /// } /// // Get the Fraud Response parameters. /// FraudResponse FraudResp = Resp.FraudResponse; /// if (FraudResp != null) /// { /// Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg); /// Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg); /// } /// } /// // Get the Context and check for any contained SDK specific errors. /// Context Ctx = Resp.TransactionContext; /// if (Ctx != null && Ctx.getErrorCount() > 0) /// { /// Console.WriteLine(Environment.NewLine + "Errors = " + Ctx.ToString()); /// } /// </code> /// <code lang="Visual Basic" escaped="false"> /// ............ /// 'Trans is the transaction object. /// ............ /// ' Submit the transaction. /// Trans.SubmitTransaction() /// ' Get the Response. /// Dim Resp As Response = Trans.Response /// /// If Not Resp Is Nothing Then /// ' Get the Transaction Response parameters. /// /// Dim TrxnResponse As TransactionResponse = Resp.TransactionResponse /// /// If Not TrxnResponse Is Nothing Then /// Console.WriteLine("RESULT = " + TrxnResponse.Result) /// Console.WriteLine("PNREF = " + TrxnResponse.Pnref) /// Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg) /// Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode) /// Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr) /// Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip) /// Console.WriteLine("IAVS = " + TrxnResponse.IAVS) /// End If /// ' Get the Fraud Response parameters. /// Dim FraudResp As FraudResponse = Resp.FraudResponse /// If Not FraudResp Is Nothing Then /// Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg) /// Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg) /// End If /// End If /// ' Get the Context and check for any contained SDK specific errors. /// Dim Ctx As Context = Resp.TransactionContext /// /// If Not Ctx Is Nothing AndAlso Ctx.getErrorCount() > 0 Then /// Console.WriteLine(Constants.vbLf + "Errors = " + Ctx.ToString()) /// End If /// </code> /// </example> public virtual async Task <Response> SubmitTransactionAsync() { PayflowNetapi pfProNetApi = null; string responseValue = null; var fatal = false; Logger.Instance.Log("##### BEGIN TRANSACTION ##### -- " + RequestId, PayflowConstants.SeverityInfo); Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Entered", PayflowConstants.SeverityDebug); try { if (ClientInfo == null) { ClientInfo = new ClientInfo(); } //Check for the errors in the context now. var errors = PayflowUtility.AlignContext(Context, false); Context.LoadLoggerErrs = false; Context.ClearErrors(); Context.AddErrors(errors); if (Context.HighestErrorLvl == PayflowConstants.SeverityFatal) { Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SeverityDebug); fatal = true; } if (!fatal) { GenerateRequest(); _mRequest = RequestBuffer.ToString(); //Remove the trailing PayflowConstants.DELIMITER_NVP; var parmListLen = _mRequest.Length; if (parmListLen > 0 && _mRequest[parmListLen - 1] == '&') { _mRequest = _mRequest.Substring(0, parmListLen - 1); } //Call the api from here and submit transaction if (_mPayflowConnectionData != null) { pfProNetApi = new PayflowNetapi(_mPayflowConnectionData.HostAddress, _mPayflowConnectionData.HostPort, _mPayflowConnectionData.TimeOut, _mPayflowConnectionData.ProxyAddress, _mPayflowConnectionData.ProxyPort, _mPayflowConnectionData.ProxyLogon, _mPayflowConnectionData.ProxyPassword); } else { pfProNetApi = new PayflowNetapi(); } pfProNetApi.IsStrongAssemblyTransaction = true; pfProNetApi.ClientInfo = ClientInfo; responseValue = await pfProNetApi.SubmitTransactionAsync(_mRequest, RequestId); Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SeverityDebug); Logger.Instance.Log("##### END TRANSACTION ##### -- " + RequestId, PayflowConstants.SeverityInfo); } } catch (BaseException baseEx) { var error = baseEx.GetFirstErrorInExceptionContext(); //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_FATAL,false, null); Context.AddError(error); } catch (Exception ex) { var transEx = new TransactionException(ex); var error = PayflowUtility.PopulateCommError(PayflowConstants.EUnknownState, transEx, PayflowConstants.SeverityFatal, false, null); Context.AddError(error); } finally { if (pfProNetApi != null) { _mRequest = pfProNetApi.TransactionRequest; Context.AddErrors(pfProNetApi.TransactionContext.GetErrors()); RequestId = pfProNetApi.RequestId; ClientInfo = pfProNetApi.ClientInfo; } else { //There is some error due to which the return //is called even before pfpronetapi object is //created. //Check the first fatal error in context and //put its response value to string. if (_mRequest != null && _mRequest.Length > 0) { _mRequest = PayflowUtility.MaskSensitiveFields(_mRequest); } var errorList = Context.GetErrors(PayflowConstants.SeverityFatal); var firstFatalError = (ErrorObject)errorList[0]; responseValue = firstFatalError.ToString(); } _mResponse = new Response(RequestId, Context); _mResponse.SetRequestString(_mRequest); _mResponse.SetParams(responseValue); //Log the context if (Context.IsErrorContained()) { Context.LogErrors(); } pfProNetApi = null; } return(_mResponse); }
/// <summary> /// This method submits the transaction /// to the PayPal Payment Gateway. /// The response is obtained from the gateway /// and response object is populated with the /// response values along with the sdk specific /// errors in context, if any. /// </summary> /// <returns>Returns response object for Strong assembly transactions</returns> /// <example> /// <code lang="C#" escaped="false"> /// ............ /// //Trans is the transaction object. /// ............ /// /// //Submit the transaction. /// Trans.SubmitTransaction(); /// /// // Get the Response. /// Response Resp = Trans.Response; /// if (Resp != null) /// { /// // Get the Transaction Response parameters. /// TransactionResponse TrxnResponse = Resp.TransactionResponse; /// if (TrxnResponse != null) /// { /// Console.WriteLine("RESULT = " + TrxnResponse.Result); /// Console.WriteLine("PNREF = " + TrxnResponse.Pnref); /// Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg); /// Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode); /// Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr); /// Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip); /// Console.WriteLine("IAVS = " + TrxnResponse.IAVS); /// } /// // Get the Fraud Response parameters. /// FraudResponse FraudResp = Resp.FraudResponse; /// if (FraudResp != null) /// { /// Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg); /// Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg); /// } /// } /// // Get the Context and check for any contained SDK specific errors. /// Context Ctx = Resp.TransactionContext; /// if (Ctx != null && Ctx.getErrorCount() > 0) /// { /// Console.WriteLine(Environment.NewLine + "Errors = " + Ctx.ToString()); /// } ///</code> /// <code lang="Visual Basic" escaped="false"> /// ............ /// 'Trans is the transaction object. /// ............ /// ' Submit the transaction. /// Trans.SubmitTransaction() /// /// ' Get the Response. /// Dim Resp As Response = Trans.Response /// /// If Not Resp Is Nothing Then /// ' Get the Transaction Response parameters. /// /// Dim TrxnResponse As TransactionResponse = Resp.TransactionResponse /// /// If Not TrxnResponse Is Nothing Then /// Console.WriteLine("RESULT = " + TrxnResponse.Result) /// Console.WriteLine("PNREF = " + TrxnResponse.Pnref) /// Console.WriteLine("RESPMSG = " + TrxnResponse.RespMsg) /// Console.WriteLine("AUTHCODE = " + TrxnResponse.AuthCode) /// Console.WriteLine("AVSADDR = " + TrxnResponse.AVSAddr) /// Console.WriteLine("AVSZIP = " + TrxnResponse.AVSZip) /// Console.WriteLine("IAVS = " + TrxnResponse.IAVS) /// End If /// /// ' Get the Fraud Response parameters. /// Dim FraudResp As FraudResponse = Resp.FraudResponse /// If Not FraudResp Is Nothing Then /// Console.WriteLine("PREFPSMSG = " + FraudResp.PreFpsMsg) /// Console.WriteLine("POSTFPSMSG = " + FraudResp.PostFpsMsg) /// End If /// End If /// /// ' Get the Context and check for any contained SDK specific errors. /// Dim Ctx As Context = Resp.TransactionContext /// /// If Not Ctx Is Nothing AndAlso Ctx.getErrorCount() > 0 Then /// Console.WriteLine(Constants.vbLf + "Errors = " + Ctx.ToString()) /// End If /// </code> /// </example> public virtual Response SubmitTransaction() { PayflowNETAPI PfProNetApi = null; String ResponseValue = null; bool Fatal = false; Logger.Instance.Log("##### BEGIN TRANSACTION ##### -- " + mRequestId, PayflowConstants.SEVERITY_INFO); Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Entered", PayflowConstants.SEVERITY_DEBUG); try { if (mClientInfo == null) { mClientInfo = new ClientInfo(); } //Check for the errors in the context now. ArrayList Errors = PayflowUtility.AlignContext(mContext, false); mContext.LoadLoggerErrs = false; mContext.ClearErrors(); mContext.AddErrors(Errors); if (mContext.HighestErrorLvl == PayflowConstants.SEVERITY_FATAL) { Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SEVERITY_DEBUG); Fatal = true; } if (!Fatal) { GenerateRequest(); mRequest = RequestBuffer.ToString(); //Remove the trailing PayflowConstants.DELIMITER_NVP; int ParmListLen = mRequest.Length; if (ParmListLen > 0 && mRequest[ParmListLen - 1] == '&') { mRequest = mRequest.Substring(0, ParmListLen - 1); } //Call the api from here and submit transaction if (mPayflowConnectionData != null) { PfProNetApi = new PayflowNETAPI(mPayflowConnectionData.HostAddress, mPayflowConnectionData.HostPort, mPayflowConnectionData.TimeOut, mPayflowConnectionData.ProxyAddress, mPayflowConnectionData.ProxyPort, mPayflowConnectionData.ProxyLogon, mPayflowConnectionData.ProxyPassword); } else { PfProNetApi = new PayflowNETAPI(); } PfProNetApi.IsStrongAssemblyTransaction = true; PfProNetApi.ClientInfo = mClientInfo; ResponseValue = PfProNetApi.SubmitTransaction(mRequest, mRequestId); Logger.Instance.Log("PayPal.Payments.Transactions.BaseTransaction.SubmitTransaction(): Exiting", PayflowConstants.SEVERITY_DEBUG); Logger.Instance.Log("##### END TRANSACTION ##### -- " + mRequestId, PayflowConstants.SEVERITY_INFO); } } catch (BaseException BaseEx) { ErrorObject Error = BaseEx.GetFirstErrorInExceptionContext(); //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_FATAL,false, null); mContext.AddError(Error); } catch (Exception Ex) { TransactionException TransEx = new TransactionException(Ex); ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, TransEx, PayflowConstants.SEVERITY_FATAL, false, null); mContext.AddError(Error); } finally { if (PfProNetApi != null) { mRequest = PfProNetApi.TransactionRequest; mContext.AddErrors(PfProNetApi.TransactionContext.GetErrors()); mRequestId = PfProNetApi.RequestId; mClientInfo = PfProNetApi.ClientInfo; } else { //There is some error due to which the return //is called even before pfpronetapi object is //created. //Check the first fatal error in context and //put its response value to string. if (mRequest != null && mRequest.Length > 0) { mRequest = PayflowUtility.MaskSensitiveFields(mRequest); } ArrayList ErrorList = mContext.GetErrors(PayflowConstants.SEVERITY_FATAL); ErrorObject FirstFatalError = (ErrorObject)ErrorList[0]; ResponseValue = FirstFatalError.ToString(); } mResponse = new Response(mRequestId, mContext); mResponse.setRequestString(mRequest); mResponse.SetParams(ResponseValue); //Log the context if (mContext.IsErrorContained()) { mContext.LogErrors(); } PfProNetApi = null; } return(mResponse); }
/// <summary> /// Initializes the Server Connection. /// </summary> /// <returns>True if success, False otherwise.</returns> public bool ConnectToServer() { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Entered.", PayflowConstants.SEVERITY_DEBUG); bool RetVal = false; try { //Initialize Server Uri. Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Initializing Server Uri.", PayflowConstants.SEVERITY_INFO); InitServerUri(); Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Initialized Server Uri = " + mServerUri.AbsoluteUri, PayflowConstants.SEVERITY_INFO); //Create Connection object & Set Connection Attributes Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Initializing Connection Attributes.", PayflowConstants.SEVERITY_INFO); CreateConnection(); if (mServerConnection != null) { if (mProxyStatus) { RetVal = true; Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Connection Created.", PayflowConstants.SEVERITY_INFO); } else { RetVal = false; Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Connection Creation Failure: Incorrect Proxy Details.", PayflowConstants.SEVERITY_INFO); } } else { RetVal = false; Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Connection Creation Failure.", PayflowConstants.SEVERITY_INFO); } } catch (Exception Ex) { String AddlMessage = "Input Server Uri = " + mServerUri.AbsoluteUri; if (IsProxy) { AddlMessage += " Input Proxy info = " + mProxyInfo.Address.ToString(); } ErrorObject InitError = PayflowUtility.PopulateCommError(PayflowConstants.E_SOK_CONN_FAILED, Ex, PayflowConstants.SEVERITY_ERROR, IsXmlPayRequest, AddlMessage); if (!ConnContext.IsCommunicationErrorContained(InitError)) { ConnContext.AddError(InitError); } } finally { Logger.Instance.Log("PayPal.Payments.Communication.PaymentConnection.ConnectToServer(String): Exiting.", PayflowConstants.SEVERITY_DEBUG); } return(RetVal); }
/// <summary> /// Execute function. /// </summary> public override async Task ExecuteAsync() { var isReceiveSuccess = false; Logger.Instance.Log("PayPal.Payments.Communication.ReceiveState.Execute(): Entered.", PayflowConstants.SeverityDebug); if (!InProgress) { return; } try { //Begin Payflow Timeout Check Point 4 long timeRemainingMsec; if (PayflowUtility.IsTimedOut(Connection.TimeOut, Connection.StartTime, out timeRemainingMsec)) { var addlMessage = "Input timeout value in millisec = " + Connection.TimeOut; var err = PayflowUtility.PopulateCommError(PayflowConstants.ETimeoutWaitResp, null, PayflowConstants.SeverityFatal, IsXmlPayRequest, addlMessage); if (!CommContext.IsCommunicationErrorContained(err)) { CommContext.AddError(err); } } else { Connection.TimeOut = timeRemainingMsec; } //End Payflow Timeout Check Point 4 var responseValue = await Connection.ReceiveResponseAsync(); isReceiveSuccess = SetReceiveResponse(responseValue); } catch (Exception ex) { Logger.Instance.Log( "PayPal.Payments.Communication.ReceiveState.Execute(): Error occurred While Receiving Response.", PayflowConstants.SeverityError); Logger.Instance.Log("PayPal.Payments.Communication.ReceiveState.Execute(): Exception " + ex, PayflowConstants.SeverityError); isReceiveSuccess = false; } //catch //{ // IsReceiveSuccess = false; //} finally { if (isReceiveSuccess) { Logger.Instance.Log( "PayPal.Payments.Communication.ReceiveState.Execute(): Receive Response = Success ", PayflowConstants.SeverityInfo); SetStateSuccess(); } else { Logger.Instance.Log( "PayPal.Payments.Communication.ReceiveState.Execute(): Receive Response = Failure ", PayflowConstants.SeverityInfo); SetStateFail(); } } Logger.Instance.Log("PayPal.Payments.Communication.ReceiveState.Execute(): Exiting.", PayflowConstants.SeverityDebug); }
/// <summary> /// Overrides ToString /// </summary> /// <returns>String value of currency</returns> /// <remarks>Formats string value of currency in format "$.CC"</remarks> /// <example> /// <code lang="C#" escaped="false"> /// ............. /// //Inv is the Invoice object /// ............. /// /// //Set the invoice amount. /// Inv.Amt = new Currency(new Decimal(25.12),"USD"); /// String CurrValue = Inv.ToString(); /// ............. /// </code> /// <code lang="Visual Basic" escaped="false"> /// ............. /// 'Inv is the Invoice object /// ............. /// /// 'Set the invoice amount. /// Inv.Amt = New Currency(New Decimal(25.12),"USD") /// CurrValue As String = Inv.ToString /// ............. /// </code> /// </example> public override string ToString() { try { //Overridden ToString. Returns held Currency Value. var retVal = PayflowConstants.EmptyString; // We need to double check here whether currency value // is non-zero positive before converting it. // PPSCR00563818 - .NET SDK: Foreign currency not supported // Added Globalization - 15/10/07 - tsieber // Removed Globalization - Oct 03 2012, tsieber - as GW cannot handle comma's in amounts yet. // Creates a CultureInfo for English in the U.S. //CultureInfo usCulture = new CultureInfo("en-US"); // Sets the CurrentCulture to en_US. //Thread.CurrentThread.CurrentCulture = usCulture; // Clones the NumberFormatInfo and creates // a new object for the local currency of France. //NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); // Replaces the default currency symbol with the // local currency symbol. //LocalFormat.CurrencySymbol = ""; if (_mNoOfDecimalDigits < 0) { _mNoOfDecimalDigits = 2; } if (_mRound && _mTruncate) { var err = PayflowUtility.PopulateCommError(PayflowConstants.ECurrencyProcessError, null, PayflowConstants.SeverityFatal, false, null); throw new DataObjectException(err); } if (_mRound) { _mCurrencyValue = decimal.Round(_mCurrencyValue, _mNoOfDecimalDigits); retVal = RoundCurrencyValue(_mCurrencyValue.ToString(), _mNoOfDecimalDigits); //RetVal = mCurrencyValue.ToString("c", LocalFormat); } else if (_mTruncate) { //RetVal = TruncateCurrencyValue(mCurrencyValue.ToString("c", LocalFormat),mNoOfDecimalDigits); retVal = TruncateCurrencyValue(_mCurrencyValue.ToString(), _mNoOfDecimalDigits); } else { //RetVal = mCurrencyValue.ToString("c", LocalFormat); retVal = _mCurrencyValue.ToString(); } var indexOfDecimal = retVal.IndexOf(".", 1); if (indexOfDecimal < 0 && _mNoOfDecimalDigits != 0) { retVal += ".00"; } var tempStr = retVal.Substring(indexOfDecimal + 1, retVal.Length - indexOfDecimal - 1); var len = tempStr.Length; if (len < 2) { for (var i = len; i < 2; i++) { retVal = retVal + "0"; } } return(retVal); } catch (BaseException) { throw; } catch (Exception ex) { var dEx = new DataObjectException(ex); throw dEx; } //catch //{ // throw new Exception(); //} }
/// <summary> /// Sets the response params /// </summary> /// <param name="response">Response string</param> internal void SetParams(string response) { try { _mResponseString = response; if (response != null) { var resultIndex = response.IndexOf(PayflowConstants.ParamResult); if (resultIndex >= 0) { if (resultIndex > 0) { response = response.Substring(resultIndex); } ParseResponse(response); SetResultParams(ref _mResponseHashTable); SetFraudResultParams(ref _mResponseHashTable); SetBuyerAuthResultParams(ref _mResponseHashTable); var trxType = PayflowUtility.LocateValueForName(RequestString, PayflowConstants.ParamTrxtype, false); if (string.Equals(trxType, PayflowConstants.TrxtypeRecurring)) { SetRecurringResultParams(ref _mResponseHashTable); } else { SetExpressCheckoutDoResultParams(ref _mResponseHashTable); SetExpressCheckoutGetResultParams(ref _mResponseHashTable); SetExpressCheckoutSetResultParams(ref _mResponseHashTable); SetExpressCheckoutUpdateResultParams(ref _mResponseHashTable); } _mResponseHashTable.Remove(PayflowConstants.IntlParamFullresponse); SetExtDataList(); _mResponseHashTable = null; } else { //Append the RESULT and RESPMSG for error code //E_UNKNOWN_STATE and create a message. //Call SetParams again on it. var responseValue = PayflowConstants.ParamResult + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorCodes[PayflowConstants.EUnknownState] + PayflowConstants.DelimiterNvp + PayflowConstants.ParamRespmsg + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorMessages[ PayflowConstants.EUnknownState] + ", " + _mResponseString; SetParams(responseValue); } } else { var addlMessage = "Empty response"; var err = PayflowUtility.PopulateCommError(PayflowConstants.EEmptyParamList, null, PayflowConstants.SeverityWarn, false, addlMessage); TransactionContext.AddError(err); err = TransactionContext.GetError(TransactionContext.GetErrorCount() - 1); var responseValue = err.ToString(); SetParams(responseValue); } } catch (BaseException baseEx) { //ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,BaseEx,PayflowConstants.SEVERITY_ERROR,false, null); var error = baseEx.GetFirstErrorInExceptionContext(); TransactionContext.AddError(error); var responseValue = error.ToString(); SetParams(responseValue); } catch (Exception ex) { var dEx = new DataObjectException(ex); var error = PayflowUtility.PopulateCommError(PayflowConstants.EUnknownState, dEx, PayflowConstants.SeverityError, false, null); TransactionContext.AddError(error); var responseValue = error.ToString(); SetParams(responseValue); } //catch //{ // ErrorObject Error = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE,null,PayflowConstants.SEVERITY_ERROR,false,null); // mContext.AddError(Error); // String ResponseValue = Error.ToString(); // this.SetParams(ResponseValue); //} }
/// <summary> /// Changes the Payment States depending upon /// the current state status. /// </summary> /// <param name="CurrentPmtState">Current Payment State.</param> /// <returns>Next Payment State</returns> private PaymentState GetNextState(PaymentState CurrentPmtState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState): Entered.", PayflowConstants.SEVERITY_DEBUG); if (CurrentPmtState.Success && CurrentPmtState.InProgress) { if (CurrentPmtState is TransactionReceiveState) { // exit state CurrentPmtState.SetTransactionSuccess(); } else if (CurrentPmtState is SendInitState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Success): SentInitState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new TransactionSendState(CurrentPmtState); } else if (CurrentPmtState is TransactionSendState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Success): TransactionSentState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new TransactionReceiveState(CurrentPmtState); } else if (CurrentPmtState is SendRetryState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Success): SendRetryState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new SendReconnectState(CurrentPmtState); } else if (CurrentPmtState is SendReconnectState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Success): SendReconnectState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new SendInitState(CurrentPmtState); } // unknown state else { String AddlMessage = "Unknown State, Current State = " + mPaymentState.ToString(); ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, null, PayflowConstants.SEVERITY_FATAL, mPaymentState.IsXmlPayRequest, AddlMessage); if (!PsmContext.IsCommunicationErrorContained(Err)) { PsmContext.AddError(Err); } } } else if (CurrentPmtState.Failed && CurrentPmtState.InProgress) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState): Current Payment State Failed. Current State = " + mPaymentState.ToString(), PayflowConstants.SEVERITY_DEBUG); if (CurrentPmtState is ReconnectState) { // exit state if (!PsmContext.IsErrorContained()) { String AddlMessage = "Exceeded Reconnect attempts, check context for error, Current reconnect attempt = " + mPaymentState.AttemptNo.ToString(); ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_TIMEOUT_WAIT_RESP, null, PayflowConstants.SEVERITY_FATAL, mPaymentState.IsXmlPayRequest, AddlMessage); if (!PsmContext.IsCommunicationErrorContained(Err)) { PsmContext.AddError(Err); } } else { ArrayList ErrList = new ArrayList(); ErrList.AddRange(PsmContext.GetErrors()); int HighestSevLevel = PsmContext.HighestErrorLvl; int ErrorListIndex; int ErrorListSize = ErrList.Count; for (ErrorListIndex = 0; ErrorListIndex < ErrorListSize; ErrorListIndex++) { ErrorObject Err = (ErrorObject)ErrList[ErrorListIndex]; if (Err.SeverityLevel == HighestSevLevel) { int index; int size = Err.MessageParams.Count; string[] MsgCodeParams = new string[size]; for (index = 0; index < size; index++) { MsgCodeParams[index] = (string)Err.MessageParams[index]; } ErrorObject Error = new ErrorObject(PayflowConstants.SEVERITY_FATAL, Err.MessageCode, MsgCodeParams); ErrList[ErrorListIndex] = Error; break; } } PsmContext.ClearErrors(); PsmContext.AddErrors(ErrList); } } else if (CurrentPmtState is SendInitState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Failed): SendInitState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new SendReconnectState(CurrentPmtState); } else if (CurrentPmtState is TransactionSendState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Failed): TransactionSendState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new SendRetryState(CurrentPmtState); } else if (CurrentPmtState is TransactionReceiveState) { Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState.Failed): TransactionReceiveState Entered.", PayflowConstants.SEVERITY_DEBUG); CurrentPmtState = new SendRetryState(CurrentPmtState); } // unknown state else { String AddlMessage = "Current State = " + mPaymentState.ToString(); ErrorObject Err = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, null, PayflowConstants.SEVERITY_FATAL, mPaymentState. IsXmlPayRequest, AddlMessage); if (!PsmContext.IsCommunicationErrorContained(Err)) { PsmContext.AddError(Err); } } } Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState): Obtained State = " + mPaymentState.GetType().ToString(), PayflowConstants.SEVERITY_INFO); Logger.Instance.Log("PayPal.Payments.Communication.PaymentStateMachine.GetNextState(PaymentState): Exiting.", PayflowConstants.SEVERITY_DEBUG); return(CurrentPmtState); }