private void GetAccessToken(HttpContext context)
        {
            // (Required) The request token from the response to RequestPermissions.
            string token = context.Request.Params["txtrequest_token"];

            // (Required) The verification code returned in the redirect from PayPal to the return URL.
            string verifier = context.Request.Params["txtverification_code"];
            string source = context.Request.Params["source"];

            PermissionsModelAlias.GetAccessTokenRequest gat =
                new PermissionsModelAlias.GetAccessTokenRequest();
            gat.token = token;
            gat.verifier = verifier;
            gat.requestEnvelope = new PermissionsModelAlias.RequestEnvelope();

            // (Required) RFC 3066 language in which error messages are returned;
            // by default it is en_US, which is the only language currently supported.
            gat.requestEnvelope.errorLanguage = ERROR_LANGUAGE;
            PermissionsModelAlias.GetAccessTokenResponse gats = null;

            try
            {
                // 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]
                Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();

                // Creating service wrapper object to make an API call by loading configuration map.
                PermissionsAlias.PermissionsService service = new PermissionsAlias.PermissionsService(configurationMap);
                gats = service.GetAccessToken(gat);
                context.Response.Redirect(source + "?token=" + gats.token + "&tokensecret=" + gats.tokenSecret);
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }
        }
    // # GetAccessToken API Operation
    // Use the GetAccessToken API operation to obtain an access token for a set of permissions
    public GetAccessTokenResponse GetAccessTokenAPIOperation()
    {
        // Create the GetAccessTokenResponse object
        GetAccessTokenResponse responseGetAccessToken = new GetAccessTokenResponse();

        try
        {
            // Create the GetAccessTokenRequest object
            GetAccessTokenRequest requestGetAccessToken = new GetAccessTokenRequest();

            // The request token from the response to RequestPermissions.
            requestGetAccessToken.token = "AAAAAAAXO-JZhFLpTLLe";

            // The verification code returned in the redirect from PayPal to the
            // return URL after `RequestPermissions` call
            requestGetAccessToken.verifier = "R.X1BWK7QEv-dcjQEzk2xg";

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

            // # API call 
            // Invoke the GetAccessToken method in service wrapper object
            responseGetAccessToken = service.GetAccessToken(requestGetAccessToken);

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

                // # Success values
                if (responseGetAccessToken.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    logger.Info("Access Token : " + responseGetAccessToken.token + "\n");
                    logger.Info("Token Secret : " + responseGetAccessToken.tokenSecret + "\n");
                    Console.WriteLine("Access Token : " + responseGetAccessToken.token + "\n");
                    Console.WriteLine("Token Secret : " + responseGetAccessToken.tokenSecret + "\n");
                }
                // # Error Values            
                else
                {
                    List<ErrorData> errorMessages = responseGetAccessToken.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 responseGetAccessToken;
    }
        private void GetAccessToken(HttpContext context)
        {
            GetAccessTokenRequest gat = new GetAccessTokenRequest();

            // (Required) The request token from the response to RequestPermissions.
            string token = context.Request.Params["txtrequest_token"];

            // (Required) The verification code returned in the redirect from PayPal to the return URL.
            string verifier = context.Request.Params["txtverification_code"];

            gat.token = token;
            gat.verifier = verifier;

            // (Required) RFC 3066 language in which error messages are returned;
            // by default it is en_US, which is the only language currently supported.
            gat.requestEnvelope = new RequestEnvelope("en_US");
            GetAccessTokenResponse gats = 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());

                gats = service.GetAccessToken(gat);
                context.Response.Write("<html><body><textarea rows=30 cols=80>");
                ObjectDumper.Write(gats, 5, context.Response.Output);
                context.Response.Write("</textarea></br>");

                //Selenium Test Case
                context.Response.Write("</br>Acknowledgement: ");
                context.Response.Write("<div id = '");
                context.Response.Write("Acknowledgement");
                context.Response.Write("'>");
                context.Response.Write(gats.responseEnvelope.ack);
                context.Response.Write("</div>");

                context.Response.Write("</br>Request token: ");
                context.Response.Write("<div id = '");
                context.Response.Write("Request token");
                context.Response.Write("'>");
                context.Response.Write(context.Request.Params["txtrequest_token"]);
                context.Response.Write("</div>");

                context.Response.Write("</br>Verification code: ");
                context.Response.Write("<div id = '");
                context.Response.Write("Verification code");
                context.Response.Write("'>");
                context.Response.Write(context.Request.Params["txtverification_code"]);
                context.Response.Write("</div>");

                context.Response.Write("</br>token: ");
                context.Response.Write("<div id = '");
                context.Response.Write("token");
                context.Response.Write("'>");
                context.Response.Write(gats.token);
                context.Response.Write("</div>");

                context.Response.Write("</br>tokenSecret: ");
                context.Response.Write("<div id = '");
                context.Response.Write("tokenSecret");
                context.Response.Write("'>");
                context.Response.Write(gats.tokenSecret);
                context.Response.Write("</div>");
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
            }
        }
Пример #4
0
        private void GetAccessToken(HttpContext context)
        {
            GetAccessTokenRequest gat = new GetAccessTokenRequest();

            String token = context.Request.Params["txtrequest_token"];
            String verifier = context.Request.Params["txtverification_code"];

            gat.token = token;
            gat.verifier = verifier;

            gat.requestEnvelope = new RequestEnvelope("en_US");
            GetAccessTokenResponse gats = null;

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

                //Selenium Test Case
                context.Response.Write("</br>Acknowledgement: ");
                context.Response.Write("<div id = '");
                context.Response.Write("Acknowledgement");
                context.Response.Write("'>");
                context.Response.Write(gats.responseEnvelope.ack);
                context.Response.Write("</div>");

                context.Response.Write("</br>Request token: ");
                context.Response.Write("<div id = '");
                context.Response.Write("Request token");
                context.Response.Write("'>");
                context.Response.Write(context.Request.Params["txtrequest_token"]);
                context.Response.Write("</div>");

                context.Response.Write("</br>Verification code: ");
                context.Response.Write("<div id = '");
                context.Response.Write("Verification code");
                context.Response.Write("'>");
                context.Response.Write(context.Request.Params["txtverification_code"]);
                context.Response.Write("</div>");

                context.Response.Write("</br>token: ");
                context.Response.Write("<div id = '");
                context.Response.Write("token");
                context.Response.Write("'>");
                context.Response.Write(gats.token);
                context.Response.Write("</div>");

                context.Response.Write("</br>tokenSecret: ");
                context.Response.Write("<div id = '");
                context.Response.Write("tokenSecret");
                context.Response.Write("'>");
                context.Response.Write(gats.tokenSecret);
                context.Response.Write("</div>");
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
            }
        }