Esempio n. 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);
        }
Esempio n. 2
0
 /// <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);
     //}
 }