Beispiel #1
0
        /**
         * AUTO_GENERATED
         */
        public RequestPermissionsResponse RequestPermissions(RequestPermissionsRequest requestPermissionsRequest, string apiUserName)
        {
            string  response = Call("RequestPermissions", requestPermissionsRequest.ToNVPString(""), apiUserName);
            NVPUtil util     = new NVPUtil();

            return(RequestPermissionsResponse.CreateInstance(util.ParseNVPString(response), "", -1));
        }
    public void RequestPermissions()
    {
        RequestPermissionsSample   sample = new RequestPermissionsSample();
        RequestPermissionsResponse requestPermissionsResponse = sample.RequestPermissionsAPIOperation();

        Assert.IsNotNull(requestPermissionsResponse);
        Assert.AreEqual(requestPermissionsResponse.responseEnvelope.ack.ToString().Trim().ToUpper(), "SUCCESS");
        Assert.IsNotNull(requestPermissionsResponse.token);
    }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        ///<param name="requestPermissionsRequest"></param>
        ///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param>
        public RequestPermissionsResponse RequestPermissions(RequestPermissionsRequest requestPermissionsRequest, ICredential credential)
        {
            IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, requestPermissionsRequest.ToNVPString(string.Empty), ServiceName, "RequestPermissions", credential);

            ((PlatformAPICallPreHandler)apiCallPreHandler).SDKName    = SDKName;
            ((PlatformAPICallPreHandler)apiCallPreHandler).SDKVersion = SDKVersion;
            ((PlatformAPICallPreHandler)apiCallPreHandler).PortName   = "Permissions";

            NVPUtil util = new NVPUtil();

            return(RequestPermissionsResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1));
        }
Beispiel #4
0
 /// <summary>
 /// Gets the permissions token.
 /// </summary>
 /// <param name="callback">The callback.</param>
 /// <remarks>
 ///  callback - function that specifies actions to take after the account holder grants or denies the request
 /// </remarks>
 /// <returns></returns>
 public Task <string> GetPermissionsToken(string callback)
 {
     //Permission SDK
     return(Task.Run(() => {
         var permissionsService = new PermissionsService(Config.ToDictionary());
         RequestPermissionsRequest request = new RequestPermissionsRequest {
             callback = callback,
             scope = new List <string> {
                 "ACCESS_BASIC_PERSONAL_DATA",
                 "ACCESS_ADVANCED_PERSONAL_DATA",
                 "TRANSACTION_SEARCH",
                 "TRANSACTION_DETAILS"
             }
         };
         RequestPermissionsResponse response = permissionsService.RequestPermissions(request);
         return response.token;
     }));
 }
Beispiel #5
0
        private void RequestPermissions(HttpContext context)
        {
            RequestPermissionsRequest rp = new RequestPermissionsRequest();

            rp.scope = new List <string>();
            string[] scopes = context.Request.Form.GetValues("api");

            for (int i = 0; i < scopes.Length; i++)
            {
                rp.scope.Add(scopes[i]);
            }


            rp.callback        = context.Request.Params["callback"];
            rp.requestEnvelope = new RequestEnvelope("en_US");
            RequestPermissionsResponse rpr = null;

            try
            {
                PermissionsService service = new PermissionsService();
                rpr = service.RequestPermissions(rp);
                context.Response.Write("<html><body><textarea rows=30 cols=80>");
                ObjectDumper.Write(rpr, 5, context.Response.Output);
                context.Response.Write("</textarea></body></html>");

                string red = "<br>";
                red = red + "<a href=";
                red = red + ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_grant-permission&request_token=" + rpr.token;
                red = red + ">Redirect URL (Click to redirect)</a><br>";
                context.Response.Write(red);
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
            }
        }
