Parameters for getting an access token using a authorization code.
Inheritance: ClientCredentials
Exemple #1
0
        /// <summary>
        /// Creates an Access Token from an Authorization Code.
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
        /// </summary>
        public static Tokeninfo CreateFromAuthorizationCode(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
        {
            var pattern      = "v1/identity/openidconnect/tokenservice?grant_type={0}&code={1}&redirect_uri={2}";
            var parameters   = new object[] { createFromAuthorizationCodeParameters };
            var resourcePath = SDKUtil.FormatURIPath(pattern, parameters);

            return(CreateFromAuthorizationCodeParameters(apiContext, createFromAuthorizationCodeParameters, resourcePath));
        }
Exemple #2
0
        /// <summary>
        /// Helper method for creating Access and Refresh Tokens from an Authorization Code.
        /// </summary>
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for the API call.</param>
        /// <param name="resourcePath">The path to the REST API resource that will be requested.</param>
        /// <returns>A TokenInfo object containing the Access and Refresh Tokens.</returns>
        private static Tokeninfo CreateFromAuthorizationCodeParameters(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters, string resourcePath)
        {
            var payLoad = resourcePath.Substring(resourcePath.IndexOf('?') + 1);

            resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
            var headersMap = new Dictionary <string, string>();

            headersMap.Add(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
            if (apiContext == null)
            {
                apiContext = new APIContext();
            }
            apiContext.HTTPHeaders   = headersMap;
            apiContext.MaskRequestId = true;
            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Exemple #3
0
 /// <summary>
 /// Creates an Access Token from an Authorization Code.
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
 /// </summary>
 public static Tokeninfo CreateFromAuthorizationCode(CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
 {
     return(CreateFromAuthorizationCode(null, createFromAuthorizationCodeParameters));
 }
Exemple #4
0
        private Payment CreateFuturePayment(string correlationId, string authorizationCode, string redirectUrl)
        {
            Payer payer = new Payer()
            {
                payment_method = "paypal"
            };

            var amount = new Amount()
            {
                currency = "USD",
                total = "100",
                details = new Details()
                {
                    tax = "15",
                    shipping = "10",
                    subtotal = "75"
                }
            };

            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            var itemList = new ItemList() { items = new List<Item>() };
            itemList.items.Add(new Item()
            {
                name = "Item Name",
                currency = "USD",
                price = "15",
                quantity = "5",
                sku = "sku"
            });

            var transactionList = new List<Transaction>();

            transactionList.Add(new Transaction()
            {
                description = "Transaction description.",
                amount = amount,
                item_list = itemList
            });

            var authorizationCodeParameters = new CreateFromAuthorizationCodeParameters();
            authorizationCodeParameters.setClientId(Configuration.ClientId);
            authorizationCodeParameters.setClientSecret(Configuration.ClientSecret);
            authorizationCodeParameters.SetCode(authorizationCode);

            var apiContext = Configuration.GetAPIContext();

            var tokenInfo = Tokeninfo.CreateFromAuthorizationCodeForFuturePayments(apiContext, authorizationCodeParameters);
            var accessToken = string.Format("{0} {1}", tokenInfo.token_type, tokenInfo.access_token);

            var futurePaymentApiContext = Configuration.GetAPIContext(accessToken);

            var futurePayment = new FuturePayment()
            {
                intent = "authorize",
                payer = payer,
                transactions = transactionList,
                redirect_urls = redirUrls
            };
            return futurePayment.Create(futurePaymentApiContext, correlationId);
        }
Exemple #5
0
        /// <summary>
        /// Creates Access and Refresh Tokens from an Authorization Code for future payments.
        /// </summary>
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for the API call.</param>
        /// <returns>A TokenInfo object containing the Access and Refresh Tokens.</returns>
        public static Tokeninfo CreateFromAuthorizationCodeForFuturePayments(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
        {
            var pattern      = "v1/oauth2/token?grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code={0}";
            var parameters   = new object[] { createFromAuthorizationCodeParameters.ContainerMap["code"] };
            var resourcePath = SDKUtil.FormatURIPath(pattern, parameters);

            return(CreateFromAuthorizationCodeParameters(apiContext, createFromAuthorizationCodeParameters, resourcePath));
        }
        // #Create Future Payment Using PayPal
        // This sample code demonstrates how you can process a future payment made using a PayPal account.
        /// <summary>
        /// Code example for creating a future payment object.
        /// </summary>
        /// <param name="correlationId"></param>
        /// <param name="authorizationCode"></param>
        private Payment CreateFuturePayment(string correlationId, string authorizationCode, string redirectUrl)
        {
            // ###Payer
            // A resource representing a Payer that funds a payment
            // Payment Method
            // as `paypal`
            Payer payer = new Payer()
            {
                payment_method = "paypal"
            };

            // ###Amount
            // Let's you specify a payment amount.
            var amount = new Amount()
            {
                currency = "USD",
                // Total must be equal to sum of shipping, tax and subtotal.
                total = "100",
                // ###Details
                // Let's you specify details of a payment amount.
                details = new Details()
                {
                    tax = "15",
                    shipping = "10",
                    subtotal = "75"
                }
            };

            // # Redirect URLS
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            // ###Items
            // Items within a transaction.
            var itemList = new ItemList() { items = new List<Item>() };
            itemList.items.Add(new Item()
            {
                name = "Item Name",
                currency = "USD",
                price = "15",
                quantity = "5",
                sku = "sku"
            });

            // ###Transaction
            // A transaction defines the contract of a
            // payment - what is the payment for and who
            // is fulfilling it. 
            var transactionList = new List<Transaction>();

            // The Payment creation API requires a list of
            // Transaction; add the created `Transaction`
            // to a List
            transactionList.Add(new Transaction()
            {
                description = "Transaction description.",
                amount = amount,
                item_list = itemList
            });

            var authorizationCodeParameters = new CreateFromAuthorizationCodeParameters();
		    authorizationCodeParameters.setClientId(Configuration.ClientId);
		    authorizationCodeParameters.setClientSecret(Configuration.ClientSecret);
		    authorizationCodeParameters.SetCode(authorizationCode);

            // ### Api Context
            // Pass in a `APIContext` object to authenticate 
            // the call and to send a unique request id 
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly. 
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();


            var tokenInfo = Tokeninfo.CreateFromAuthorizationCodeForFuturePayments(apiContext, authorizationCodeParameters);
            var accessToken = string.Format("{0} {1}", tokenInfo.token_type, tokenInfo.access_token);

            var futurePaymentApiContext = Configuration.GetAPIContext(accessToken);

            // ###Payment
            // A FuturePayment Resource
            var futurePayment = new FuturePayment()
            {
                intent = "authorize",
                payer = payer,
                transactions = transactionList,
                redirect_urls = redirUrls
            };
            return futurePayment.Create(futurePaymentApiContext, correlationId);
        }
Exemple #7
0
 /// <summary>
 /// Creates an Access Token from an Authorization Code.
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
 /// </summary>
 public static Tokeninfo CreateFromAuthorizationCode(CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
 {
     return CreateFromAuthorizationCode(null, createFromAuthorizationCodeParameters);
 }
Exemple #8
0
 /// <summary>
 /// Helper method for creating Access and Refresh Tokens from an Authorization Code.
 /// </summary>
 /// <param name="apiContext">APIContext to be used for the call.</param>
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for the API call.</param>
 /// <param name="resourcePath">The path to the REST API resource that will be requested.</param>
 /// <returns>A TokenInfo object containing the Access and Refresh Tokens.</returns>
 private static Tokeninfo CreateFromAuthorizationCodeParameters(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters, string resourcePath)
 {
     var payLoad = resourcePath.Substring(resourcePath.IndexOf('?') + 1);
     resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
     var headersMap = new Dictionary<string, string>();
     headersMap.Add(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
     if (apiContext == null)
     {
         apiContext = new APIContext();
     }
     apiContext.HTTPHeaders = headersMap;
     apiContext.MaskRequestId = true;
     return PayPalResource.ConfigureAndExecute<Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad);
 }
Exemple #9
0
 /// <summary>
 /// Creates Access and Refresh Tokens from an Authorization Code for future payments.
 /// </summary>
 /// <param name="apiContext">APIContext to be used for the call.</param>
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for the API call.</param>
 /// <returns>A TokenInfo object containing the Access and Refresh Tokens.</returns>
 public static Tokeninfo CreateFromAuthorizationCodeForFuturePayments(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
 {
     var pattern = "v1/oauth2/token?grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code={0}";
     var parameters = new object[] { createFromAuthorizationCodeParameters.ContainerMap["code"] };
     var resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
     return CreateFromAuthorizationCodeParameters(apiContext, createFromAuthorizationCodeParameters, resourcePath);
 }
Exemple #10
0
 /// <summary>
 /// Creates an Access Token from an Authorization Code.
 /// <param name="apiContext">APIContext to be used for the call.</param>
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
 /// </summary>
 public static Tokeninfo CreateFromAuthorizationCode(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
 {
     var pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&code={1}&redirect_uri={2}";
     var parameters = new object[] { createFromAuthorizationCodeParameters };
     var resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
     return CreateFromAuthorizationCodeParameters(apiContext, createFromAuthorizationCodeParameters, resourcePath);
 }