/// <summary>
        /// Invokes the GetAccessToken API that requests third party permissions
        /// from another PayPal user for the API caller
        /// </summary>
        /// <param name="context"></param>
        private void RequestPermissions(HttpContext context)
        {
            // Restrict permissioning scope to "INVOICING"
            // This will allow the API caller to invoke any invoicing related API
            // on behalf of the permission granter
            string requestperm = "INVOICING";
            PermissionsModelAlias.RequestPermissionsRequest rp = new PermissionsModelAlias.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
            rp.scope.Add(requestperm);

            string url = context.Request.Url.Scheme + "://" + context.Request.Url.Host + ":" + context.Request.Url.Port;
            string returnURL = url + "/GetAccessToken.aspx?source=" + context.Request.UrlReferrer.LocalPath;

            //(Required) Your callback function that specifies actions to take after the account
            // holder grants or denies the request.
            rp.callback = returnURL;
            PermissionsModelAlias.RequestPermissionsResponse rpr = 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);
                rpr = service.RequestPermissions(rp);

                string ret = "<div class='overview'>Step 1) Invoke the RequestPermissions API and redirect third party to "
                + "PayPal so that the user may login and grant permissions to the API caller<br/></div>";
                ret = ret + "<a href=";
                ret = ret + ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_grant-permission&request_token=" + rpr.token;
                ret = ret + "> Redirect URL (Click to redirect) </a><br/><br/>";
                context.Response.Write(ret);

                context.Response.Write("<html><body><textarea rows=30 cols=80>");
                ObjectDumper.Write(rpr, 5, context.Response.Output);
                context.Response.Write("</textarea></body></html>");
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }
        }
        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);
            }
        }
        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;
            }
        }
        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);
            }
        }
    // # 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;
    }
    // # 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;
    }
Пример #7
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);
            }
        }
Пример #8
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);
            }
        }