/// ----------------------------------------------------------------------------- /// <summary> /// This is a internal method and takes in a errorobject as a parameter.This method /// then calls another overloaded version for the method Log which takes in a /// string to be logged and the severity level of the Error Object. /// </summary> /// <param name="Message" >ErrorObject</param> /// <return></return> /// <remarks> /// </remarks> /// ----------------------------------------------------------------------------- internal void Log(ErrorObject Message) { if (Message != null) { Log(Message.ToString(), Message.SeverityLevel); } }
public override string ToString() { var msg = CatchedException.Message; msg += $"{Environment.NewLine}{ErrorObject.ToString()}"; return(msg); }
/// <summary> /// 异常返回值 /// </summary> /// <param name="context"></param> /// <returns></returns> public IActionResult OnException(ExceptionContext context) { // 解析异常信息 var(ErrorCode, ErrorObject) = UnifyContext.GetExceptionMetadata(context); return(new JsonResult(new TData <object> { Message = ErrorObject.ToString() })); }
/// <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> /// This is a internal method and takes in a errorobject as a parameter.This method /// then calls another overloaded version for the method Log which takes in a /// string to be logged and the severity level of the Error Object. /// </summary> /// <param name="message">ErrorObject</param> /// <return></return> /// <remarks> /// </remarks> /// ----------------------------------------------------------------------------- internal void Log(ErrorObject message) { if (message != null) Log(message.ToString(), message.SeverityLevel); }
/// <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); }
internal static ArrayList AlignContext(Context Context, bool IsXmlPayRequest) { ArrayList Errors = Context.GetErrors(); ArrayList RetVal = new ArrayList(); int ErrorCount = Errors.Count; int Index; for (Index = 0; Index < ErrorCount; Index++) { ErrorObject Error = (ErrorObject)Errors[Index]; String MessageCode = Error.MessageCode; if (Error != null) { if (MessageCode != null && MessageCode.Length > 0) { bool Msg1012 = false; bool Msg1013 = false; bool Msg1015 = false; bool Msg1016 = false; if ("MSG_1012".Equals(MessageCode)) { Msg1012 = true; } else if ("MSG_1013".Equals(MessageCode)) { Msg1013 = true; } else if ("MSG_1015".Equals(MessageCode)) { Msg1015 = true; } else if ("MSG_1016".Equals(MessageCode)) { Msg1016 = true; } if (IsXmlPayRequest) { if (Msg1013 || Msg1016) { RetVal.Add(Error); } else { ErrorObject NewError = null; try { if (Msg1012) { ArrayList MsgParams = Error.MessageParams; String[] NewMsgParams = new String[] { (String)MsgParams[0], (String)MsgParams[1] }; NewError = new ErrorObject(Error.SeverityLevel, "MSG_1013", NewMsgParams, Error.ErrorStackTrace); } else if (Msg1015) { ArrayList MsgParams = Error.MessageParams; String[] NewMsgParams = new String[] { (String)MsgParams[0], (String)MsgParams[1] }; NewError = new ErrorObject(Error.SeverityLevel, "MSG_1016", NewMsgParams, Error.ErrorStackTrace); } else { String ErrMessage = Error.ToString(); NewError = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, null, Error.SeverityLevel, true, ErrMessage); } } catch { NewError = null; } if (NewError != null) { RetVal.Add(NewError); } } } else { if (Msg1012 || Msg1015) { RetVal.Add(Error); } else { ErrorObject NewError = null; try { if (Msg1013) { ArrayList MsgParams = Error.MessageParams; String[] NewMsgParams = new String[] { (String)MsgParams[2], (String)MsgParams[3] }; NewError = new ErrorObject(Error.SeverityLevel, "MSG_1012", NewMsgParams, Error.ErrorStackTrace); } else if (Msg1016) { ArrayList MsgParams = Error.MessageParams; String[] NewMsgParams = new String[] { (String)MsgParams[1], (String)MsgParams[2] }; NewError = new ErrorObject(Error.SeverityLevel, "MSG_1015", NewMsgParams, Error.ErrorStackTrace); } else { String ErrMessage = Error.ToString(); NewError = PayflowUtility.PopulateCommError(PayflowConstants.E_UNKNOWN_STATE, null, Error.SeverityLevel, false, ErrMessage); } } catch { NewError = null; } if (NewError != null) { RetVal.Add(NewError); } } } } else { ErrorObject NewError = null; try { String ErrMessage = Error.ToString(); if (ErrMessage != null && ErrMessage.Length > 0) { String Result = PayflowConstants.EMPTY_STRING; String RespMsg = PayflowConstants.EMPTY_STRING; bool ErrIsXmlPay = (ErrMessage.IndexOf(PayflowConstants.XML_RESP_ID) >= 0); //Check whether the error string is in nvp format // or xml pay format. if (ErrIsXmlPay) { //Try to get values in nodes Result, RespMsg Result = PayflowUtility.GetXmlPayNodeValue(ErrMessage, PayflowConstants.XML_PARAM_RESULT); RespMsg = PayflowUtility.GetXmlPayNodeValue(ErrMessage, PayflowConstants.XML_PARAM_MESSAGE); } else { //Try to get RESULT , RESPMSG from the error if // available. Result = PayflowUtility.LocateValueForName(ErrMessage, PayflowConstants.PARAM_RESULT, false); RespMsg = PayflowUtility.LocateValueForName(ErrMessage, PayflowConstants.PARAM_RESPMSG, false); } if (Result != null && Result.Length > 0 && RespMsg != null && RespMsg.Length > 0) { StringBuilder NewErrMessage = new StringBuilder(""); if (IsXmlPayRequest && !ErrIsXmlPay) { NewErrMessage = new StringBuilder("<XMLPayResponse xmlns='http://www.paypal.com/XMLPay'"); NewErrMessage.Append("><ResponseData><TransactionResults><TransactionResult><Result>"); NewErrMessage.Append(Result); NewErrMessage.Append("</Result><Message>"); NewErrMessage.Append(RespMsg); NewErrMessage.Append("</Message></TransactionResult></TransactionResults></ResponseData></XMLPayResponse>"); NewError = new ErrorObject(Error.SeverityLevel, "", NewErrMessage.ToString()); } else if (!IsXmlPayRequest && ErrIsXmlPay) { NewErrMessage = new StringBuilder(PayflowConstants.PARAM_RESULT); NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP); NewErrMessage.Append(Result); NewErrMessage.Append(PayflowConstants.DELIMITER_NVP); NewErrMessage.Append(PayflowConstants.PARAM_RESPMSG); NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP); NewErrMessage.Append(RespMsg); NewError = new ErrorObject(Error.SeverityLevel, "", NewErrMessage.ToString()); } else { NewError = new ErrorObject(Error.SeverityLevel, "", ErrMessage); } } else { StringBuilder NewErrMessage = new StringBuilder(""); if (IsXmlPayRequest) { NewErrMessage = new StringBuilder("<XMLPayResponse xmlns='http://www.paypal.com/XMLPay'"); NewErrMessage.Append("><ResponseData><TransactionResults><TransactionResult><Result>"); NewErrMessage.Append((String)PayflowConstants.CommErrorCodes[PayflowConstants.E_UNKNOWN_STATE]); NewErrMessage.Append("</Result><Message>"); NewErrMessage.Append((String)PayflowConstants.CommErrorMessages[PayflowConstants.E_UNKNOWN_STATE] + " " + ErrMessage); NewErrMessage.Append("</Message></TransactionResult></TransactionResults></ResponseData></XMLPayResponse>"); } else { NewErrMessage = new StringBuilder(PayflowConstants.PARAM_RESULT); NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP); NewErrMessage.Append((String)PayflowConstants.CommErrorCodes[PayflowConstants.E_UNKNOWN_STATE]); NewErrMessage.Append(PayflowConstants.DELIMITER_NVP); NewErrMessage.Append(PayflowConstants.PARAM_RESPMSG); NewErrMessage.Append(PayflowConstants.SEPARATOR_NVP); NewErrMessage.Append((String)PayflowConstants.CommErrorMessages[PayflowConstants.E_UNKNOWN_STATE] + " " + ErrMessage); } NewError = new ErrorObject(Error.SeverityLevel, "", NewErrMessage.ToString()); } } } catch { NewError = null; } if (NewError != null) { RetVal.Add(NewError); } } } } return(RetVal); }
/// <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); //} }