コード例 #1
0
        /// <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 &amp;&amp; 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);
        }
コード例 #2
0
        /// <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 &amp;&amp; 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);
        }