コード例 #1
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);
        }