Exemplo n.º 1
0
        public TransactionException(PayLoadFromat payLoadFormat, string faultMessage)
        {
            try
            {
                switch (payLoadFormat)
                {
                case PayLoadFromat.SOAP11:
                {
                    /// typecasting fault string to SOAP fault Envelope
                    PayPal.Platform.SDK.Fault env = (PayPal.Platform.SDK.Fault)SoapEncoder.Decode(faultMessage, typeof(PayPal.Platform.SDK.Fault));

                    /// Constructing TransactionException message
                    this.ack           = env.detail.FaultMessage.responseEnvelope.ack;
                    this.build         = env.detail.FaultMessage.responseEnvelope.build;
                    this.correlationID = env.detail.FaultMessage.responseEnvelope.correlationId;
                    this.errorDetails  = env.detail.FaultMessage.error;
                    break;
                }

                case PayLoadFromat.XML:
                {
                    /// typecasting fault string to SOAP fault Envelope
                    PayPal.Platform.SDK.FaultDetailFaultMessage env = (PayPal.Platform.SDK.FaultDetailFaultMessage)XMLEncoder.Decode(faultMessage, typeof(PayPal.Platform.SDK.FaultDetailFaultMessage));

                    /// Constructing TransactionException message
                    this.ack           = env.responseEnvelope.ack;
                    this.build         = env.responseEnvelope.build;
                    this.correlationID = env.responseEnvelope.correlationId;
                    this.errorDetails  = env.error;
                    break;
                }

                case PayLoadFromat.JSON:
                {
                    /// typecasting fault string to SOAP fault Envelope
                    PayPal.Platform.SDK.Fault env = (PayPal.Platform.SDK.Fault)JSONSerializer.JsonDecode(faultMessage, typeof(PayPal.Platform.SDK.Fault));
                    ///// Constructing TransactionException message
                    this.ack           = env.detail.FaultMessage.responseEnvelope.ack;
                    this.build         = env.detail.FaultMessage.responseEnvelope.build;
                    this.correlationID = env.detail.FaultMessage.responseEnvelope.correlationId;
                    this.errorDetails  = env.detail.FaultMessage.error;
                    break;
                }
                }
            }
            catch (FATALException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new FATALException("Error occurred in TranactionException->Constructor method", ex);
            }
            finally
            {
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calls Pay Platform API for the given PayRequest and returns PayResponse
        /// </summary>
        /// <param name="request">PayRequest</param>
        /// <returns>PayResponse</returns>
        public RequestPermissionsResponse requestPermissions(RequestPermissionsRequest request)
        {
            RequestPermissionsResponse PResponse = null;

            PayLoad = null;

            try
            {
                APIProfile.EndPointAppend = Endpoint + "RequestPermissions";
                if (APIProfile.RequestDataformat == "SOAP11")
                {
                    PayLoad = SoapEncoder.Encode(request);
                }
                else if (APIProfile.RequestDataformat == "XML")
                {
                    PayLoad = PayPal.Platform.SDK.XMLEncoder.Encode(request);
                }
                else
                {
                    PayLoad = PayPal.Platform.SDK.JSONSerializer.ToJavaScriptObjectNotation(request);
                }
                res = CallAPI();

                if (APIProfile.RequestDataformat == "JSON")
                {
                    object obj = JSONSerializer.JsonDecode(res.ToString(), typeof(PayPal.Services.Private.Permissions.RequestPermissionsResponse));
                    if (obj.GetType() == typeof(PayPal.Services.Private.Permissions.RequestPermissionsResponse))
                    {
                        PResponse = (PayPal.Services.Private.Permissions.RequestPermissionsResponse)obj;
                    }
                    string name = Enum.GetName(PResponse.responseEnvelope.ack.GetType(), PResponse.responseEnvelope.ack);

                    if (name == "Failure")
                    {
                        this.result = "FAILURE";
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.JSON, res.ToString());
                        this.lastError = tranactionEx;
                    }
                }

                else if (res.ToString().ToUpper().Replace("<ACK>FAILURE</ACK>", "").Length != res.ToString().Length)
                {
                    this.result = "FAILURE";

                    if (APIProfile.RequestDataformat == "SOAP11")
                    {
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.SOAP11, res.ToString());
                        this.lastError = tranactionEx;
                    }
                    else if (APIProfile.RequestDataformat == "XML")
                    {
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.XML, res.ToString());
                        this.lastError = tranactionEx;
                    }
                    else
                    {
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.JSON, res.ToString());
                        this.lastError = tranactionEx;
                    }
                }
                else
                {
                    if (APIProfile.RequestDataformat == "SOAP11")
                    {
                        PResponse = (PayPal.Services.Private.Permissions.RequestPermissionsResponse)SoapEncoder.Decode(res.ToString(), typeof(PayPal.Services.Private.Permissions.RequestPermissionsResponse));
                    }
                    else if (APIProfile.RequestDataformat == "XML")
                    {
                        PResponse = (PayPal.Services.Private.Permissions.RequestPermissionsResponse)XMLEncoder.Decode(res.ToString(), typeof(PayPal.Services.Private.Permissions.RequestPermissionsResponse));
                    }
                    else
                    {
                        object obj = JSONSerializer.JsonDecode(res.ToString(), typeof(PayPal.Services.Private.Permissions.RequestPermissionsResponse));
                        if (obj.GetType() == typeof(PayPal.Services.Private.Permissions.RequestPermissionsResponse))
                        {
                            PResponse = (PayPal.Services.Private.Permissions.RequestPermissionsResponse)obj;
                        }
                    }
                    this.result = "SUCCESS";
                }
            }
            catch (FATALException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new FATALException("Error occurred in Permissions -> RequestPermissions method.", ex);
            }
            return(PResponse);
        }