Beispiel #6
0
        private void RequestPermissions(HttpContext context)
        {
            RequestPermissionsRequest rp = new RequestPermissionsRequest();

            rp.scope = new List <string>();

            // (Required) At least 1 of the following permission categories:
            //EXPRESS_CHECKOUT - Express Checkout
            //DIRECT_PAYMENT - Direct payment by debit or credit card
            //SETTLEMENT_CONSOLIDATION - Settlement consolidation
            //SETTLEMENT_REPORTING - Settlement reporting
            //AUTH_CAPTURE - Payment authorization and capture
            //MOBILE_CHECKOUT - Mobile checkout
            //BILLING_AGREEMENT - Billing agreements
            //REFERENCE_TRANSACTION - Reference transactions
            //AIR_TRAVEL - Express Checkout for UTAP
            //MASS_PAY - Mass pay
            //TRANSACTION_DETAILS - Transaction details
            //TRANSACTION_SEARCH - Transaction search
            //RECURRING_PAYMENTS - Recurring payments
            //ACCOUNT_BALANCE - Account balance
            //ENCRYPTED_WEBSITE_PAYMENTS - Encrypted website payments
            //REFUND - Refunds
            //NON_REFERENCED_CREDIT - Non-referenced credit
            //BUTTON_MANAGER - Button Manager
            //MANAGE_PENDING_TRANSACTION_STATUS includes ManagePendingTransactionStatus
            //RECURRING_PAYMENT_REPORT - Reporting for recurring payments
            //EXTENDED_PRO_PROCESSING_REPORT - Extended Pro processing
            //EXCEPTION_PROCESSING_REPORT - Exception processing
            //ACCOUNT_MANAGEMENT_PERMISSION - Account Management Permission (MAM)
            //ACCESS_BASIC_PERSONAL_DATA - User attributes
            //ACCESS_ADVANCED_PERSONAL_DATA - User attributes
            //INVOICING - Invoicing
            string[] scopes = context.Request.Form.GetValues("api");

            for (int i = 0; i < scopes.Length; i++)
            {
                rp.scope.Add(scopes[i]);
            }

            //(Required) Your callback function that specifies actions to
            // take after the account holder grants or denies the request.
            rp.callback = context.Request.Params["callback"];

            // (Required) RFC 3066 language in which error messages are returned;
            // by default it is en_US, which is the only language currently supported.
            rp.requestEnvelope = new RequestEnvelope("en_US");
            RequestPermissionsResponse rpr = null;

            try
            {
                // ## Creating service wrapper object
                // Creating service wrapper object to make API call
                // Configuration map containing signature credentials and other required configuration.
                // For a full list of configuration parameters refer in wiki page
                // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
                PermissionsService service = new PermissionsService(Configuration.GetAcctAndConfig());

                rpr = service.RequestPermissions(rp);
                context.Response.Write("<html><body><textarea rows=30 cols=80>");
                ObjectDumper.Write(rpr, 5, context.Response.Output);
                context.Response.Write("</textarea></body></html>");

                string red = "<br>";
                red = red + "<a href=";
                red = red + ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_grant-permission&request_token=" + rpr.token;
                red = red + ">Redirect URL (Click to redirect)</a><br>";
                context.Response.Write(red);
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
            }
        }
Beispiel #7
0
    // # RequestPermissions API Operation
    // Use the RequestPermissions API operation to request permissions to execute API operations on a PayPal account holder’s behalf.
    public RequestPermissionsResponse RequestPermissionsAPIOperation()
    {
        // Create the RequestPermissionsResponse object
        RequestPermissionsResponse responseRequestPermissions = new RequestPermissionsResponse();

        try
        {
            // # RequestPermissionsRequest
            // `Scope`, which can take at least 1 of the following permission
            // categories:
            //
            // * EXPRESS_CHECKOUT
            // * DIRECT_PAYMENT
            // * AUTH_CAPTURE
            // * AIR_TRAVEL
            // * TRANSACTION_SEARCH
            // * RECURRING_PAYMENTS
            // * ACCOUNT_BALANCE
            // * ENCRYPTED_WEBSITE_PAYMENTS
            // * REFUND
            // * BILLING_AGREEMENT
            // * REFERENCE_TRANSACTION
            // * MASS_PAY
            // * TRANSACTION_DETAILS
            // * NON_REFERENCED_CREDIT
            // * SETTLEMENT_CONSOLIDATION
            // * SETTLEMENT_REPORTING
            // * BUTTON_MANAGER
            // * MANAGE_PENDING_TRANSACTION_STATUS
            // * RECURRING_PAYMENT_REPORT
            // * EXTENDED_PRO_PROCESSING_REPORT
            // * EXCEPTION_PROCESSING_REPORT
            // * ACCOUNT_MANAGEMENT_PERMISSION
            // * INVOICING
            // * ACCESS_BASIC_PERSONAL_DATA
            // * ACCESS_ADVANCED_PERSONAL_DATA
            List <String> scopeList = new List <String>();
            scopeList.Add("INVOICING");
            scopeList.Add("EXPRESS_CHECKOUT");

            // Create RequestPermissionsRequest object which takes mandatory params:
            //
            // * `Scope`
            // * `Callback` - Your callback function that specifies actions to take
            // after the account holder grants or denies the request.
            RequestPermissionsRequest requestRequestPermissions = new RequestPermissionsRequest(scopeList, "http://localhost/callback");

            // Create the service wrapper object
            PermissionsService service = new PermissionsService();

            // # API call
            // Invoke the RequestPermissions method in service wrapper object
            responseRequestPermissions = service.RequestPermissions(requestRequestPermissions);

            if (responseRequestPermissions != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "Request Permissions API Operation - ";
                acknowledgement += responseRequestPermissions.responseEnvelope.ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseRequestPermissions.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // # Redirecting to PayPal
                    // Once you get the success response, user needs to redirect to
                    // paypal to authorize. Construct the `redirectUrl` as follows,
                    //
                    //     redirectURL=https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token="+responseRequestPermissions.token;
                    //
                    // Once you are done with authorization, you will be returning
                    // back to `callback` url mentioned in your request. While
                    // returning, PayPal will send two parameters in request:
                    //
                    // * `request_token`
                    // * `token_verifier`
                    // You have to use these values in `GetAccessToken` API call to
                    // generate `AccessToken` and `TokenSecret`
                }
                // # Error Values
                else
                {
                    List <ErrorData> errorMessages = responseRequestPermissions.error;
                    foreach (ErrorData error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.message);
                        Console.WriteLine("API Error Message : " + error.message + "\n");
                    }
                }
            }
        }
        // # Exception log
        catch (System.Exception ex)
        {
            // Log the exception message
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return(responseRequestPermissions);
    }
Beispiel #8
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);
        }